In this project you will implement the midpoint line drawing algorithm
to rasterize line segments, and also a simple method for scan
converting triangles and using barycentric coordinates to interpolate
colors. Both algorithms are described in our textbook, Fundamentals of
You are given support code for this project and will need to
- plan to use the jot library
provided for you on CAEN space, or else install jot on your
- copy the project support code and edit the Makefile to indicate jot
installation information; and
- implement the missing functionality.
The support code is based on jot
collection of C++ libraries that
support 3D graphics applications. jot
developed at Brown
University, Princeton University, and the University of Michigan, runs
on Linux, Windows, and Mac OS X, and
has been used in a number of research projects.
Your first step will be to get the jot
code and compile it, unless you plan to use the compiled version of jot
on CAEN space. For
instructions on getting and compiling jot, click here
For this and subsequent projects, you will need to become familiar with
some jot classes. Reading relevant header files is a good way to do
this. Some jot documentation is also available via web
pages created automatically
. In this
project, you will primarily be concerned with the PIXEL and VEXEL
classes in jot's math library (called mlib
These classes represent points and vectors, respectively, in 2D "pixel
coordinates". Useful information about using jot code in this project
is contained in the source file jot-tops.C inside the proj1 directory
Next, copy the project support
code to your local machine. (On windows, you can execute the
following commands using cygwin, which we recommend):
% scp -r red.engin.umich.edu:/afs/engin.umich.edu/class/perm/eecs487/proj1 .
(Note the 'dot' at the end of line.) The above command overwrites all
proj1 files, including any files that
you may have made changes to. To copy 'old' versions of files while
leaving the new untouched (sync-ing operation):
% rsync -avz red.engin.umich.edu:/afs/engin.umich.edu/class/perm/eecs487/proj1 .
(Do this from the parent directory containing the proj1 subdirectory.)
The C++ source code file p1.C
contains this support code. It defines a jot
application that loads a 3D model from the command line, then renders
the model either using OpenGL (that part is already implemented) or
else using scan conversion code that you will write. The application
understands several commands entered by pressing keys: 'g' to toggle
between OpenGL rendering and your code, 'w' to toggle between
wrireframe and filled triangles (in your code), and 't' to toggle
between semi-transparent and opaque mode (in your code). The handling
of the key
commands is already implemented. You just need to write the scan
conversion code, including support for lines, filled triangles (with or
without colors assigned to the vertices), and support for both opaque
and transparent rendering. Read through this file to get
familiar with it, then implement the following missing functionality:
- Render mesh edges as 1-pixel wide white lines using the midpoint
drawing algorithm described in the textbook (Fundamentals of Computer
Graphics, 2nd Edition, Section 3.5: Line Drawing). The image of the cow
on the left above is an example of this type of rendering (known as
"wireframe"). 20 points.
- Extend the algorithm to handle the case that colors are stored at
mesh vertices. In that case, interpolate colors smoothly along the line
segment. We suggest you use an incremental method to compute colors.
(See Section 3.5). 10 points.
- Add functionality for clipping the lines before scan converting
them. The goal is to discard any line segment that lies entirely
outside the window, and trim line segments that lie partially outside
the window, leaving only the parts that are inside the window. This can
greatly speed rendering for some viewpoints. 10 points.
- Implement the algorithm described in the text (section 3.5) for
scan converting triangles using barycentric coordinates to
interpolate colors assigned to mesh vertices. 25 points.
- If the mesh does not have colors assigned to its vertices,
compute a single color for the whole triangle using a simple
shading calculation: construct a greyscale color value from the dot
product of the triangle normal and
the vector from the camera to the triangle centroid (both unit
vectors). Be sure to carefully read the provided file,
proj1/jot-tips.C, as well as p1.C, for advice and utility functions
that will make your job easier. 15
- Add the ability to toggle between opaque and semi-transparent
triangles. When semi-transparent mode is on, blend the computed color
with the color already stored at that pixel in the image, using a blend
factor of 0.5. 10 points.
- Comment your code reasonably, particularly your design decisions
and choice of approach.
- Modularize your code: use a suitable number of helper functions
- Use descriptive variable and function names: apply a suitable
tradeoff between symbol-length and descriptiveness.
Bottom line: Make your code readable! 10 points
Modifying the code:
of the missing functionality must
begin within bodies of
two functions with the following prototypes:
scan_convert_faces(CGELlist& gels, RefImage& img, double
scan_convert_edges(CGELlist& gels, RefImage& img, double
You will find these prototypes at the top of p1.C
definitions later within p1.C
You starting points are marked with
YOUR CODE HERE
Declare and define helper functions as you see fit.
Building and running the
The support code comes with a README
that explains how to compile and run the project on Windows, Linux, or
Mac OS X.
Once you compile, you can run the executable, named p1,
which takes a model file
command-line argument. For example:
% p1 models/house.sm
On Windows you can use a DOS or cygwin
shell to execute the above command.
Several models are provided for you.
Model files are located in the proj1/models
directory and have
run p1, if you place the cursor in the rendering window and
press key 'g', you can toggle between OpenGL rendering (built into the
support code) and your scan
conversion code. Since your code is not yet written, you will
initially toggle between not seeing the model and seeing it rendered in
OpenGL. Press the 'H' key to see other key commands available in
Turn in two files: your version of p1.C
, and a brief write-up in
- anything about your
implementation that is noteworthy (e.g., your method for clipping
lines, or for interpolating
colors along line segments), and
- feedback on
this assignment, including suggestions for how it should be changed
- name your file writeup-<uniqname>.txt .
Example: I'd name my writeup file writeup-rmanoj.txt
- Copy your code, write-up and any other supporting files
(Makefiles or Visual Studio project files etc) to the following
directory on IFS:
This path is accessible from any machine you've logged into
using your ITCS (umich.edu) password. Report problems to ITCS.
- The timestamp on your key files (p1.C and your writeup) will
indicate the time of submission and if this is past the deadline your
submission will be considered late. Therefore, you are allowed multiple
'submissions' as long as you respect the deadline.
the compilation: Your submission must compile without errors and
warnings (except those from external libraries like OpenGL, JOT etc.)
on CAEN Linux or Windows machines. Mention
the platform in your writeup. Code that doesn't compile will be
The project is due on January 25, 2007, by 11:59pm. Turning it in 48
hours earlier is worth a 4% bonus; turning it in 24 hours early is
worth a 2% bonus.
updated: January 10, 2007