460 likes | 528 Vues
Advanced Computer Graphics: Parametric Curves and Surfaces. James Gain Department of Computer Science University of Cape Town jgain@cs.uct.ac.za. Objectives. To introduce general concepts associated with all parametric curves To list the desirable properties of a curve formulation
E N D
Advanced Computer Graphics:Parametric Curves and Surfaces James Gain Department of Computer ScienceUniversity of Cape Town jgain@cs.uct.ac.za Advanced Computer GraphicsCollaborative Visual Computing Laboratory
Objectives • To introduce general concepts associated with all parametric curves • To list the desirable properties of a curve formulation • To consider the smoothness (continuity) and rendering of curves • To derive the Hermite and Power curves Advanced Computer Graphics
Motivation • Representing curves as polylines, and surfaces as a collection of polygons is problematic: • requires large amounts of co-ordinate and connectivity information • difficult to exactly design smoothly varying shapes • Need a compact and easily manipulated high-level representation of smoothly varying curves and surfaces. • But must be internally convertible to line segment or polygon approximation for polygon-scan conversion rendering. Advanced Computer Graphics
Spline • A thin flexible wooden slat. • Weights (ducks) fix the spline to go through certain points. • Stiffness makes the curve smooth but not too wiggly. • Features: • Controllable • Smooth but minimum curvature • Þ Can be implemented as parametric polynomial piecewise curves. Advanced Computer Graphics
Formulations • Explicit: • y and z represented as functions of x: • 2D line: • Implicit • function relating all coordinates: • 2D line: • Weaknesses: • may have too many or too few solutions • affine transformations can be difficult • vertical tangents (with infinite slope) present problems • difficult to join separate curves together smoothly • Strengths: • good for point on curve tests Advanced Computer Graphics
Parametric Formulation • Express points on the curve in terms of an indirect control parameter, t: • Generally, the parameter is clamped, • 2D Line: • Weaknesses: • point on curve tests are difficult • Strengths: • calculating slope • generating points on the curve • joining separate curves together • easier to apply affine transformations Advanced Computer Graphics
Polynomials • An n-th degree polynomial has the form: • Where are the coefficients and are the power terms. • The degree, , is the highest power to which is raised. • The order is the number of coefficients ( ). Constant: Linear: Quadratic: Cubic: Advanced Computer Graphics
Polynomial Curves • Polynomial curves are represented by a sum of polynomials (basis or blending functions) each weighted by a 2D or 3D coefficient (control points) where the parameter has a restricted range • Often represented in the form: • Where is a point on the curve, are the control points and are the basis functions. • Example: Advanced Computer Graphics
Basis Functions • The degree of the curve is the degree of the highest basis function (sum of polynomials is a polynomial) • There are order=n+1 basis functions and control points. For instance, a cubic curve has 4 control points. • The contribution of a control point to the curve at position is determined (weighted) by the basis function . • We would like there to be an intuitive relationship between the control points and the curve. This depends on the choice of basis functions. • If successive control points are joined by line segments this is called the control polygon. Advanced Computer Graphics
Piecewise Curves • How do we create interesting and complex curves: • Degree raising: • Increase the degree of the curve (allows more inflections). • Problems: cost of operations on the curve depend on the degree; each control point influences the whole of the curve • Piecewise: • Join the heads and tails of different curves. • Have to make sure that the joins are smooth. Advanced Computer Graphics
Continuity • Geometric continuity ( ) is visually smooth. The derivative vectors agree in direction but not magnitude. • Full continuity ( ) is parametrically smooth. The derivative vectors agree in both direction and magnitude. Advanced Computer Graphics
Choosing degree and continuity • Cubic Degree : • High enough degree to be truly 3D and have an inflection point • Low enough degree to be efficient • Continuity for Modelling: • Visual appearance is important so geometric continuity generally sufficient • Continuity for Animation: • A camera or object follows the curve usually with constant size steps in . • The change in speed and/or acceleration along the curve is important so parametric continuity is required. Advanced Computer Graphics
Exercise: Properties • Question: • What features are important for a curve representation? • Answers: • Can guarantee and control levels of continuity • Compact to store • Efficient to render and interrogate • A geometrically intuitive relationship between the control points and the curve • Must not oscillate • Should be able to represent “all” shapes • Easy to transform (scale, rotate, translate) and modify Advanced Computer Graphics
Properties • Endpoint Interpolation: • The curve passesthrough (interpolates) some (or all) of the control points. Affine Invariance: • Instead of transforming potentiallymany individual points on the curve, the control points are transformed. This is similar to the property that affine transformations preserve straight lines. Advanced Computer Graphics
More Properties Convex Hull Property: • The curve never wanders outside the convex hull. This hull is definedas the set of all convex combinationsof control points: Variation Diminishing Property: • Curves does not oscillate more than its control polygon. In 2D, no straight line can intersect the curve more times than it intersectsthe control polygon. Advanced Computer Graphics
Rendering by Evaluation • Task: convert curve to a sequence of line segments • Evaluate the curve at intervals. Join the evaluated points. • Problems: length of line segments depends on the parametrisation (will be shorter where the magnitude of the derivative is smaller) not the curvature. No guarantee that the curve will appear smooth. Advanced Computer Graphics
Rendering by Subdivision • Recursively divide the curve in half. If sufficiently flat stop recursion, otherwise subdivide further. • Need a means of subdividing and testing “flatness”. Good trade-off between visual quality and number of line segments. Advanced Computer Graphics
Power Curves • Problem: very difficult to predict the shape of the curve fromthe position of the control points. • Solution: use other basisfunctions (Hermite, Bézier). Power Basis: Advanced Computer Graphics
V V 1 0 P P 0 1 Hermite Curves • Intuitive control: two endpoints and end tangent vectors • Hermite curve equation: Advanced Computer Graphics
Derivation • Each basis function has four unknowns: • Basis functions must satisfy the following properties: • Use this information to solve for the coefficients of the basis functions. Advanced Computer Graphics
Formula • Cubic Hermite Basis: Advanced Computer Graphics
Changing length of V0 V0 P1 P0 V1 Advanced Computer Graphics
Changing direction of V0 Advanced Computer Graphics
Properties • Limited to cubic curves • Curve does not lie within the convex hull of its control points • C1 continuity is very easy to enforce (start and end points and vectors are set equal) • More popular for animation than modelling Advanced Computer Graphics
Chaikin’s Corner Cutting • Take a control polygon and cut each edge at the and marks. • Join these new points across the corners to create a refined (subdivided) control polygon. • This process can be repeated, producing a successively smoother curve. • In the limit, a quadraticcurve. • Note: each control point only influences a local portion of the curve. Advanced Computer Graphics
Objectives • To explore Bézier curves in detail • To briefly motivate for B-spline curves • To compare and contrast the curve formulations described so far • To extend from curves to surfaces • To describe the shortcomings of standard surfaces and show how subdivision surfaces avoid them Advanced Computer Graphics
Bézier Curves • Discovered independently in the early 70’s by Bézierand de Casteljau. Both worked in the automobile industry. • Bézier curves are popular because there is a clear geometric connection between the control points and the curve: • Interpolates the first and last control points: • The tangent vectors at the endpoints are aligned with the line segments, and • The curve lies in the convex hull of its control points. This is a key difference from Hermite curves. Advanced Computer Graphics
Bézier (Bernstein) Basis • Binomial coefficient function: • Read as choose , it is the number of ways of choosing items from a collection of items. • The binomial coefficients can be quickly derived using Pascal’s triangle (terms are summed from above diagonally left and right): Advanced Computer Graphics
Linear and Quadratic Bézier Curves • Linear (a line segment): • Quadratic: Advanced Computer Graphics
Cubic Bézier Curves • Cubic: Advanced Computer Graphics
Examples Advanced Computer Graphics
Properties • Endpoint interpolation • Convex Hull • Curve is an affine combination of the control points and so lies inside the convex hull. • Affine Invariance • An affine transformation of the control points is the same as transforming the curve (not true of perspective projection). • Linear Precision • A high degree Bézier curve can beforced into a straight line segmentby placing the control points on a straight line. • Variation Diminishing • The curve does not oscillate unduly. Advanced Computer Graphics
Exercise: Bézier Circles • Question: • Create a single closed cubic Bézier curve that approximates a circle. • Answer: • (a) Closed curve (b) continuous at (c) All control points are collinear which implies, by the convex hull property, that . (d) This is a point not a circle. Advanced Computer Graphics
The de Casteljau Algorithm • A recursive in-betweening (linear interpolation) process which can be used to: • Generate a point on the curve (the alternative is to evaluate the Bézier curve equation). • Split a Bézier curve into two halves. • Working from the initial control polygon (the line segments joining adjacent control points): • a point is placed of the way along each edge. • These points are joined into a new control polygon. • The process is repeated until only a single point is introduced. • This is the point at parameter on the curve. Advanced Computer Graphics
de Casteljau Specifics • The recurrence relation is: • Where are the original control points and is the point on the curve. • The intermediate control points constitute two Bézier curves split from the originalat : Advanced Computer Graphics
The Problem of Local Control • Bézier curves are geometrically intuitive but they fail to provide local control. • A designer cannot concentrate on altering part of a Bézier curve without affecting the rest. • This is because the basis functions, which define the weight (influence) given to each control point, are all non-zero over . So, each control point has some influence over the shape of the whole curve. • Solution: build a curve by piecing together polynomial segments. • This is the purpose behind B-spline curves. Advanced Computer Graphics
Evaluation Advanced Computer Graphics
Surfaces • Curves generalise to Surfaces: • A surface is a function of two variables rather than just one . • A rectangular surface has a curve running along each of its four edges. • A rectangular surface can be envisioned as a curve which changes its shape as it is swept through space. Each control point of the initial curve is moved along a path which is itself a curve. • Surface Definition: • An -degree by -degree Bézier patch is defined by control points : Advanced Computer Graphics
Surface Properties • Adjacent control points can be connected to form a control net (which serves the same purpose as a control polygon). • The degrees along and do not have to match. • B-spline surfaces are a similar extension of B-spline curves. • Continuity between patches: • C0: continuous in position. The four edge c.p. must match. • C1: continuous in position and tangent vector. The two control points on either side of each edge c.p. must be colinear with the edge point and each other and be equidistant from the edge point. • Algorithms (e.g. de Casteljau subdivision) and properties (e.g. convex hull) still apply with some small modification. Advanced Computer Graphics
Example Surfaces • Example: cubic Bézier patch • The four corner c.p. are interpolated. • Each edge is a curve defined by four c.p. • There are four interior c.p. determining the inner shape. Advanced Computer Graphics
Exercise: Designing Surfaces • Question: • Specify the control points of an open-endedcontinuouscylinder with radius and height composed of twopatches. Youneed only create one patch and explain how the other follows. Advanced Computer Graphics
Rendering Bézier Surfaces • Adaptive Subdivision: Approximate the surface with planar polygons, • Check if a quadrilateral with corners at the endpoints is an adequate approximation to the surface. • If so, halt recursion. • If not, subdivide into two smaller Bézier patches using bi-parametric de Casteljau. Subdivision must alternate in and on successive recursive subdivisions. • Need to specify a tolerance for when the quadrilateral is an adequate approximation. • The set of resulting (non-planar) quadrilaterals is further subdivided into (planar) triangles. Advanced Computer Graphics
Surface Normals • Often require a surface normal (e.g. Gouraud and Phong shading) • Procedure: • Given a surface • Calculate the partial derivatives and . These are tangents to the surface. • Take the cross product to get the normal • Scale the normal so that it is a unit vector: Advanced Computer Graphics
Subdivision Surfaces • Motivation: • Creating objects from Bézier patches is very difficult if they have a non-planar topology. For instance a C1 sphere cannot be constructed from non-degenerate patches. But complex topologies and many-sided patches are possible with subdivision surfaces, • Method: • Similar to Chaikin’s corner cutting. • Start with a closed control netroughly approximating the object. • Successively refine the control net by introducing new c.p.. In the limit this produces a smooth surface. • Proviso: • There may be exception points where continuity is not as high. Advanced Computer Graphics
Doo-Sabin Subdivision • Mostly produces a quadratic B-spline surface. • Algorithm: • Input: an arbitrary open or closed polyhedron; Output: a smooth surface. • Refinement: • Find the centroid of each face (average its vertices). • Find the midpoints of all straight lines connecting the centroid to its defining vertices. • Construct a new polyhedron from these midpoints by forming: • E-faces. For a given edge there are four midpoints controlled by its endpoints. Connect these midpoints into a rectangle. • V-faces. Form a face with the midpoints that surround an original vertex. • F-faces. Connect the midpoints belonging to the same face. Advanced Computer Graphics
Curves and Surfaces in OpenGL • use Evaluators to compute points on a curve or surface. A very powerful mechanism. • setup: glMaplf(type, u_min, u_max, stride, order, point_array); • example: glMaplf(GL_MAP_VERTEX_3, 0.0, 1.0, ?, 4, data); • enable: glEnable(type); • rendering: glEvalCoordlf(u); replaces glVertex • Similar calls for creating surfaces. Advanced Computer Graphics