CSE 167: Assignment 3 — Bezier and B-Spline Curves
Ravi Ramamoorthi
You will use the de Casteljau Algorithm, and variations of it, to draw Bezier curves and B-Splines. You will also be asked to implement a drawing of Bezier curves using recursion. This assignment only asks you to do a 2D curve editor (and this assignment uses only no-op shaders, with most drawing done in a very basic fashion within the skeleton code). However, 2D curves can be used as elements of a 3D modeling package, for instance, to define surfaces of revolution. Thus, an extra credit only part of the assignment requests you to implement a simple modeling program in that direction.
Since some of the topics are advanced, the most helpful information will be found in the lecture material, and in the related handouts.
Post any questions you have to Piazza, since other students will want to see the answers too. Please use detailed subject headings. However, do not post anything resembling code.
Please note that this assignment (or lectures) is not available on UCSD Online (for historical reasons, this part of the course was never ported and offered as a MOOC). We do have a stand-alone code feedback system, for which we will post instructions to use on Piazza. In this case, we don’t have a differencing or grading process in the code grader, but it will provide feedback by overlaying your curve on the correct solution, and can therefore be used for automatic feedback. As in other assignments, a link to the resulting images must be included in your submission. Please note there is no image grader for this homework, only a code-grader.
for the midterm, and time is relatively short.
Download the skeleton code for the assignment. Unzip the assignment into its own directory. You can run the solution program to see how your code should behave (the exact naming of the solution is system dependent; it is a .exe file in Windows, and is called reference-solution-linux and reference-solution-osx on Linux and Mac. Of course, the binary may not be portable across Linux systems (or modern Macs) especially. As usual, please do not try to de-compile or reverse engineer the solution, nor copy from previous online or in-person classes or online solutions). Make sure your code behaves identically to the solution (checking that detail levels match). If your code works except for slightly different behavior at level 1, don’t worry about it. (Though it may be an indication of other errors).
There are two points to note. The solution (and skeleton code) can crash if you drag in the window, before pressing a number to select the type of curve. Don’t worry about this, but also don’t intentionally cause itto crash. Please select a curve by pressing a number before adding points. Most of the code skeleton should be fairly self explanatory. In general, there is a curve object in your WorkingScene called theOnlyCurve. All addition and deletion of points should be for that curve object.
Your job is simply to fill in the sections of curves2.cpp that say /* YOUR CODE HERE */ WorkingScene should be filled in first.
For the required part of the assignment (the 2D curve drawing), do not use any OpenGL calls or external libraries. The one exception to the OpenGL calls rule above, is where it says “make sure the scene gets redrawn”. The correct line to complete this operation is glutPostRedisplay() ;. Also, do not modify any files other than curves2.cpp.
For submission of the required assignment, please submit it like any other assignment following the instructions on the class assignments page. You must include a link to the full-res images from the (stand alone) code-grader, your source code for curves2.cpp and all other requirements for a submission. The logistics of the feedback server, which is standalone in this case, will be posted on Piazza.
Thereafter, you will fill in code for Bezier, Bspline and Bezier2. For Bezier, you simply divide the curve into line segments (depending on the detail parameter, there should be detail segments). Hence, all you need to do is evaluate the curve at detail+1 points, connecting these with line segments. The evaluation can be done by the deCasteljau algorithm as described in class, or you can use the explicit Bernstein-Bezier polynomial form. For Bezier2, you draw the curve by recursive subdivision, splitting it at its midpoint each time. The recursive subdivision of Bezier curves using the deCasteljau algorithm was discussed in class.
Finally, for drawing cubic Bsplines, you can either use a variant of the deCasteljau algorithm, or the B-spline matrix formula discussed in class directly. This latter formula applies since the knot spacing is uniform and the B-splines are always cubic.
Please note that the program (even solution) will not do anything if you click on control points after startup. You first need to enter the type of curve, with 0 for a basic straight line. You should read the code to figure out how to switch to Bezier and Bspline curves. Also the + and - keys are used to change the detail parameter.
The assignment skeleton code uses the vector class from the Standard Template Library (STL). It is a very powerful class, but may have a slight learning curve. It is worth investing the time to learn how to use this. Microsoft’s MSDN web site is a good source of information. There are also plenty of books and other web sites that discuss STL. If you really don’t want to use vector, figure out just enough to convert the vector of points into a form you are comfortable with before you start your manipulations of the points.
FAQ: Can I write other helper functions instead of using the given functions when implementing Bezier2?
You can change whatever you want in curves2.cpp, but please don’t change anything outside of that. Of course, you can add whatever helper functions you need inside of curves2.cpp. In all cases, the code must compile and produce output with the feedback servers (please try not to include additional system headers, since these are often system-dependent and may not work with the feedback server).