Contouring - åäº¬å¤§å¦å¯è§åä¸å¯è§åæç ç©¶ç»

可 视 化 与 可 视 计 算 概 论

Introduction to Visualization and Visual

Computing

袁 晓 如

北 京 大 学

2008 年 12 月 3 日

1

**Contouring**

and Isosurface Generation

2

**Contouring** in 2D

• Purpose: construct explicit boundary between regions

• Example: topological maps

• Algorithm

– Select contour value

– Calculate intersection of points on cell edges

– For edges straddling contour value

do linear interpolation to find intersection

r = (C - s0)/(s1 - s0)

– Connect intersections

• Edge tracking: track contours across cell boundaries until all crossings

used

3

Example of 2D **Contouring**

4

**Contouring** in 2D (con’t): Marching Squares

• Marching Squares: based on topological state

– Look up in case table based on combinations of vertex

state

– Merge duplicates (only for marching squares)

5

**Contouring** Ambiguity

• Single configuration can indicate two different

underlying distributions

• Two possible actions

6

**Contouring** in 3D

• Isosurface: surface of constant value

• Examples:

– Extent of tumor (or other tissues)

– Region of space exceeding safe toxin level

• Historical approaches:

– Find contours in 2D, then connect contours (e.g., lofting)

The isosurface with value 37 at at time 60 in in a jet shockwave data set

7

**Contouring** in 3D

• Treat volume as a set of 2D slices

– Apply 2D contouring algorithm on each slice.

– Or given as a set of hand-drawn contours

• Stitch the slices together.

8

**Contouring** in 3D

• Find iso-surfaces from 2D contours

– Segmentation: find closed contours in 2D slices and represent

them as polylines

– Labeling: identify different structures by means of the iso-value

of higher order characteristics

– Tracing/Stiching: connect contours representing the same object

from adjacent slices and form triangles

– Rendering: display triangles

9

**Contouring** in 3D

• Issues:

– Choose topological or geometrical reconstruction

– Problems:

• Sometimes there are many contours in each slice or there is a high

variation between slices

→ Tracing becomes very difficult

10

Contour Stitching

2

1

11

Contour Stitching

•Problem:

Given: 2 two-dimensional

closed curves

Curve #1 has m points

Curve #2 has n points

Which point(s) does vertex i

on curve one correspond to

on curve two

i

12

Surface Fitting Techniques

• General method:

– Choose an iso-value (arbitrarily or from segmentation)

– Detect all cells the surface is passing through by checking the vertices

• Mark vertices with respect to f(x,y,z)≥/< (+/-) c

• Consider all cells with different signs at vertices

– Place graphical primitives in each marked cell and render the surface

13

Isosurface Generation

• Five common techniques

– Cuberille

– Marching cubes

– Dividing cubes

– Marching tetrahedra

– Implicit surface techniques

14

Visualization Pipeline

•

Model

Database

Simulation

Data Collection

Generation

Enhancement

Selection

Segmentation

Analysis

Revisions

Updates

Image / Animation

Generation

Visualization

Rendering

15

Cuberille Method

• Opaque cubes approach (Cell Centered)

(A) Binarization of the volume with respect to the

iso-value

+ + + + + +

+ + + – – –

+ + – – – –

+ – – – – –

16

Cuberille Method

• Opaque cubes approach

(B) Find all boundary front-faces

if the normal of each face points outward the cell, find all faces where the

normal points towards the viewpoint (N•V>0) – back-face culling

(C) Render these faces as shaded polygons

17

Cuberille Method

• Cuberille approach yields blocky surfaces

• Improve results by adaptive subdivision

– Subdivide each marked cube into 8 smaller cubes

– Use tri-linear interpolation in order to reconstruct data values at new

cell corners

– Repeat cuberille approach for each new cube until pixel size

18

Adaptive Subdivision

exact

solution

19

Cuberille Method

• Spheres or cubes dispersed

throughout the volume

– color-coded

– optional shape-controlled

– glyphs

20

Marching Cubes (MC)

• Lorensen and Cline ’87

• Basic approach: 3D generalization of marching

squares

• Two main steps:

– Locate the surface corresponding to the user-specified value

• Using a divide and conquer strategy

– Generate surface normals

21

Marching Cubes – Statement

• Extracting an iso-surface from an implicit function, that is,

• Extracting a surface from volume data (discrete implicit

function),

• f (x ,y ,z ) = C

22

Marching Cubes

• Treat each cube individually

– No 2D contour curves

• Allow intersections only on the edges or at

vertices.

• Pre-calculate all of the necessary information to

construct a surface

• Use table lookup

– Like Marching Squares

23

The MC-Algorithm

• The core algorithm

– Cell consists of 8 voxel values:

(i+[01], j+[01], k+[01])

– 1. Consider a Cell

– 2. Classify each vertex as inside or outside

– 3. Build an index

– 4. Get edge list from table[index]

– 5. Interpolate the edge location

– 6. Go to next cell

24

MC 1: Create a Cube

• Consider a Cube defined by eight data values:

(i,j+1,k+1)

(i+1,j+1,k+1)

(i,j,k+1)

(i+1,j,k+1)

(i,j+1,k)

(i+1,j+1,k)

(i,j,k)

(i+1,j,k)

25

MC 2: Classify Each Voxel

• Classify each voxel according to whether it lies

outside the surface:

(value > iso-surface value)

inside the surface:

(value

MC 3: Build An Index

• Use the binary labeling of each voxel to create an index

v4

v8

v3

v7

inside =1

outside=0

11110100

v5

v6

00110000

v1

v2

Index:

v1 v2 v3 v4 v5 v6 v7 v8

27

MC 4: Lookup Edge List

• For a given index, access an array storing a list of edges

• all 256 cases can be derived from 15 base cases

28

MC 5: Interpolation Example

• Index = 10110001

• Number of triangles = 4

• triangle 1 = e4,e7,e11

• triangle 2 = e1, e7, e4

• triangle 3 = e1, e6, e7

• triangle 4 = e1, e10, e6

e4

e11

e7

e6

e1

e10

29

MC 6: Interp. Triangle Vertex

• For each triangle edge, find the vertex location along the edge using

linear interpolation of the voxel values

i i+1 x

=10

=0

T=5

x

=

i

+

⎛

⎜

⎝

v

T − v[]

i

[ ] [] ⎟ ⎞

i + 1 − v i ⎠

T=8

30

MC: Compute Normals

• Calculate the normal at each cube vertex

• G x = V x-1,y,z -V x+1,y,z

• G y = V x,y-1,z -V x,y+1,z

• G z = V x,y,z-1 -V x,y,z+1

• Use linear interpolation to compute the polygon vertex normal

31

MC: Ambiguous Cases

• Ambiguous cases:

3, 6, 7, 10, 12, 13

• Adjacent vertices: different

states

• Diagonal vertices: same

state

• Resolution:

decide for one case

or

or

32

Another View – Combined Cells

33

MC Hole Problem Example

34

MC Hole Solutions

• Tessellate cubes w/ tetrahedron and compute

marching tetrahedron

– No ambiguities

– LOTS of polygons

– Orientation of tetrahedron affects contour

location

• Asymptotic decider -- Nielson and

Hamann ’91

– Analyze bilinear variation over

face to choose patches

• Add complementary cases

– Use when necessary

35

Asymptotic Decider

• Assume bilinear interpolation within a face

• Hence iso-surface is a hyperbola

• Compute the point p where the asymptotes meet

• Sign of S(p) decides the connectivity

asymptotes

p

hyperbolas

36

Summary of Algorithm

– Read 4 slices of data

– Scan 2, creating cubes

– For each cube, determine triangle table index to find

triangulation of the cube surface intersection

– Find exact intersections using linear interpolation

– Create vertex normal vectors using gradient

– Output triangles and normals

37

Marching Cubes - Summary 1

• 256 Cases

• reduce to 15 cases by symmetry

• Complementary cases - (swap

in- and outside)

• Ambiguity resides in cases 3, 6,

7, 10, 12, 13

• Causes holes if arbitrary choices

are made.

38

Marching Cubes - Summary 2

• Up to 5 triangles per cube

• Dataset of 512 3 voxels can result in

several million triangles (many Mbytes!!!)

• Iso-surface does not represent an object!!!

• No depth information

• Semi-transparent representation --> sorting

• Optimization:

– Reuse intermediate results

– Prevent vertex replication

– Mesh simplification

39

MC Examples

3 Iso-surfaces

1 Iso-surface

40

2 Iso-surfaces

MC Examples

41

MC Extensions

• Higher order surfaces

– Use parametric cubics instead of polygons

– Particularly useful for large or irregular grids

– Use gradients to get curvature

• Adaptive subdivision

– Estimate error based on gradient

– Subdivide mesh adaptively

42

Dividing Cubes (Cline et. al 1988)

• Motivation: Marching Cubes

generates a large number of

very small polygons, which take

a long time to render

• Subdivide voxel into

a x b x c cubes that are the size of a

pixel if:

– The voxel intersects

the surface

• Render these as points

43

Dividing Cubes

– Choose a cube

– Classify, whether an iso-surface is passing through

it or not

– If (surface is passing through)

• Recursively subdivide cube until pixel size

– Compute normals at each corner

– Render shaded points with averaged normal

44

Advantages of Dividing Cubes

• No scan-conversion needed

– Simple projection of pixel-sized points

– Similarity to:

• “Points as Display Primitives” (Levoy & Whitted)

• splatting techniques (Westover, others)

• Surfels (Pfister & Gross)

• other point-based rendering techniques (OpenGL)

• No triangle resolution artifacts

45

Rendering Issues

• Dividing Cubes

– (+) Point shading hardware now supported by OpenGL

– (-) Adaptive Subdivision slow

• Marching Cubes

– (+) Great for PC polygon rendering hardware

• Market driven performance by games

– (-) Generates millions of polygons

• Utilize polygon simplification or view-dependent techniques

46

Marching tetrahedra

Primarily used for unstructured grids

• Split cells into tetrahedra

Process each Tet similar to the MC-algorithm

• Two different cases:

• A) one – and three + (or vice versa)

• The surface is defined by one triangle

• B) two – and two +

• Sectional surface given by a quadrilateral – split it into two triangles

using the shorter diagonal

47

Marching tetrahedra

• Properties

+ Fewer cases, i.e. 2 instead of 15

• no problems with consisteny between adjacent cells (but not

necessarily correct)

- Number of generated triangles might increase considerably

compared to the MC-algorithm due to splitting into tetrahedra

48

Implicit Surface Techniques

• Definition: use of functional implicit surface

formulation to model object geometry

• Example:

– Sphere - F(x,y,z)= x^2 + y^2 + z^2 -r^2=0

• To render implicits, isosurfaces are often created

49

Implicit Surface Polygonization

• Wyvill first presented a technique similar to marching

cubes with some advantages

• More recent techniques include

– Bloomenthal’s Polygonizer

http://www.implicit.eecs.wsu.edu

– Particle System Polygonizers - Hoppe, Pedersen, Heckbert

50

Normal Vector Calculation

• Use gradient vector g(x,y,z) to determine

surface normal

– Gradient is the derivative of the density function

• Calculation: (need 4 slices in memory)

– Find gradient at the cube vertices using central

differences

– Linearly interpolate gradient to intersection

51

Gradient Calculation Methods

• Central difference

• Higher-order

separable

function

• Regression

52

Example Result Using Gradient Magnitude

as Opacity

53

Surface fitting techniques

• Properties

– Huge amount of geometric primitives

– But, several improvements exist:

• Hierachical surface reconstruction

• View dependent surface reconstruction

• Mesh decimation

54

Optimization

• Hierachical surface reconstruction

– Generate copies of the data set at different resolutions

– Select level-of-detail based on error criterion

• Distance of coarse approximation to "original" surface

55

Optimization

• View dependent

– User defined level-of-detail (focus point oracle, like a lens)

– View frustum culling

• Avoid reconstructing in regions that are outside the viewing pyramid

– Occlusion culling

• Avoid reconstruction in regions that are already occluded by the surface (implies

front-to-back traversal)

– Avoid reconstruction in cells that are below the pixel size

56

Optimization

• Mesh decimation

– Remove triangles and retriangulate

with less triangles

– Consider deviation between

mesh before and after

decimation

– Generate hierarchical mesh

structure as a post-process and

switch to appropriate resolution

during display

57

Optimization

• Example:

Left: full reconstruction (6MΔ, 45 sec.)

Right: LOD-reconstruction (123KΔ, 1.1 sec.)

58

Optimization

• Example:

59

Optimization

• Example:

60

Research

• View-dependent methods

• Interval volumes

• 4D Iso-contouring (level set theory)

• Time-varying iso-contours

• Smooth surfaces

61

Conclusion

• **Contouring** is a common technique

• 3D isosurfaces are one of the most common

visualization techniques

• Useful to show boundary regions in data

62