CS321 -- Lab 4: Lines and Color



->Courses
->CS321
-->Presentation
-->Lab 1
-->Lab 2
-->Lab 3
->Lab 4
-->Lab 5
-->Lab 6
-->Lab 7
-->Lab 8
->Electronic Submission
->Old Exams
->C++ Examples
->Unix Help
->Software
->Tentative Schedule
->Course Policies

[Courses]
[Rich][Home][Rich]
[Author]

Fall Quarter 2001

Purpose

The purpose of this lab is to develop the ability to implement low-level graphics algorithms.

Acknowledgement

This lab was developed by Dr. Henry Welch.

General Lab Information

It is now time to add more functionality to our graphical system. Specifically, we will be adding color and the ability to draw lines.

Update your button pressing code so that the left mouse button defines lines (e.g., press for the start and release for the end) and the right mouse button defines points. This does present a bit of a coding challenge since the press and release come from different events and the one has to know about the other. In general it is better to use static local variables to the member function than use a data member to this class that is accessible to the other member functions; however, if more than one Shell object exists then their member functions would all share the same static local variable. (You may want to experiment with pressing or releasing outside of the drawing window to see what happens.) For an additional challenge use the motion event to "draw" the line in progress; although this is not a requirement.

Develop a line class that is derived from shape so that you can store both the points and lines in the same image object.

In addition add a line drawing (end points) command to the command line parser and be sure to document all of these changes in your help text routine.

Also you will need to enter a color command to the command line parser that either accepts RGB values, uses one of the standard X color names from the standard list in the file /usr/lib/X11/rgb.txt, or uses the QColorDialog. Once a new color is selected, all subsequent shapes should appear in that color until a new and valid color command is entered. During an exposure redraw each shape should appear in the color in which it was first drawn so you will need to save the color information with the shape itself (you will have to modify your point class or derive a new coloredpoint class from it). You must use some caution when working with color. Because X is network aware both the PC and Concord must agree on how colors are being modeled. Each graphics API handles this differently so you need to research the QColor class and color modeling. It is vitally important that when your program is finished using a color (erase or exit) that you deallocate the colors you've used.

For your line drawing code you MAY NOT use the predefined methods of QPainter. You MUST implement Bresenham's Line Drawing Algorithm. For future maintainability you may want to give it the same parameter list as the corresponding QPainter call so that it is a simple matter to substitute the standard line drawing method for yours.

To help you demonstrate that you have accounted for all the special cases of the Bresenham algorithm a sample data file is provided which draws a graphical asterisk. The file format is 4 integers per line as x y x y for each line. It is perfectly acceptable to modify this file so that your Line::Read and Image::Read methods can use it.

There are plenty of areas for extra credit with this assignment; however, you must complete the basic requirements in order to receive the extra credit. (e.g., Dashed lines, anti-aliasing, etc.)

Application demonstration

You should demonstrate the successful operation of your application before or during week 6 lab.

Lab report (due 11pm, the day prior to week 6 lab)

Your lab report should be self-contained. That is, it should be possible for someone to understand what you did and why without seeing anything other than your report and any previous reports that you have submitted. Your report should include:

  • Purpose
  • Problem Statement
  • Procedure -- what approach you used to solve the problem
  • Discussion including:
    • A tally of the number of new Non-commented Lines Of Code (NLOC) written for this lab assignment. You should use the CLC perl script on your code. If possible, break the NLOC down into the various features you needed to implement.
    • A summary of your activity log indicating how much time you spent on each phase of the assignment. Please report the time in the following categories:
      • Designing
      • Coding
      • Debugging (before you think it's working)
      • Testing (after you think it's working)
      • Report writing
      • Other
    • A narrative describing any specific problems you encountered and how you solved them.
  • Conclusions (what you learned, suggestions of how the lab could be improved, things you would have done differently, etc.)
  • Documented source code (clearly identifying any changes made since your last submission). Note: you should include all the source code necessary to compile your project except for unmodified source code written by Dr. Welch. For example, you don't need to include shell.cpp if you didn't modify it.
    You may wish to use gensrc, a shell script which will produce an XML document that may be used as a starting point for your report. The file will include all of the source code files (provided you modify the script appropriately... edit gensrc for details on how to do this.)
  • Be sure to address any areas concern from previous submissions.

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic Submission Guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.

If you have any questions, consult the instructor.

© 1998-2001 Dr. Christopher C. Taylor Office: CC-27C Phone: 277-7339 Last Updated: May 9, 2001
I am responsible for all content posted on these pages; MSOE is welcome to share these opinions but may not want to.