Homework 5: NURBS Editor

In this problem, you will create an interactive, two-dimensional B-Spline editor with OpenGL/glut. Your program should allow the user to insert and manipulate control points for a nonuniform B-Spline of order 4 (degree 3 or cubic). Read the handout on uniform and nonuniform B-splines (***See TA's helpful hints below if you're beating your head against the wall after reading the paper***). Also, this webpage on B-spline basis functions and this one on Nonuniform B-splines might be useful(and there's always wikipedia!). Both of them have little interactive spline applets. Also, Mark Meyers' lecture slides on higher order surfaces and splines are great for understanding splines mathematically and conceptually.

IT IS REQUIRED that you compute x-y values with your own implementation of the Cox de-Boor algorithm; you SHOULD NOT USE OPENGL or GLU functions to do the math or splining for you. Get the points yourself and then have OpenGL draw line segments for you.

(You can then add NURBS drawn using GLU for extra credit, of course.) Also, so you know, the next assignment uses GLU to do 3D NURBS.

TA's Helpful Hints:

Homework 5 is due on Tuesday Nov. 9 at 11:59 pm

NURBS spline of a profile of a face, polyline

Display Spline and Control Polyline

The editor should show both the spline curve and the control poly-line. The editor should start out with a predefined spline of 4 points in a U shape and a knot vector of < 0, 0, 0, 0, 1, 1, 1, 1 > :

A NURBS curve with 4 control points, U shapes

The repeat knots ensure that the curve goes from the first control point to the last one (and touches both of them).

To display the spline, you should break the continuous function (the one that only lives in the World of Mathematics) into many discrete segments via the Cox de Boor algorithm (in the handout) for blending functions, at an appropriately fine resolution (see the extra credit on adaptive parameterization).

Editing

Move Control Points -- Left-click

The editor should also allow a user to alter the control poly-line (and therefore the spline curve) after it has been created. In this editing mode, left-clicking and dragging a control point should move the point and update the spline accordingly. (For extra credit you can optimize the performance of your editor by noticing that each control point only affects a certain section of the curve-- cache the x-y values in a buffer and update the appropriate interval, etc.)

Insert Knots -- Right-click

The editor should allow a user to insert knots. When the user right-clicks, you convert the x-y point to a t value, which is basically a number between 0% and 100% (or 0.0 and 1.0) on the curve. To know where to insert this new knot value, ignore everthing about the control points and just stick it in the sequence of non-decreasing knot values at the first position available (after you caluculate the new control points from the old knot vector. see Helpful Pointer below). For example, after the program loads up, the user right-clicks 66% of the way along the curve from the first point to the last point. This knot value of .66 gets stuck between the zero and one to give the new knot vector < 0 0 0 0 .66 1 1 1 1 > Now the algorithm for knot insertion is run and the set of control points is update appropriately.

Note that this scheme won't insert points before or after the ends of the orignal U; you just move the U around and insert and move points to make the curve look the way you want. The shape of the curve is preserved and a new control point appears in the region of the curve where the user clicked. The purpose of doing this with NURBS instead of some other spline is that the curve stays the same when you use the knot insertion algorithm. For other types of splines (especially uniform ones where you don't track the knot values because they're all at the same intervals), it might make sense to insert control points without affecting other points, but for now (for the assignment and for the sake of simplicity) it is easiest to think of it as inserting a knot and then automatically changing the control points, instead of thinking of it as inserting control points.

Helpful pointer: When inserting a new knot and re-calculating control points, (1) Create a new empty control point list, (2) Insert the new knot into the knot vector, (3) Fill in the new control point list so that the control point values are affected only by old control point values (but NEW knot values).

What your program should do

Name your program editSpline. It should take no arguments, except maybe width and height (or a filename if you do the Load/Save extra credit).

    editSpline [ <xRes> <yRes> [ <spline-file> ] ]

The xRes and yRes would specify the window dimensions.

Include a README file with your code, saying what you did, how to compile and run it, and anything else you think we need to know.

Extra credit

Feel free to implement a few additional features for your editor. Points will be awarded based on the difficulty of implementation, how much you can learn from adding those features, and how much more useful your program will be. You may want to talk to a TA before implementing any additions.

Some things to consider adding: