Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Algorithms Ying Zhu Georgia State University

Similar presentations


Presentation on theme: "Computer Graphics Algorithms Ying Zhu Georgia State University"— Presentation transcript:

1 Computer Graphics Algorithms Ying Zhu Georgia State University
Lecture 22 Parametric Curves & Surfaces

2 Curves and Curved Surfaces
Modeling curved surfaces using polygon mesh requires a large number of polygons. A second general method is to use Parametric Bicubic Patches Describe the curves and surfaces mathematically by a small number of parameters such as a few control points Saving a few control points for surface requires much less storage than saving 1000 triangles with normal vector information at each vertex Plus the control points accurately describe the real surface However, such savings only apply to the application stage Eventually those parametric surfaces will be converted to triangles which are then rendered by graphics hardware

3 Parametric Curves and Surfaces
The curve is a basic geometric building block. Most high-end modeling systems use splines or parametric curves and surfaces. They provide a more compact representation of smoothly curved objects. And it’s easy to manipulate.

4 Curves and Surfaces Curves are one parameter entities of the form P(a) where the function is nonlinear Surfaces are formed from two-parameter functions P(a, b) Linear functions give planes and polygons P(a) P(a, b)

5 Parametric Curves A normal 3D curve representation might be the following: Explicit line equation: x = x, y = f(x), z = g(x) Implicit line equation: Ax + By + C = 0 There are potential problems with the above representations. It may be difficult to determine the start - end points of a curve segment. So instead use the parametric form: x = X(t), y=Y(t), z=Z(t) with 0.0 < t < 1.0 on the curve segment. Note that it is now easy to determine the end points since the start point corresponds to t = 0.0 and the end point corresponds to t = 1.0.

6 Parametric Polynomial Curves
A parametric polynomial curve is a parametric curve where each function x(t), y(t), z(t) is described by a polynomial: Polynomial curves have certain advantages: Easy to compute Indefinitely differentiable

7 Polynomials A polynomial is a function of the form
n is the degree of the polynomial The order of the polynomial is the number of coefficients it has. Order = degree + 1. Linear Quadratic Cubic

8 Curve Drawing How to draw a curve interactively?
Specifying coefficients of a polynomial is not very intuitive. We want: Predictable control: curves don’t wiggle Multiple values: curves of arbitrary length Local control: local edits have local effects Versatility: be able to draw any curve Continuity: smoothness guarantees Spline curves gives all of these.

9 Spline The word “spline” comes from ship building with wood.
A wooden plank is forced between fixed posts, called “ducks”. The ducks corresponds to control points in interactive curve design. Splines are being used for designing ship hulls, automobiles, and aircraft fuselage and wings.

10 Spline

11 What is a Spline? Smooth curve defined by some control points
Moving the control points changes the curve Control points: a set of points that influence the curve’s shape. Hull: the lines that connect the control points. BSpline

12 Bézier (approximation)
Splines Interpolation: curve passes through the control points. Approximation: control points merely influence shape. Interpolation Bézier (approximation)

13 Basic Problems Case 1: we have a curve ( or surface ) with a few known points and want to interpolate between them. We could do straight line interpolation, but a better method is curve interpolation. Case 2: we want to synthesize a curve or a surface, for example in designing an automobile. Then let designer specify a set of control points (Knots) which define the curve/surface. The computer then computes and displays the curve. As the designer modifies the control points the curve changes.

14 Interpolation Curves Curve is constrained to pass through all control points Given points P0, P1, ... Pn, find lowest degree polynomial which passes through the points x(t) = an-1tn a2t2 + a1t + a0 y(t) = bn-1tn b2t2 + b1t + b0

15 Interpolation vs. Approximation Curves
Interpolation Curve – over constrained → lots of (undesirable?) oscillations Approximation Curve – more reasonable?

16 Specifying Splines Spline curve: any composite curve formed with piecewise parametric polynomials subject to certain continuity conditions at the boundary of the pieces. What is “piecewise”? What is “continuity”?

17 Piecewise Curves We want to represent a curve as a series of curves pieced together. A piecewise parametric polynomial curve uses different polynomial functions for different parts of the curve. Provides flexibility How do we fit the pieces together and make it look smooth? E.g. if we design an airplane wing with slop or position discontinuity: CRASH!

18 Continuity definitions:
C0 continuous : curves are joined curve/surface has no breaks/gaps/holes "watertight“, position are the same C1 continuous: first derivatives are equal curve/surface derivative is continuous "looks smooth, no facets“, slopes are the same C2 continuous: first and second derivatives are equal. curve/surface 2nd derivative is continuous Actually important for shading

19 Parametric Cubic Curves
To ensure C2 continuity, the parametric curve function must be of at least degree 3. Parametric cubic function: The key to polynomial spline is deriving their coefficients given a set of control points and continuity conditions.

20 Bezier curve and Bezier Surface
A Bezier curve is a vector-valued function of one variable C(u) = [X(u) Y(u) Z(u)] where u varies in some domain (say [0, 1]). A Bezier surface patch is a vector valued function of two variables S(u, v) = [X(u,v) Y(u, v) Z(u, v)] where u and v can both vary in some domain For each u (or u and v), the formula for C() (or S()) calculates a point on the curve (or curved surface)

21 Cubic Bézier Curve 4 control points
Curve passes through first & last control point Curve is tangent at P1 to (P2-P1) and at P4 to (P4-P3)

22 Cubic Bézier Curve Example

23 Bézier Curves Have a bounding convex hull defined by the control points. Every control point affects the entire curve Not simply a local effect More difficult to control for modeling Bezier curve demo

24 Bezier Splines To build more complex curves we can piece together different Bezier curves to make Bezier Splines. C0: match endpoints of curve segments C1: match tangents; align the last two points of the first curve with the first two points of the second curve. C2: hard, constrains next three control points

25 Connecting Cubic Bézier Curves
How can we guarantee C0 continuity (no gaps)? How can we guarantee C1 continuity (tangent vectors match)? Asymmetric: Curve goes through some control points but misses others

26 Higher Order Curves BSplines NURBS
BSplines are a generalization of the Bézier curves NURBS NURBS are a generalization of BSpline curves

27 BSplines Problems with Bezier curves
Non-localness: modifying one control points affects the curve everywhere Difficulty of matching a Bezier curve to a given set of points BSpline curves does not suffer these drawbacks to the same degree “B” in BSpline stands for Basis B-splines are a generalization of the Bézier curves and can be further generalized to NURBS, allowing the accurate modelling of more general classes of geometry.

28 Cubic BSplines ≥ 4 control points
Curve is not constrained to pass through any control points

29 Cubic BSplines Can be chained together Better control locally

30 Bézier curve is not the same as BSpline
Relationship to the control points is different Bézier BSpline

31 BSpline Curves Demo

32 BSpline Properties Local control: each control point determines local shape Approximating: does not interpolate control points. Convex hull: curve contained in polygon [P1, P2, …, Pn+1].

33 NURBS (generalized BSplines)
Disadvantages of the curves discussed so far: Cannot create common conic shapes such as circles, ellipse, parabolas, etc. NURBS are generalizations of both B-splines and Bézier curves NURBS: Non-Uniform Rational BSplines Useful in 3D modeling Most advanced modeling tools support NURBS.

34 NURBS NURBS are useful for a number of reasons, they:
Approximate splines, interpolate the first and last control points. Offer one common mathematical form for both standard analytical shapes (e.g. conics) and free form shapes; Provide the flexibility to design a large variety of shapes; Can be evaluated reasonably fast by numerically stable and accurate algorithms; Are invariant under affine as well as perspective transformations; Are generalizations of non-rational B-splines and non-rational and rational Bézier curves and surfaces. They can accurately represent standard geometric objects like lines or conic sections as well as free form geometry.

35 Types of Splines Hermite Bezier Uniform B-Splines NURBS Convex Hull
n/a Yes Number of Parameters 4 5 Inherent Continuity C0 C2 Achievable Continuity C1 Interpolating No

36 Curves in OpenGL In OpenGL, the basic tool to draw 2D curves and 3D surfaces is evaluator. You specify array of control points Evaluate coordinates at u (or u and v) to generate vertex coordinates

37 Drawing Bezier Curves in OpenGL
Basic steps: Define control points in an array Set up curve evaluator: glMap1f(…) Enable evaluator: glEnable(GL_MAP1_VERTEX_3) Use glEvalCoord1*() instead of glVertex3*() to specify vertices. Refer to OpenGL Man Pages for glMap*(), glEvalCoord*()

38 glMap1*() Defines a one-dimentional evaluator
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]); glEvalCoord1f ( (GLfloat)i /(GLfloat)num_points);

39 Example GLfloat ctrlpoints[4][3] = {
{-4.0, -4.0, 0.0}, {-2.0, 4.0, 0.0}, {2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}}; Void init() { glMap1f(GL_MAP1_VERTEX_3, // set up Bezier curve 0.0, // lower u range 1.0, // upper u range 3, // distance between points in the data 4, // number of control points &ctrlpoints[0][0]); // array of control points glEnable(GL_MAP1_VERTEX_3); // enable the evaluator }

40 Example Void display() { … glBegin(GL_LINE_STRIP);
for (i=0; i <= num_points; i++) glEvalCoord1f ((GLfloat)i / (GLfloat)num_points); glEnd(); }

41 Surface Representation
Implicit representation for surfaces f(x, y, z) = 0 Plane: ax + by + cz + d = 0 Sphere: x^2 + y^2 + z^2 – r^2 = 0 Parametric form for surfaces x = X(u, v) y = Y(u, v) z = Z(u, v)

42 Parametric Polynomial Surfaces
We can define a parametric polynomial surface in generic terms: We must specify 3(n+1)(m+1) coefficients to determine a particular surface. We shall always take n=m and let u, and v vary over the rectangle 0<=u<=1, 0<=v<=1.

43 Bezier Surface Patches
Specify Bezier patch with 4x4 control points The corresponding Bezier patch is Where

44 Bezier surface properties
Some properties of Bézier surfaces: A Bézier surface will transform in the same way as its control points under all linear transformations and translations. All u=constant and v=constant lines in the (u,v) space, and, in particular, all four edges of the deformed (u, v) unit square are Bézier curves. A Bézier surface will lie completely within the convex hull of its control points, and therefore also completely within the bounding box of its control points in any given Cartesian coordinate system. The points in the patch corresponding to the corners of the deformed unit square coincide with four of the control points. However, a Bézier surface does not in general pass through its other control points.

45 Bezier surface in computer graphics
Bézier surfaces are superior to polygon meshes since they are much more compact, easier to manipulate, and have much better continuity properties. Other common parametric surfaces such as spheres and cylinders can be well approximated by relatively small numbers of cubic Bézier patches. However, Bézier patch meshes are difficult to render directly. Difficult to combine directly with perspective projection algorithms. Calculating their intersections with lines is difficult, making them awkward for pure ray tracing Therefore Bézier patch meshes will eventually be decomposed into meshes of triangles by 3D rendering pipelines.

46 Drawing Bezier surfaces in OpenGL
Steps are similar to the procedure for Bezier curves Define evaluators with glMap2*() Enable them by passing the appropriate value to glEnable() Invoke them either by calling glEvalCoord2() between a glBegin() and a glEnd() or by specifying and then applying a mesh with glMapGrid2() and glEvalMesh2()

47 glMap2*() Defines a 2D evaluator
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlpoints[0][0][0]);

48 glMapGrid*() & glEvalMesh*()
glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); Internally will call glEvalCoord2()

49 Example GLfloat ctrlpoints[4][4][3] = {
{ {-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0}, {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}}, { {-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}}, { {-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0}, {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}}, { {-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0}, {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}} };

50 Example void init(void) {
glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlpoints[0][0][0]); glEnable(GL_MAP2_VERTEX_3); glEnable(GL_AUTO_NORMAL); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); }

51 Example // Draw a filled Bezier surface void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(85.0, 1.0, 1.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); glPopMatrix(); glFlush(); }

52 Example // Display a wireframe Bezier surface void display(void) { int i, j; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glPushMatrix (); glRotatef(85.0, 1.0, 1.0, 1.0); for (j = 0; j <= 8; j++) { glBegin(GL_LINE_STRIP); for (i = 0; i <= 30; i++) glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0); glEnd(); glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0); glEnd(); } glPopMatrix (); glFlush(); }

53 BSpline Surfaces BSpline surfaces are similar to Bezier surfaces
use 16 control points However, only use the patch in the central area. Need nine times as many splines as for Bezier.

54 BSpline Surfaces v.s. Bezier Surfaces
BSpline surfaces are more expensive to construct than Bezier surfaces BSpline surfaces are smoother at joint points Additional continuity at the edges from the BSpline curves Better local control How far away does a control point change propagate?

55 BSpline basis functions
NURBS Surface A NURBS surface of degree (p, q) is defined by BSpline basis functions Control points Weight

56 NURBS Surfaces Properties
Preserve convex-hull and continuity properties of BSplines NURBS curves are handled correctly in perspective views Curves with transformed points = transformed curve. BSpline will not be handled correctly in perspective view. Widely used in modeling tools such as 3DS Max, Maya, etc.

57 Creating NURBS surfaces in OpenGL
The OpenGL GLU library provides NURBS interface built on top of the OpenGL evaluator commands See example

58 Parametric Surfaces and Polygon Mesh
Parametric Surfaces have more complex mathematical descriptions. In many cases, this added complexity is still cheaper than describing an object with a multitude of triangles. However, 3D graphics cards only understand triangles. Eventually parametric curved surfaces have to be tessellated (converted to triangles) by either API, graphics card driver, or graphics hardware. Hardware tessellation yields better performance. Less traffic over AGP port

59 Subdivision Surfaces vs. NURBS
cheap in both memory and computation.  You get a smooth surface with relatively few points which can also be animated.  NURBS patches also have inherent uv coordinates and can be patched together in such a way to insure tangency across seams (to a certain extent).

60 Subdivision Surfaces vs. NURBS
Work with arbitrary topology Easy to implement Local continuity control Local refinement  The drawback is that uv coordinates are not defined for you, so care must be taken in texturing. Also widely supported in modeling tools

61 Readings “OpenGL Programming Guide,” chapter 12 “Evaluators and NURBS”
Code reading bezmesh.c, bezsurf.c, texturesurf.c

62 Next lecture Advanced modeling techniques


Download ppt "Computer Graphics Algorithms Ying Zhu Georgia State University"

Similar presentations


Ads by Google