Scalar Algorithms: Contouring Computer Animation and Visualisation Lecture tkomura@inf.ed.ac.uk Institute for Perception, Action & Behaviour School of Informatics Contouring Scaler Data
Last Lecture... Colour mapping Designing the colour lookup table / transfer function Interpolating in various colour spaces HSV, RGB, greyscale Contouring Scaler Data
Contouring Contours explicitly construct the boundary between regions with values Boundaries correspond to: lines in D surfaces in D (known as isosurfaces) of constant scalar value Contouring Scaler Data
Example : contours lines of constant pressure on a weather map (isobars) surfaces of constant density in medical scan (isosurface) iso roughly means equal / similar / same as Contouring Scaler Data 4
Overview Contouring - Problem statement - Tracking - Marching squares - Ambiguity problems - Marching cubes - Dividing squares Volume rendering Contouring Scaler Data 5
Contours Contours are boundaries between regions they DO NOT just connect points of equal value they DO also indicate a TRANSITION from a value below the contour to a value above the contour Contouring Scaler Data 6
D contours Data : D structured grid of scalar values 0 6 6 9 8 6 4 Difficult to visualise transitions in data use contour at specific scalar value to highlight transition What is the contour of 5? Contouring Scaler Data
Methods of Contour Line Generation Approach : Tracking find contour intersection with an edge track it through the cell boundaries if it enters a cell then it must exit via one of the boundaries track until it connects back onto itself or exits dataset boundary If it is known to be only one contour, stop otherwise Check every edge Approach : Marching Squares Algorithm Contouring Scaler Data 8
Marching Squares Algorithm Focus : intersection of contour and cell edges how the contour passes through the cell Assumption: a contour can pass through a cell in only a finite number of ways A vertex is inside contour if scalar value > contour outside contour if scalar value < contour 4 vertices, states (in or out) Contouring Scaler Data 9
Marching Squares No intersection. Ambiguous case. 4 = 6 possible cases for each square Contour intersects edge(s) small number so just treat each one separately Contouring Scaler Data 0
MS Algorithm Overview Main algorithm?. Select a cell. Calculate inside/outside state for each vertex. Look up topological state of cell in state table determine which edge must be intersected (i.e. which of the 6 cases) 4. Calculate contour location for each intersected edge 5. Move (or march) onto next cell until all cells are visited GOTO Contouring Scaler Data
MS Algorithm - notes Intersections for each cell must be merged to form a complete contour cells processed independently further merging computation required disadvantage over tracking (continuous tracked contour) Easy to implement (also to extend to D) Easy to parallelise Contouring Scaler Data
MS : Dealing with ambiguity? Split Ambiguous case. Join Choice independent of other choices either valid : both give continuous and closed contour Contouring Scaler Data
Example : Contour Line Generation 0 No intersection. Contour intersects edge Contour intersects edges 6 6 9 8 6 4 Ambiguous case. main steps for each cell here using simplified summary model of cases Contouring Scaler Data 4
Step : classify vertices 0 No intersection. Contour intersects edge Contour intersects edges 6 6 9 8 6 4 Contour value =5 Ambiguous case. Decide whether each vertex is inside or outside contour Contouring Scaler Data 5
Step : identify cases No intersection. Contour intersects edge Contour intersects edges 0 6 6 9 8 6 4 Ambiguous case. Contour value =5 Classify each cell as one of the cases Contouring Scaler Data 6
Step : interpolate contour intersections 0 No intersection. Contour intersects edge Contour intersects edges 6 6 9 8 6 4 Ambiguous case. Split Determine the edges that are intersected compute contour intersection with each of these edges Contouring Scaler Data
Ambiguous contour No intersection. Contour intersects edge Contour intersects edges 0 6 6 9 8 6 4 Ambiguous case. Join Finally : resolve any ambiguity here choosing join (example only) Contouring Scaler Data 8
MS : Dealing with ambiguity? One solution Calculate the value at the middle of the square by interpolation Check if it is under or above the threshold value Choose the pattern that matches Contouring Scaler Data 9
Ambiguous contour No intersection. Contour intersects edge Contour intersects edges 0 6 6 9 8 6 4? Ambiguous case. Finally : resolve any ambiguity here choosing join (example only) Contouring Scaler Data 0
D : Example contour A slice through the head A Quadric function. (with colour mapping added) Contouring Scaler Data
D surfaces : marching cubes Extension of Marching Squares to D data : D regular grid of scalar values result : D surface boundary instead of D line boundary D cube has 8 vertices 8 = 56 cases to consider use symmetry to reduce to 5 Problem : ambiguous cases cannot simply choose arbitrarily as choice is determined by neighbours poor choice may leave hole artefact in surface Contouring Scaler Data
Marching Cubes - cases Ambiguous cases,6,0,, split or join? Contouring Scaler Data
Example of bad choices The dark dots are the interior There are edges which are not shared by both cubes Need to make sure there is no contradiction with the neighbors Contouring Scaler Data 4
Cracks eliminated Contouring Scaler Data 5
Other two possible triangulations Need to decide how the faces are intersected by the contours Contouring Scaler Data 6
Adding more patterns Adding more patterns for,6,0,, [Neilson '9] Compute the values at the middle of the faces and the cubes Selecting the pattern that matches Contouring Scaler Data
Results : isosurfaces examples isosurface of Electron potential isosurface of flow density white outline shows bounds of D data grid surface = D contour (i.e. isosurface) through grid method : Marching Cubes Contouring Scaler Data 8
Rendering Metaballs The marching cubes algorithm is useful for rendering metaballs (implicit functions) D ( x, y, z)= b i exp(ai r i ) i r i= ( x xi ) +( y y i ) +( zz i ) ( x i, y i, z i ): the center of the particle i F ( x, y, z )=D ( x, y, z)t Rendering the surface where F(x,y,z) = 0 Contouring Scaler Data 9
Marching Cubes by CUDA http://www.youtube.com/watch?v=y5urxpx8q8u Contouring Scaler Data 0
Problems with Marching Cubes Generates lots of polygons -4 triangles per cell intersected many unnecessary e.g. co-planar triangles Increases the cost of rendering As with marching squares separate merging required Contouring Scaler Data
Dividing Cubes Algorithm Marching cubes often produces more polygons than pixels for given rendering scale Problem : causes high rendering overhead Solution : Dividing Cubes Algorithm draw points instead of polygons (faster rendering) Need : efficient method to find points on surface : method to shade points Contouring Scaler Data
Example : D divided squares for D lines Find pixels that intersect contour - Subdivide them Contouring Scaler Data
D divided squares for lines Find pixels that intersect line Subdivide them ( usually in x) Repeat recursively Contouring Scaler Data 4
D divided squares for lines Find pixels that intersect line Subdivide them Repeat recursively until screen resolution reached Fill in the pixel with the color of the line Contouring Scaler Data 5
Extension to D Find voxels which intersect surface Recursively subdivide the voxels that intersect the contour Until the voxel fits within a pixel Calculate mid-points of voxels Calculate the color of the pixel by shading Contouring Scaler Data 6
Drawing divided cubes surfaces surface normal for lighting calculations interpolate from voxel corner points problem with camera zoom ideally dynamically re-calculate points not always computationally possible Contouring Scaler Data
Dividing Cubes : Example 50,000 points when sampling less than screen resolution structure of surface can be seen Contouring Scaler Data 8
Viewing the volume data Originally we had the volume data Contouring: visualisation via surface shading volumetric data geometric primitives screen pixels Only watching the objects at the threshold value What if we want to watch other parts? Contouring Scaler Data 9
Volume Rendering Shaded iso-surface surface based rendering Volume Rendering voxel based rendering Data : D dense volume; structured D grid of voxels regular geometry and topology Contouring Scaler Data 40
Volume Rendering display the information inside the volume direct display : volumetric data screen pixels use transparency (seeing through volumes) Volview (now opensource) Contouring Scaler Data 4
Summary Contouring Theory D : Marching Squares Algorithm D : Marching Cubes Algorithm [Lorensen '8] marching tetrahedra, ambiguity resolution limited to regular structured grids D Rendering : Dividing Cubes Algorithm [Cline '88] - Volume Rendering Readings G.M. Nielson, B Hamann, The Asymptotic Decider: Resolving the Ambiguity in Marching Cubes W.E. Lorensen, H.E. Cline, Marching Cubes: A high resolution D surface construction algorithm H.E. Cline, W.E. Lorensen and S. Ludke, Two algorithms for the threedimensional reconstruction of tomograms Contouring Scaler Data 4