
                         Scan Converter Assignment

Your directory should have the following files:
README
   this file

Makefile
   rules for compiling the code.  Typing 'make' should produce
   the executable "ivscan" (remember to "add 6.837" before you make,
   since some of the libraries you need are provided there).

Edge.h
EdgeRec.C *
EdgeRec.h *
EdgeRecList.C *
EdgeRecList.h *
Interface.C
Interface.h
List.C
List.h *
Main.C
Polygon.h
SCtypes.h
Scan.C *
Scan.h *
ScanWrap.C
Types.h
Utils.C
Utils.h
    These are the source files of the program.  The ones marked with
    a '*' are important, and should be looked at carefully.

onetri.iv   -- single monochrome polygon
twotris.iv  -- two monochrome polygons sharing an edge
rgbtri.iv   -- a polygon with r,g,b at its three vertices
cube.iv     -- a multicolored cube, each face monochrome
ellipsoid.iv -- many, many polygons approximating an ellipsoid
interpen.iv  -- three interpenetrating parallelepipeds

   Inventor files which exercise the capabilities of your 
   implementation.

ii_files/
   this directory will be created when you do "make". ignore
   it and its contents; it is compiler scratch space for 
   templated classes.

In this problem set you will implement parts of a scan converter. 
Your task will be to supply the innards of the scan converter. 

To build this program you should be in the "ivscan" directory.  Type:
        % make 
When the make completes, producing an executable ivscan, type:
        % ivscan rgbtri.iv

When you run ivscan you will see 6 Scene Viewer buttons on the left:
        S -- scan converts the scene into a frame buffer and then
             outputs the complete frame buffer to the screen.
                (interface::debug == 0 when button "S" is pressed)
        D -- scan converts the scene updating every screen pixel
             every time setPixel() is called.
                (interface::debug == 1 when button "D" is pressed)
        B -- clears the viewport, then scan converts the scene updating
             every screen pixel every time setPixel() is called.
                (interface::debug == 2 when button "B" is pressed)
        # -- Invokes your scan converter at low resolution (try it)

        There are several example files in the directory "ivexamples."
Use them to test your code. We will use these and other Inventor files
to test your code. (You can see correct behavior by running the 
"reference executable" /mit/6.837/as2_ivscan/ivscan.)

        When you run the original (incomplete) program, and press D,B,
etc. you will see lines on the screen at the edges of the polygons.
These show you where Edges (and EdgeRecs) are.  The procedures in
Scan.C and other files are heavily documented to help you complete the
assignment.

For this assignment you must:

In EdgeRec.C:
  1. Complete EdgeRec::Init(), which is invoked once per polygon Edge.

In Scan.C:
  2. Complete RenderScene(), which scan converts all polygons for 
     all scan lines.  RenderScene() calls four routines:
        A) EdgeRecList::Concat ()       (given, in List.C)
        B) EdgeRecList::Sort ()         (given, in EdgeRecList.C)
        C) RenderScanLine()             (stub given in Scan.C)
        D) EdgeRecList::Update()        (stub given in EdgeRecList.C) 

In Scan.C:
  3. Complete RenderScanLine(), which renders all spans of one scanline.
     That is, RenderScanLine() takes the existing state of the AEL and
     produces a single raster of color values.  Spans are formed by 
     matching pairs of SpanEdges from the AEL (as described in lecture).
     RenderScanLine() should call setPixel() once for each pixel of
     the current raster.
     
In EdgeRecList.C:
  4. Complete EdgeRecList::Update(), which updates the current AEL 
     in preparation for the next scan line.  EdgeRecList::Update()
     calls EdgeRec::Update() once for each EdgeRec that survives to 
     the next scan line; otherwise it should Remove() the EdgeRec
     from the AEL.

In EdgeRec.C:
  5. Complete EdgeRec::Update(), which causes an EdgeRec to update
     its fields so as to remain valid for the next scanline.

Here is an overview of the types and classes used in ivscan.

In Polygon.h:

  PolyVert: A vertex (in screen-space and eye-space coords) and RGB color.
  Polygon:  A collection of three PolyVerts.


In ScanRec.h:

  EdgeRec:  Built from the Edge of a Polygon, as described in lecture.
            Contains edge start and end, current value of y, x, eye z, 
            h (1/z), color, normals, and a pointer to owner Edge and Polygon.


EdgeRecList.h:

  EdgeRecList: Contains the head of a list of EdgeRecs.


SCtypes.h:

  Environment: Named "env" throughout ivscan, the Environment contains

    1. viewportSize,  i.e. xres = env->wvpSize[X], 
                           yres = env->wvpSize[Y]

    2. pixelData      the [xres * yres] buffer into which your routine
                      RenderScene() will scan convert all input polygons

    3. EdgeRecTable an array of size yres of EdgeRecLists.
                      env->EdgeRecTable[k] contains exactly those
                      EdgeRecs that will become active on line k


SUMMARY:  These are the functions you should complete:
EdgeRec.C:
    Init                (Task 1)
    Update              (Task 5)

EdgeRecList.C
    Update              (Task 4)

Scan.C
    RenderScene         (Task 2)
    RenderScanLine      (Task 3)

Bottom-up, we recommend order 1, 5, 4, 3, 2.
Top-down, we recommend order 1, 2, 3, 4, 5.


EXTRA CREDIT:  Here are some possible extra credit tasks.  They
are independent; you can do any one alone or in combination with
others.

2 pts.  A) Better lighting. Apply lighting per-pixel, after visibility.

1 pt.   B) Better clipping. Fix ScanWrap.C to clip triangles correctly.

1 pt.   C) Better interactivity.  Modify ivscan to call back your 
        scan-line renderer every frame, suppressing inventor rendering.
        

