CPSC 102 Computer Science II
Spring 2013
TTh 15:30—16:45 McAdams 119

URL: http://andrewd.ces.clemson.edu/courses/cpsc102/s13/

DateL#Topic
Thu. Jan.10 01 Introduction; syllabus; office hours, etc.

C math library

  • use man sqrt to look up man page for sqrt function
  • note use of #include <math.h> header
  • note use of -lm link library
C compiler
  • distinction between compiling and linking
Working towards building a vector library (lab 1)
  • e.g., #include <math.h> and -lm
  • "interface" (.h) and "implementation" (.c)
  • example of vec_sum function
Tue. Jan.15
Lab 1: vec_t
02 Working towards building a vector library (lab 1)
  • vec_sum
  • vec_dot
  • vec_len
  • vec_scale
  • vec_unit
  • vec_print
  • example Makefile
Thu. Jan.17 03 More on vectors
  • vec_unit (argument aliasing example)
  • vec_cross
  • vec_project
Building a list library (lab 2)
  • concept of generic linked list data structure
  • typedef struct _link { ... } link_t; link node
  • link_init
  • typedef struct _list { ... } list_t; list header
  • list_init
  • list_empty
Tue. Jan.22
Lab 2: list_t
04 Debugging
  • print statements
  • the gdb debugger
    • break <file:line_no>
    • print <variable_name>
    • run
    • where
    • next
    • step
Building a list library (lab 2)
  • list_add (note how to set current pointer)
  • list_fdel (delete first node)
  • list_del (delete entire list)
  • list_not_end
  • list_reset
  • "interface" (.h) and "implementation" (.c)
  • example Makefile
Ray tracing intro
  • coordinate reference frame mapping (image to world coord's)
  • linear interpolation
  • the main double for loop
Thu. Jan.24 05 Ray tracing intro cont'd
  • ray definition (pos, dir) and parametric representation point_along_ray = pos + t * dir
  • 3-step outline of ray tracing algorithm
Building the material_t library (lab 3)
  • material file entry structure
  • typedef struct material_type { ... } material_t; data structure (abstract data type)
  • material_t processing functions
    • material_init
    • material_load_attributes
  • parsing the data file mat.txt
  • material_load_attributes
  • header file organization, Makefile
Data representation of pixel types
  • drgb_t, a double[3] storing R,G,B color values
Tue. Jan.29
Lab 3: material_t
06 Assignment 1

Building the material_t library (cont'd)

  • material_getbyname
  • material_list_print
  • material_print
  • material_getambient (return ambient pixel)
Pixel operations (methods)
  • pix_sum
  • pix_nonzero
  • pix_print
OOP
  • generic objects and specialized object instances (inheritance)
  • generic and specialized object member functions (polymorphism)
  • object_t and plane_t data types
  • object_print and plane_print functions
  • object_init and plane_init functions
Thu. Jan.31 07 Testing for floating point equivalence
  • (fabs(a-b) < epsilon) instead of (a == b) if a and b are floating point
OOP
  • "isa" relationship
  • iterating through list of objects, calling obj->printer(obj,out)
  • idea of virtual object and virtual method
  • sphere_print()
  • function pointers (polymorphic functions)
  • typedef struct object_type { ... } object_t; structure
  • typedef struct plane_type { ... } plane_t; structure
  • contiguous memory
  • plane_init()
  • object_init()
C in C++ style notes
  • plane_t must contain object_t at top for pointer masquerading to work
  • no void *priv; pointer is needed
  • object_init() function signature changes
Tue. Feb.05
Lab 4: object_t
08 OOP review
  • (object_t *) and (plane_t *) pointers and type casting
  • hits() virtual function (function pointer) (like object_print())
  • plane_hits()
  • sphere_hits()
  • plane_init() again and setting of function pointers
  • object_init() refresher
Ray tracing, cont'd
  • ray-plane intersection
  • what is pln->ndotq?
  • plane equation
  • plane_hits function
Thu. Feb.07 09 Ray tracing, cont'd
  • using obj->hits() to find the closest intersected object via object_find_closest() (lab 5)
Parsing model.txt (Assignment 2) with model_t object (Lab 5)
  • Makefile
  • model.h
  • model.c
A matrix data type
  • matrix.h
  • matrix.c
  • mat_xpose() and vec_xform()
  • mtx_t "class" (lab 6)
  • vec_xform() bug
The camera object
  • camera_t
  • camera.h
  • camera.c
  • calling camera_init() and camera_print()

Odds and ends

  • argc, argv
  • fopen, fclose
Tue. Feb.12
Lab 5: object_find_closest()

See also: Lab 5 redux: object_find_closest()

10 Assignment 1 due (23:59:59). Solution: asg01.tar.gz

Assignment 2

Redoing object_last_hit to get rid of the check for last_hit

  • remove object_t *last_hit from funciton arguments
  • add vec_t hit and vec_t N to arguments
  • need to rewrite hits() functions so they all accept and set hit and N

Basic ray caster

  • writing a .ppm image
  • converting image pixel coordinates to world coordinates
  • calculating ray direction
  • converting double pixel r,g,b values to unsigned char r,g,b values
Calling ray_trace() routine.
  • using drgb_t color as color accumulator
  • calling object_find_closest()
  • getting material ambient color
  • scaling material ambient color, adding to drgb_t color color accumulator
Thu. Feb.14 11 Intro to Objective-C:
  • #import <Foundation/Foundation.h>
  • #import <stdio.h>
  • #import <vector.h>
  • .h and .m files
  • @interface and @implementation
  • member function categories:
    • constructor
    • accessor/mutator
    • operator
    • friends
  • int main()
  • NSLog()
  • NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  • [pool drain];
  • [[v1 scale: 1./[v1 len]] write: stderr: "v1 scaled by 1/length is:"];
    is this a memory leak?
Tue. Feb.19
Lab 6: vec_xform()
12 Assignment 2 due (23:59:59). Solution: asg02.tar.gz

Assignment 3

Building a list library (lab 8)

  • NSString
  • a basic data_t object
  • link_t and list_t interface and implementation
  • example of init, add, empty
Building the material_t library (lab 9)
  • pixels like vectors (both now objects)
  • material now stores pointers to objects instead of double[3] arrays
  • need for accessor/mutator functions
  • material members "read themselves"
  • material_t object
  • material_getbyname search function
Using the pixel_t class
Thu. Feb.21 13 Objective-C object_t and plane_t objects (lab 10)
  • base class, derived class relationships
  • using NSString as index into materials list
    (eventually could use an associative array to store materials)
  • virtual functions
  • derived class : public object_t syntax
  • getting base class (parent) to read/write itself
    (no need for *priv pointer)
Tue. Feb.26
Lab 7: object vec_t
14
Assignment 3 due (23:59:59). Solution: asg03.tar.gz

Assignment 4

Objective-C and OpenMP

  • writing an image (color bands) sequentially and in parallel
  • timer_r class to time program execution
  • #pragma calls for parallel execution on multi-core platforms
  • NSImage
  • NSBitmapImageRep
  • NSData
Thu. Feb.28 15 MIDTERM EXAM
10 questions, non-uniform weighting, covering:
  • C
  • linear algebra
  • object-oriented principles
  • writing functions, programs
  • understanding (tracing) programs
  • pointers, pointers to functions
  • linked lists
Tue. Mar.05
Lab 8: object data_t, object list_t
16 Objective-C model_t object and virtual hits function (lab 11)
  • Objective-C file i/o
  • find_closest() function
  • getting model to "read itself" via [model: read: model_file];
hits function as used by test_hits (asg 5)
  • pass-by-reference arguments of vec_t *hit and vec_t *N
  • asg 5 pre-dates lab 11, so complete asg 5 first
  • model_t and camera_t objects
Basic ray caster in Objective-C (asg 7, a re-do of asg 3)
  • take out image writing loop from within nested for loops
  • run two set of nested for loops one after the other, the second set of for loops just writes image data to file (can use NSdata instead)
  • can use timer_t to time first set of nested for loops

Thu. Mar.07 17 Assignment 4 due (23:59:59). Solution: asg04.tar.gz
Assignment 5

Midterm answers

Tue. Mar.12
Lab 9: object pixel_t, object material_t

Dr. D. out of town

18 Reading day
Thu. Mar.14
Dr. D. out of town
19 Jo Anna Eason: Windows 8 Presentation (out sick)
Tue. Mar.19
20 Spring Break
Thu. Mar.21 21 Spring Break
Tue. Mar.26
Lab 10: object object_t, object plane_t
22 Assignment 5 due (23:59:59). Solution: asg05.tar.gz
Assignment 6

Objective-C list_t (doubly-linked) and idea of a separate list iterator (lab 12)

  • two problems with old, singly-linked list
  • the doubly-linked list
  • writing your own iterators
Thu. Mar.28 23 Objective-C sphere_t class and virtual hits function
  • ray/sphere intersection
  • ray_trace call
  • light_t object
  • rendering equation: ambient and diffuse components (Lambert's Law)
  • pixel_t clamp function
Tue. Apr.02
Lab 11: hits, find_closest

See also: Lab 11 redux: hits, find_closest

24 Reflecting the ray
  • rendering equation: specualr component (Phong model)
  • recursive call to ray_trace function
  • final color composite (linear interpolation)
Thu. Apr.04 25 Assignment 6 due (23:59:59). Solution: asg06.tar.gz
Assignment 7

Ray tracing extensions

  • ray objectification
  • vector reflect, refract functions
  • ray transmission
  • bounded planes
  • depth of field
  • shadow casting
Tue. Apr.09
Lab 12: object list_t, object litr_t
(doubly-linked list with iterator object)
26 Objective-C frameworks (like C library or C++ STL)
  • NSArray
  • NSNumber (Assignment 4 redux with "temlatized" rgb_t object))
  • NSMutableDictionary
  • NSSet
Objective-C file output
  • NSMutableData
  • NSFileManager
Thu. Apr.11 27 Assignment 7 due (23:59:59). Solution: asg07.tar.gz Assignment 7 review

Assignment 8

C++

  • class
  • iostream
  • polymorphic (virtual) functions
See:
Tue. Apr.16
Lab 13: None
28 C++ STL
  • containters
  • iterators
  • templates
Thu. Apr.18 29 Jo Anna Eason: Windows 8 Presentation (2nd attempt)
Tue. Apr.23 30 Assignment 8 due (23:59:59). Solution: asg08.tar.gz

Final exam review

Thu. Apr.25
Dr. D. out of town
31 Dead Day
Fri. May.0345 FINAL EXAM 11:30am-2:00pm
10 questions, non-uniform weighting, covering:
  • Makefiles
  • C programming
  • Objective-C programming
  • Objective-C polymorphism
  • Objective-C iterators
  • Objective-C Foundation classes (NSNumber, NSArray, NSEnumerator)