18 Curves and Surfaces III Based on EA
计算机图形学讲义-18 Curves and Surfaces (III) 姜明 北京大学数学科学学院 Based on [EA], Chapter 10. 更新时间 2020/11/26 3: 20: 43
计算机图形学讲义-18 Outline • • Rendering of Curves and Surfaces The Utah Teapot Algebraic Surfaces Curves and Surfaces in Open. GL
计算机图形学讲义-18 Rendering of Curves and Surfaces • Rendering methods – Compute points on the object that are the intersection of rays from the COP through pixels with the object. • This requires the solution of nonlinear equations too complicated to be practical. – Evaluate the curve or surface at a sufficient number of points so that it can be well approximate with the flat objects. • We focus on the 2 nd approach.
计算机图形学讲义-18 Methods • • Polynomial Evaluation Methods Recursive Subdivision of Bezier Polynomials Rendering of Other Polynomial Curves by Subdivision of Bezier Surfaces
计算机图形学讲义-18 Horner’s Method for Polynomial Computation • We can evaluate p(u) at some set of values {uk}. • We can use a polyline (or GL_LINE_STRIP) to approximate the curve. • The evaluation is carried out by Horner’s method.
计算机图形学讲义-18 Forward Difference • Method of forward difference for uniformly spaced points {uk}. • O(n) additions and no multiplications when the step-length is 1.
计算机图形学讲义-18 Forward Difference: example
计算机图形学讲义-18 de Casteljau Recursion of Bezier Polynomials • Based on the use of convex hull: the curve must lie within the convex hull of the 4 control points. • Based on the idea that “any polynomial and any part of a polynomial is a Bezier polynomial for properly chosen control data”
计算机图形学讲义-18 Recursive Subdivision of Bezier Polynomials • Divide the curve into two separate parts, l(u) and r(u). • Each of l(u) and r(u) has 4 new control points that define the polynomial and form the new convex hull. • It is a recursive process, until the flatness criterion is satisfied. • Flatness test: the deviation of l 1 and l 2 from the line segment from l 0 to l 3 is small.
计算机图形学讲义-18 New Control Points
计算机图形学讲义-18 Every Curve is a Bezier Curve • We can render a given polynomial using the recursive method if we find control points for its representation as a Bezier curve • Suppose that p(u) is given as an interpolating curve with control points q p(u)=u. TMIq • There exist Bezier control points p such that p(u)=u. TMBp • Equating and solving, we find p=MB-1 MI 11
计算机图形学讲义-18 Example These three curves were all generated from the same original data using Bezier recursion by converting all control point data to Bezier control points Bezier Interpolating B Spline 12
计算机图形学讲义-18 Rendering of Other Polynomial Curves by Subdivision • Any polynomial is a Bezier, a B-spline, a Hermite, and any polynomial, for a properly selected set of control points. • We can convert other curve form to Bezier and apply the subdivision algorithm. Bezier Interpolating B-Spline
计算机图形学讲义-18 Subdivision of Bezier Surfaces Subdivide in v and u directions, respectively.
计算机图形学讲义-18 Pros vs Cons • Advantages – Only shifts (division by 2) and adds. – It can be done adaptively. • Adaptive Subdivision of Bezier Curves • Disadvantages – if multiple patches are combined to form a description of a complex shape, there may be problems with normal interpolation across patch boundaries, and with cracks forming at patch boundaries. – http: //web. cs. wpi. edu/~matt/courses/cs 563/talks/surfa ce/bez_surf. html
计算机图形学讲义-18 Bezier surface patches rendered by subdivision algorithm Cracking between Bezier patches subdivided to different depths http: //web. cs. wpi. edu/~matt/courses/cs 563/talks/surface/bez_surf. html
计算机图形学讲义-18 The Utah Teapot • • • – – – Most famous data set in computer graphics Widely available as a list of 306 3 D vertices and the indices that define 32 Bezier patches teapot. c 函数 draw_patch(); divide_curve(); divide_patch(); A more efficient implementation is based on the Bezier curve functions: bteapot. c.
计算机图形学讲义-18 Histroy • • • The original, physical teapot was purchased from ZCMI (a department store in Salt Lake City, Utah) in 1974. It was donated to the Boston Computer Museum in 1984 where it was on display until 1990. It now resides at the Computer History Museum in Mountain View, California. • • • It's not just any teapot - it's 'the' teapot. - http: //en. wikipedia. org/wiki/Utah_teapot - http: //www. osnews. com/story/19399/The_History _of_the_Teapot Newell needed a moderately simple mathematical model of a familiar object for his work. His wife Sandra Newell suggested modelling their tea service since they were sitting down to tea at the time. He got some graph paper and a pencil, and sketched the entire teapot by eye. Then he went back to the lab and edited bézier control points on a Tektronix storage tube, again by hand. – A special monochromatic CRT.
计算机图形学讲义-18 Martin Newell’s drawing of the Utah Teapot Original data • The actual teapot is skinnier than many of its computerized images because the data was created for the rectangular pixels of early displays. • It has become something of an in joke to hide a Utah teapot somewhere in one of the film's scenes. - As displayed at the Computer History Museum in Mountain View, California (1990 -present). - https: //design. osu. edu/carlson/history/images/u tah_teapot. jpg - http: //graphics. wikia. com/wiki/Utah_teapot http: //www. computerhistory. org/revolution/comp uter-graphics-music-and-art/15/206
计算机图形学讲义-18 Algebraic Surfaces • • • Quadrics Rendering of Surfaces by Ray Casting Subdivision Curves and Surfaces
计算机图形学讲义-18 Curves and Surfaces in Open. GL • • • Bezier Curves Bezier Surfaces Displaying the Teapot NURBS Functions Quadrics
计算机图形学讲义-18 Bezier Curves • Evaluation of Bernstein polynomials. • Functions: – gl. Map 1 f – gl. Eval. Cood 1 f • For uniform grids – gl. Map. Grid 1 f – gl. Eval. Mesh 1
计算机图形学讲义-18 One-Dimensional Evaluators • Evaluate a Bernstein polynomial of any degree at a set of specified values • Can evaluate a variety of variables –Points along a 2, 3 or 4 dimensional curve –Colors –Normals –Texture Coordinates • We can set up multiple evaluators that are all evaluated for the same value Angel: Interactive Computer Graphics 5 E © Addison-Wesley 2009 23
计算机图形学讲义-18 Setting Up an Evaluator what we want to evaluate max and min of u gl. Map 1 f(type, u_min, u_max, stride, order, pointer_to_array) separation between 1+degree of polynomial data points pointer to control data Each type must be enabled by gl. Enable(type)
计算机图形学讲义-18 Example Consider an evaluator for a cubic Bezier curve over (0, 1) point data[ ]={…………. . }; * /3 d data /* gl. Map 1 f(GL_MAP_VERTEX_3, 0. 0, 1. 0, 3, 4, data); cubic data are 3 D vertices data are arranged as x, y, z, x, y, z…… three floats between data points in array gl. Enable(GL_MAP_VERTEX_3);
计算机图形学讲义-18 Evaluating • The function gl. Eval. Coord 1 f(u) causes all enabled evaluators to be evaluated for the specified u –Can replace gl. Vertex, gl. Normal, gl. Tex. Coord • The values of u need not be equally spaced.
计算机图形学讲义-18 Example • Consider the previous evaluator that was set up for a cubic Bezier over (0, 1) • Suppose that we want to approximate the curve with a 100 point polyline gl. Begin(GL_LINE_STRIP) for(i=0; i<100; i++) gl. Eval. Coord 1 f( (float) i/100. 0); gl. End();
计算机图形学讲义-18 Equally Spaced Points Rather than use a loop, we can set up an equally spaced mesh (grid) and then evaluate it with one function call gl. Map. Grid(100, 0. 0, 1. 0); sets up 100 equally-spaced points on (0, 1) gl. Eval. Mesh 1(GL_LINE, 0, 99); renders lines between adjacent evaluated points from point 0 to point 99
计算机图形学讲义-18 Bezier Surfaces • Evaluation of Bernstein polynomials. • Functions: – gl. Map 2 f – gl. Eval. Cood 2 f • For uniform grids – gl. Map. Grid 2 f – gl. Eval. Mesh 2
计算机图形学讲义-18 Bezier Surfaces • Similar procedure to 1 D but use 2 D evaluators in u and v • Set up with gl. Map 2 f(type, u_min, umax, u_stride, u_order, v_min, v_max, v_stride, v_order, pointer_to_data) • Evaluate with gl. Eval. Coord 2 f(u, v) Angel: Interactive Computer Graphics 5 E © Addison-Wesley 2009 30
计算机图形学讲义-18 Example bicubic over (0, 1) x (0, 1) point data[4][4]={………}; gl. Map 2 f(GL_MAP_VERTEX_3, 0. 0, 1. 0, 3, 4, 0. 0, 12, 4, data); Note that in v direction data points are separated by 12 floats since array data is stored by rows
计算机图形学讲义-18 Displaying the Teapot with wireframes • bteapot. c
计算机图形学讲义-18 Rendering with Lines must draw in both directions for(j=0; j<100; j++) { gl. Begin(GL_LINE_STRIP); for(i=0; i<100; i++) gl. Eval. Coord 2 f((float) i/100. 0, (float) j/100. 0); gl. End(); gl. Begin(GL_LINE_STRIP); for(i=0; i<100; i++) gl. Eval. Coord 2 f((float) j/100. 0, (float) i/100. 0); gl. End(); }
计算机图形学讲义-18 Rendering with Lighting • If we use filled polygons, we have to shade or we will see solid color uniform rendering • Can specify lights and materials but we need normals –Let Open. GL find them gl. Enable(GL_AUTO_NORMAL); Angel: Interactive Computer Graphics 5 E © Addison-Wesley 2009 34
计算机图形学讲义-18 Displaying a Shaded Teapot • Bteapot-shaded. c for(k=0; k<32; k++) { gl. Map 2 f(GL_MAP 2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &data[k][0][0][0]); gl. Eval. Mesh 2(GL_FILL, 0, 8); }
计算机图形学讲义-18 NURBS • Open. GL supports NURBS surfaces through the GLU library • Why GLU? –Can use evaluators in 4 D with standard Open. GL library –However, there are many complexities with NURBS that need a lot of code –There are five NURBS surface functions plus functions for trimming curves that can remove pieces of a NURBS surface
计算机图形学讲义-18 NURBS Functions • nurbs. c • trim. c – The GLU library provides an additional useful facility called trimming curves. – Trimming curves are closed curves that we can use to render a surface from which the areas defined by curves have been removed. • quadric. c
计算机图形学讲义-18 Quadrics • glu. New. Quadric • glu. Quadric. Draw. Style • glu. Cylinder
计算机图形学讲义-18 Quadrics • Quadrics are in both the GLU and GLUT libraries – Both use polygonal approximations where the application specifies the resolution – Sphere: lines of longitude and lattitude • GLU: disks, cylinders, spheres – Can apply transformations to scale, orient, and position • GLUT: Platonic solids, torus, Utah teapot, cone
计算机图形学讲义-18 GLUT Objects Each has a wire and a solid form glut. Wire. Cone() glut. Wire. Torus() glut. Wire. Teapot()
计算机图形学讲义-18 GLUT Platonic Solids glut. Wire. Tetrahedron() glut. Wire. Octahedron() glut. Wire. Dodecahedron() glut. Wire. Icosahedron()
计算机图形学讲义-18 Quadric Objects in GLU • GLU can automatically generate normals and texture coordinates • Quadrics are objects that include properties such as how we would like the object to be rendered disk partial disk sphere
计算机图形学讲义-18 Defining a Cylinder GLUquadric. OBJ *p; P = glu. New. Quadric(); /*set up object */ glu. Quadric. Draw. Style(GLU_LINE); /*render style*/ glu. Cylinder(p, BASE_RADIUS, TOP_RADIUS, BASE_HEIGHT, sections, slices);
- Slides: 43