// CSC. Computer Graphics Lecture Kasun@dscs.sjp.ac.lk Department of Computer Science University of Sri Jayewardanepura Polygon Filling Scan-Line Polygon Fill Algorithm Span Flood-Fill Algorithm Inside-outside Test Odd-Even Rule onzero Winding umber Rule Marching Cubes // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental algorithm known as the scan-line algorithm // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Scan Line // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5
// ymax xmin slope Edge Table (ET) Entry The Scan-Line Polygon Fill Algorithm (Example) Polygon = {A, B, C, D, E, F, G} Polygon = {(, ), (, ), (,5), (, ), (, 5), (, ), (5, 5)} F D EF DE -5/ / E C 5 CD FA A B AB BC -5/ 5 / Scan Line The Scan-Line Polygon Fill Algorithm (Example) The Scan-Line Polygon Fill Algorithm Dealing with vertices
// The basic scan-line algorithm is as follows: Find the intersections of the scan line with all edges of the polygon Sort the intersections by increasing x coordinate Fill in all pixels between pairs of intersections that lie interior to the polygon // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Over the last couple of lectures we have looked at the idea of scan converting lines The key thing to remember is this has to be FAST For lines we have either DDA or Bresenham For circles the mid-point algorithm // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 5 // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP
// // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Another approach to area filling is to start at a point inside a region and paint the interior outward toward the boundary. If the boundary is specified in a single color, the fill algorithm processed outward pixel by pixel until the boundary color is encountered. A boundary-fill procedure accepts as input the coordinate of the interior point (x, y), a fill color, and a boundary color. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP The recursive boundary-fill algorithm:. Start from an interior point.. If the current pixel is not already filled and if it is not an edge point, then set the pixel with the fill color, and store its neighboring pixels ( or -connected) in the stack for processing. Store only neighboring pixel that is not already filled and is not an edge point.. Select the next pixel from the stack, and continue with step. The order of pixels that should be added to stack using -connected is above, below, left, and right. For -connected is above, below, left, right, above-left, aboveright, below-left, and below-right.
// -connected (Example) -connected (Example) Start Position 5 -connected (Example) -connected (Example) -connected (Example) -connected (Example) 5 5 5
// -connected (Example) Start Position 5 5 5
//
// Since the previous procedure requires considerable stacking of neighboring pixels, more efficient methods are generally employed. These methods (Span Flood-Fill) fill horizontal pixel spans across scan lines, instead of proceeding to -connected or -connected neighboring pixels. Then we need only stack a beginning position for each horizontal pixel spans, instead of stacking all unprocessed neighboring positions around the current position. 5 Span Flood-Fill Algorithm The algorithm is summarized as follows: Starting from the initial interior pixel, then fill in the contiguous span of pixels on this starting scan line. Then locate and stack starting positions for spans on the adjacent scan lines, where spans are defined as the contiguous horizontal string of positions bounded by pixels displayed in the area border color. At each subsequent step, unstack the next start position and repeat the process. 5 S 5
// 5 S 5 S 5 5 5 5 5 5 S 5 5 S 5 5 5 5 5 5 5 5 S 5 5 S 5 5 5 5
// 5 5 5 S 5 S 5 5 55 5 5 5 5 S 5 S 5 5 5 5 5 5 5 S 5 S 5 5 5
// 5 5 S 5 Flood Fill Algorithm Sometimes we want to fill in (recolor) an area that is not defined within a single color boundary. We paint such areas by replacing a specified interior color instead of searching for a boundary color value. This approach is called a flood-fill algorithm. Flood Fill Algorithm We start from a specified interior pixel (x, y) and reassign all pixel values that are currently set to a given interior color with the desired fill color. If the area has more than one interior color, we can first reassign pixel values so that all interior pixels have the same color. Counting umber Methods Odd-Even Rule onzero winding number rule Using either -connected or -connected approach, we then step through pixel positions until all interior pixels have been repainted. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Count the edge crossing along the line from any point (x,y) to infinity. If the number of interactions is odd, then the point (x,y) is an interior point; Else, it is an exterior point. Give directions to all the edges of the polygon. to all upward edges and - for others. Check the sum of scan line. If it is non-zero, then it is an interior point, otherwise it is an exterior point. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP
// Vertices and Edges Surface in Euclidean space defined by a parametric equation with two parameters A set of weighted control points determine the location of individual surface points The come in several flavors including Bezier, B-Spline, URBS
// Marching Cubes (Geometric) BOO - branch-on-need octree (Geometric) ISSUE - Isosurfacing in Span Space with Utmost Efficiency (Span Space) Interval Tree (Span Space) Contour line (isoline): the same scalar value, or isovalue A contour C is defined as all points p, in a dataset D, that have the same scalar value x: s(p) = x. For D dataset: contour line (isoline); For D dataset: contour surface (iso-surface) Fig 5.. Relationship between color banding and contouring // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Contour properties: Closed curve or open curves ever stop inside the dataset itself ever intersects itself o intersect of an isoline with another scalar value Contours are perpendicular to the gradient of the contoured function (Fig 5.) Fig 5.. The gradient of a scalar field is perpendicular to the field's contours Fig 5.. Isoline properties // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP
// Given a discrete, sampled dataset, compute contours Contouring need At least piecewise linear, C dataset The complexity of computing contours The most popular method D: Marching Squares ( 5..) D: Marching Cubes ( 5..) Fig 5.. Constructing the isoline for the scalar value v =.. The figure indicates scalar values at the grid vertices. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Fig5.. Topological states of a quad cell (marching squares algorithm). Red indicates "inside" vertices. Bold indices mark ambiguous cases. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Listing 5.. Marching squares pseudocode // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Similar to Marching Squares but D versus D = 5 different topological cases; Reduced to only 5 by symmetry considerations topological states (Fig 5.) William E. Lorensen, Harvey E. Cline: Marching Cubes: A high resolution D surface construction algorithm. In: Computer Graphics, Vol., r., July International Conference on Computer Graphics and Interactive Techniques (ACM/SIGGRAPH ) Computes polygons where the isosurface passes through eight nearest neighbors Gradient of scalar value at each grid point used for surface normal Other algorithms are always compared to Marching Cubes // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP
// Marching Cubes is an algorithm which creates triangle models of constant density surfaces from D medical data. Computed Tomography (CT) Magnetic Resonance (MRI) Single-Photon Emission Computed Tomography (SPECT) Each scanning process results in two dimensional slices of data. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Construction/Reconstruction of scanned surfaces or objects. Problem of interpreting/interpolating D data into D visuals. Marching Cubes provides a new method of creating D surfaces. High resolution surface construction algorithm. Extracts surfaces from adjacent pairs of data slices using cubes. Cubes march through the pair of slices until the entire surface of both slices has been examined. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Load slices. Create a cube from pixels on adjacent slices. Find vertices on the surfaces. Determine the intersection edges. Interpolate the edge intersections. Calculate vertex normals. Output triangles and normals. Uses identical squares of four pixels connected between adjacent slices. Each cube vertex is examined to see if it lies on or off of the surface. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5
// There are =5 ways the surface may intersect the cube Triangulate each case using the symmetries reduces those 5 cases to 5 patterns // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 Unique cube configurations that can be rotated and reflected to 5 configurations // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Fig 5.. Topological states of a hex cell (marching cubes algorithm). Red indicates "inside" vertices. Bold indices mark ambiguous cases. Fig 5.. Ambiguous cases for marching cubes. Each case has two contouring variants. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP
// Pixels on the slice surfaces determine D surfaces. 5 surface permutations, but only unique patterns. A normal is calculated for each triangle vertex for rendering. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Pros: Simple rendering and manipulation High resolution Cons: Possible holes in the model Model complexity Determine triangles contained by a cube. Determine which cube edges are intersected. Interpolate intersection point using pixel density. Calculate unit normals for each triangle vertex using the gradient vector. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Utilizes pixel, line and slice coherency to minimize the number of calculations. Can provide solid modeling. Can use conventional rendering techniques and hardware. o user interaction is necessary. Enables selective displays. Can be used with other density values. Variations can increase/decrease surface density. // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP
// MRI scan data wavy pattern: Caused by subsampling Fig 5.5. Ringing artifacts on isosurface. (a) Overview. (b) Detail mesh. General rule: most isosurface details that are under or around the size of the resolution of the iso-surfaced dataset can be either actual data or artifact should be interpreted with great care Can draw more than a single iso-surface of the same dataset in one visualization (Fig 5.) // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP Fig 5.. Two nested isosurfaces of a tooth scan dataset Isosurfaces and isolines are strongly related Fig 5.. Isosurfaces, isolines, and slicing // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP 5 // Kasun@dscs.sjp.ac.lk - Faculty of Applied Sciences of USJP