Program problem:
- Understand the Simplified Postscript input 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:
/Line {moveto lineto stroke} bind def
0.1 setlinewidth
%%%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.
- Understand the Simplified Postscript output file format (*.ps)
- The output from your program will be a simplified Postscript.
- << /PageSize [xsize ysize] >> setpagedevice
- 0.1 setlinewidth
- x y moveto
- x y lineto
- The text of these commands will be bounded by two
delimiters where %%%BEGIN marks the beginning, and %%% END marks the end.
- The x y tokens should be placed at the beginning of
the lines they occur on.
- Postscript assumes that the origin (0,0) is located
in the lower left corner of the window.
Some example code is given below:
%%BeginSetup
<< /PageSize [612 792] >> setpagedevice
%%EndSetup
0.1 setlinewidth
%%%BEGIN
600 510 moveto
400 530 lineto
364 530 lineto
335 600 lineto
stroke
%%%END
Here is an example output file.
- Write a program, called CG_hw1 and in the language of your choice,
that accepts our simplified
Postscript-like format file as input, applies 2D transformations to the
specified lines, clips them to the world window, and generates a line drawing in a
simplified Postscript output format.
Example input file here.
- The only Postscript input command you need to implement for this homework
assignment is "Line".
- Clip the lines to the world window with the Cohen-Sutherland algorithm.
- The output image (screen, page) dimensions/resolution will be determined by the -[abcd]
parameters (i.e. the size/shape of your world window).
- xsize = c - a + 1
- ysize = d - b + 1
- 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)
- Your program should be able to process one to many input lines. It is also possible that certain parameters will generate no output lines.
- [-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)
- You may assume that a will always be less than c, and that b will always be less than d.
- There are no limits on the input values. They can be positive and
negative.
- Your program should print the clipped lines in the Postscript file format
to stdout (cout); debugging messages should be printed to stderr (cerr).
- Steps in assignment
- Read in line segments
- Apply transformations to them in world coordinates
- Clip transformed lines to window
- Translate lines into screen/image coordinates, i.e. subtract [a,b] from transformed vertices
- Write clipped lines to standard out in Postscript format
- If the tester chooses not to enter any options and
thus enter ./CG_hw1 > out.ps, your program should produce the same
results as:
./CG_hw1 -f hw1.ps -a 0 -b 0 -c 499 -d 499 -s 1.0 -m 0 -n 0 -r 0 > out.ps
and generate the following image.
Here is the output Postscript file.

- Input/Output Example:
i. The input was: ./CG_hw1 -f hw1.ps
-a 0 -b 0 -c 499 -d 499 -s 0.8 -m 85 -n 25 -r 10 > hw1_out.ps
ii. The output was:
Here is the output Postscript file.

- Input/Output Example:
i. The input was: ./CG_hw1 -f hw1.ps
-s 0.5 > scale.ps
ii. The output was:
Here is the output Postscript file.

- Input/Output Example:
i. The input was: ./CG_hw1 -f hw1.ps
-r -30 > nrotate.ps
ii. The output was:
Here is the output Postscript file.

- Input/Output Example:
i. The input was: ./CG_hw1 -f hw1.ps
-m 100 -n 100 > translate.ps
ii. The output was:
Here is the output Postscript file.

- Input/Output Example: (Dark border is the window boundary)
i. The input was: ./CG_hw1 -f hw1.ps
-a -25 -b -50 -c 399 -d 399 > worldwindow.ps
ii. The output was:
Here is the output Postscript file.

- Input/Output Example: (Dark border is the window boundary)
i. The input was: ./CG_hw1 -f hw1.ps
-a 25 -b 50 -c 399 -d 399 -r 30 -m 100 -n 100 -s 0.5 > all.ps
ii. The output was:
Here is the output Postscript file.

- Input/Output Example: (Dark border is the window boundary)
i. The input was: ./CG_hw1 -f hw1_line.ps
-r -17 -m -10 -n 400 > line1.ps
Here is the input Postscript file.
ii. The output was:
Here is the output Postscript file.

- You should examine the Postscript output of your program, i.e. look at
the generated Postscript commands, to ensure that all vertices are inside
the displayed window. The TA will do this in order to assess the
correctness of your clipping code.
- Grading Scheme
- Command-line argument reading : 1 point
- Postcript reading : 1 point
- Postscript writing : 1 point
- Correct window/page size dimensions : 1 point
- Clipping : 3 points
- Transformations : 3 points
- Submission Guidelines:
- Assignments must be submitted via Bb Learn.
- 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.
Text files only. Word and PDF documents will NOT be accepted.
- The README file should specify the file and line numbers of
your program that implements line clipping.
- All source code. Your code must compile and run
on tux (Linux).
- You may program in any language you like as long it can produce
a usable executable named CG_hw1 on tux.
- 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: have the default
rule compile your program.
- If you are using a language that doesn't produce an executable file,
e.g. python, then be sure to include a script called CG_hw1 that
accepts arguments and prints Postscript to standard out.
- Points will be deducted if submission guidelines are not followed.
- Further details about Bb Learn
- You can reach Bb Learn 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.