CS430 Homework Assignment 3

Programming Problem:

1. In this assignment you will read polygons from the input file. The polygons will be clipped to and drawn inside the viewport. They will be drawn as filled polygons.

2. Modify your HW2 program to:

  1. Read a file containing an arbitrary number of polygons.
  2. Perform polygon filling (scan line algorithm, no flood filling).
  3. Write your pixel buffer to standard out in PBM format. The description of the PBM format can be found here.
  4. Define the resolution of your output image to be 501 x 501.
  5. All the command-line options implemented in HW1 should be supported, plus the following which implement viewport mapping. You should be able to process any subset of the options in any arbitrary order.
  6. [-j] The next argument is an integer lower bound in the x dimension of the viewport window (0)
  7. [-k] The next argument is an integer lower bound in the y dimension of the viewport window (0)
  8. [-o] The next argument is an integer upper bound in the x dimension of the viewport window (200)
  9. [-p] The next argument is an integer upper bound in the y dimension of the viewport window (200)
  10. The viewport coordinate system origin is in the lower left corner of your image. The X direction is to the right, and the Y direction is up.
  11. You may assume that the viewport parameters are greater than or equal to zero, and less then or equal to 500.
  12. Clipping should occur along the outer boundaries of the world window using the Sutherland-Hodgman algorithm from HW2.
  13. Map the clipped geometry inside the world window into the viewport and scan-fill it there.
  14. Your new program should be named CG_hw3.

  15. Steps in assignment
    1. Read in polygons
    2. Apply 2D transformations to them in world coordinates
    3. Clip polygons to world window
    4. Apply world-to-viewport transformation to the clipped polygons' vertices
    5. (You can also apply the w-t-v transformation before clipping. You would then clip the transformed polygons to the viewport window)
    6. Round polygon vertices to integers
    7. Scan fill transformed polygons into software frame buffer
    8. Write frame buffer to PBM file

  16. You can test your program with hw3.ps.
  17. If you are having problems with dangling edges from the concave shape or a with the overlapping edge in the "0",
    this file has broken the "S" into three separate polygons and the "0" into two separate polygons.
  18. The default option set for this assignment is equivalent to this command line.
        ./CG_hw3 -f hw3_split.ps -a 0 -b 0 -c 250 -d 250 -j 0 -k 0 -o 200 -p 200 -s 1.0 -m 0 -n 0 -r 0 > out.pbm
  19. If the tester enters ./CG_hw3 > hw3_a.pbm , the results should be the same as from the command line above, and produce the following image.
    PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

  20. Input/Output Example:
            i. Input: ./CG_hw3 -f hw3_split.ps -a 0 -b 0 -c 500 -d 500 -j 0 -k 0 -o 500 -p 500 -s 1.0 -m 0 -n 0 -r 0 > hw3_b.pbm
            ii. Output:

  21. Input/Output Example:
            i. Input:         i. Input: ./CG_hw3 -f hw3_split.ps -a 50 -b 0 -c 325 -d 500 -j 0 -k 110 -o 480 -p 410 -s 1 -m 0 -n 0 -r 0 > hw3_c.pbm
            ii. Output:

  22. Input/Output Example:
            i. Input: ./CG_hw3 -f hw3_split.ps -a 10 -b 10 -c 550 -d 400 -j 10 -k 10 -o 500 -p 400 -s 1.2 -m 6 -n 25 -r 8 > hw3_d.pbm
            ii. Output:

  23. Input/Output Example:
            i. Input: ./CG_hw3 -b 62 -c 500 -d 479 -r 75 -j 139 -o 404 -p 461 -s .85 -m 300 > hw3_e.pbm
            ii. Output:

  24. Input/Output Example:
            i. Input: ./CG_hw3 -a 275 -b 81 -c 550 -d 502 -r -37 -j 123 -k 217 -o 373 -p 467 > hw3_f.pbm
            ii. Output:

  25. Input/Output Example:
            i. Input: ./CG_hw3 -d 301 -c 435 -b 170 -a -100 -r -23 > hw3_g.pbm
            ii. Output:

  26. Input/Output Example:
            i. Input: ./CG_hw3 -a -135 -b -53 -c 633 -d 842 -m -23 -j 101 -p 415 -s 3.6 > hw3_h.pbm
            ii. Output:

    3. Grading Scheme

    1. Previous features : 2 points
      • Clipping operations
      • Transformations
      • Windowing
    2. Input file reading : 1 point
    3. Viewport mapping: 2 points
    4. Polygon filling : 5 points

    4. Submission Guidelines:

    1. Assignments must be submitted via Bb Learn.
    2. 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.
    3. All source code. Your code must compile and run on tux (Linux).
    4. You may program in any language you like as long it can produce a usable executable named CG_hw3 on tux.
    5. 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.
    6. Makefile: have the default rule compile your program.
    7. 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_hw3 that accepts arguments and prints PBM to standard out.
    8. Points will be deducted if submission guidelines are not followed.
    9. Further details about Bb Learn
      1. You can reach Bb Learn through DrexelOne.
      2. 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.
      3. Click on the assignment you wish to submit.
      4. Find your file and click Upload button.
      5. 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.


    Last modified on October 18, 2021.