Here is
an excellent description of line drawing algorithms from Leonard McMillan.
You may use the Bresenham code posted on this web page in your assignment.
Program problem:
Understand the XPM file format.
A brief description can be found here:
xpm.pdf (You only need chapters 1 and 2 of this document.
The XPM format assumes that the origin (0,0) is in the upper left-hand
corner.
You can ignore optional parameters and only put data for "width
height ncolors cpp" in the first string. For example:
/* width height num_colors chars_per_pixel */
"7 7 4 1"
Then you have "ncolors" strings associating characters with colors.
You can assume the color display and use "c" key. The value of color defined
by # followed by the RGB code in hexadecimal. For example:
/*colors */
"- c #ffffff",
"# c #ffe0e0",
"a c #ffb7b7",
"X c #010101",
And last you have the "height" strings of "width" * "chars_per_pixel"
characters, where every "chars_per_pixel" length string must be one of the
previously defined groups in the "colors" section. For example:
"X-###--",
"-##a##-",
"##aaa##",
"##aaa##",
"##aaa##",
"-##a##-",
"--###--"
The example images below have been enlarged, and a black border
was added for clarity.
/* XPM */
static char *sco100[] = {
/* width height num_colors chars_per_pixel */
"7 7 4 1",
/* colors */
"- c #ffffff",
"# c #ffe0e0",
"a c #ffb7b7",
"X c #010101",
/* pixels */
"X-###--",
"-##a##-",
"##aaa##",
"##aaa##",
"##aaa##",
"-##a##-",
"--###--"
};
Several free programs are available which can view, read, and write the
XPM file format. Examples of those programs are:
irfanview for Windows.
You must install all the plugins to be able to work with XPM files. gqview for Linux.
Your XPM files must be viewable with 'display' on tux.
Understand the Simplified Postscript file format (*.ps)
The input file will be a Postscript file, but your
program only needs to handle the following command
x1 y1 x2 y2 Line
The text of these commands will be bounded by two
delimiters where %%%BEGIN marks the beginning, and %%% END marks the end.
These tokens will both appear at the beginning of
the lines they occur on.
There may be blank lines anywhere between these
delimiters.
ALL text outside of these delimiters should be ignored
by your program.
Postscript assumes that the origin (0,0) is located
in the lower left corner of the window.
The purpose of using a Postscript-like format is simply to give you an
idea of what the input should look like before you start implementing a reader.
You are not actually implementing a full blown postscript reader. An example
of the simplified format is given below:
%%%BEGIN
375 100 300 230 Line
499 0 0 250 Line
170 450 400 350 Line
350 300 120 400 Line
%%%END
An example
input file. This file can be used to visualize arbitrary input data, in
our simplified format, within the world window.
A free cross-platform tool, gsview, for viewing Postscript.
There are other known free viewers such as gv (Ghostview),
and ggv(GNOME/GTK Ghostview).
Write a program, in the language of your choice, that accepts our simplified
Postscript-like format file as input and generates an XPM image as output.
Example input file here.
The only Postscript command you need to implement for this homework
assignment is "Line".
You will have to implement the DDA or Bresenham algorithm
for scan-conversion of lines.
Clip your lines to the world window with the Cohen-Sutherland algorithm.
The output image (screen) dimensions/resolution will be determined by the -[abcd]
parameters (i.e. the size/shape of your world window).
You must handle the following command-line options. You should be
able to process any subset of the options in any arbitrary order.
*Default values that should be implemented in your code are in bold.*
[-f] The next argument is the input "Postscript" file. (hw1.ps)
[-s] This next argument is a float specifying the scaling factor
in both dimensions about the world origin. (1.0)
[-r] This next argument is an integer specifying the number of
degrees for a counter-clockwise rotation about the world origin. (0)
[-m] The next argument is an integer specifying a translation in
the x dimension. (0)
[-n] The next argument is an integer specifying a translation in
the y dimension. (0)
Assume that the objects of your scene are scaled, then rotated and finally translated in the world coordinates.
[-a] The next argument is an integer lower bound in the x dimension
of the world window (0)
[-b] The next argument is an integer lower bound in the y dimension
of the world window (0)
[-c] The next argument is an integer upper bound in the x dimension
of the world window (499)
[-d] The next argument is an integer upper bound in the y dimension
of the world window (499)
Your program should print output images in the XPM file format
to stdout (cout); debugging messages should be printed to stderr (cerr).
All the pixels should be initialized to white. Draw your objects in black.
Steps in assignment
Read in line segments
Apply transformations to them in world coordinates
Clip transformed lines to window
Scan convert (i.e. draw) clipped lines into software
frame buffer
Write frame buffer to XPM file
If the tester chooses not to enter any options and
thus enter ./cs430_hw1 > out.xpm, your program should produce the same
results as:
Input/Output Example:
i. The input was: ./cs430_hw1 -f hw1.ps
-a 0 -b 0 -c 499 -d 499 -s 0.8 -m 85 -n 25 -r 10 > hw1.xpm
ii. The output was:
Here is the XPM image file.
Input/Output Example:
i. The input was: ./cs430_hw1 -f hw1.ps
-s 0.5 > scale.xpm
ii. The output was:
Input/Output Example:
i. The input was: ./cs430_hw1 -f hw1.ps
-r -30 > nrotate.xpm
ii. The output was:
Input/Output Example:
i. The input was: ./cs430_hw1 -f hw1.ps
-m 100 -n 100 > translate.xpm
ii. The output was:
Input/Output Example: (Dark border is the window boundary)
i. The input was: ./cs430_hw1 -f hw1.ps
-a 25 -b 50 -c 399 -d 399 > worldwindow.xpm
ii. The output was:
Input/Output Example: (Dark border is the window boundary)
i. The input was: ./cs430_hw1 -f hw1.ps
-a 25 -b 50 -c 399 -d 399 -r 30 -m 100 -n 100 -s 0.5 > all.xpm
ii. The output was:
Grading Scheme
Comand-line argument reading : 1 point
Postcript reading : 1 point
Image format : 1 point
Correct window/image dimensions : 1 point
Line drawing : 2 points
Clipping : 2 points
Transformations : 2 points
Submission Guidelines:
Assignments must be submitted via WebCT.
README file: explain the features of
your program, language and OS used, compiler or interpreter used,
name of file containing main(), and how to compile/link your program. Word documents will NOT be accepted.
All source code. Your code must compile and run
on tux (Linux). MacOS X is a negotiable
possibility. The TA will use one of these as the test platform.
You may program in any language you like as long it can produce
a usable executable on tux. Please contact
the TA if you plan on using something other than C, C++ or Java.
Your program will be run by the TA. Please do
NOT submit any image files, Visual C++ project files, or anything not requested
in this section. Your program must run on tux without the
installation of "special" libraries.
Makefile (optional but appreciated): have the default
rule compile your program.
Points will be deducted if submission guidelines are not followed.
Further details about WebCT
You can reach WebCT through DrexelOne.
Choose Computer Graphics among your list of courses. There is an "assignments" link in
the left frame which will give you the list of assignments in the right frame.
Click on the assignment you wish to submit.
Find your file and click Upload button.
Hit Submit button. DO NOT FORGET TO HIT THE SUBMIT BUTTON AFTER YOU UPLOAD ALL YOUR FILES.
NOTE: Your source code for all programming assignments will be run through
a plagiarism detection system. This program uses compiler techniques which
are invariant of syntax and style. If you are sharing code with other classmates,
you will get caught. Please refer to the student
handbook for actions that will be taken.