Contouring - The Problem More Formallycrawfis.3/cis694L/Slides/... · 2003. 4. 17. · (2)...
Transcript of Contouring - The Problem More Formallycrawfis.3/cis694L/Slides/... · 2003. 4. 17. · (2)...
1
Iso-Contouring and Level-Sets
Roger Crawfis
Contributors: Roger Crawfis, Han-Wei Shen, Raghu Machiraju, Torsten Moeller, Fan Ding, Charles Dyer, and Huang Zhiyong
4/17/2003 R. Crawfis, Ohio State Univ. 2
Iso-contour/surface Extractions
2D Iso-contour 3D Iso-surface
4/17/2003 R. Crawfis, Ohio State Univ. 3
Contouring - The Problem
Extracting an iso- surface from an implicit function, that is, Extracting a surface from volume data (discrete implicit function), f (x ,y ,z ) = T
4/17/2003 R. Crawfis, Ohio State Univ. 4
More Formally
A scalar visualization technique that creates curves (in 2D) or surfaces (in 3D) representing a constant scalar value across a scalar field.Contour lines are called isovalue lines or isolines.Contour surfaces are called isovaluesurfaces or isosurfaces
4/17/2003 R. Crawfis, Ohio State Univ. 5
Contouring a 2D structured grid with contour line value = 5
0 1 1 3 2
1 3 6 6 3
3 7 9 7 3
2 7 8 6 2
1 2 3 4 3
1. Using interpolation to generatepoints along edges with the constantvalue
2. Connect these points into contoursusing a few different approaches. Oneof the approaches:
. Detects edge intersection
. Tracks this contour as it moves acrosscell boundary
. Repeat for all contours4/17/2003 R. Crawfis, Ohio State Univ. 6
2D Contouring – Not so easy
AnnotationsSmooth Curves
Topographic Map of Jerusalem (Contour interval 10 meters)
North is at the top of the map. The Mount of Olives is on the far right, Mount Zion on the left. Mount Moriah rises as a long ridge at the south end of the City of David and continues on past the present Temple Mount, and reaches its highest point outside the Northern walls of the Old City, at the top of the map.
http://www.skullandcrossbones.org/articles/solomontemple/solomontemple2.htm
2
4/17/2003 R. Crawfis, Ohio State Univ. 7
Quantitative and Qualitative
In this figure, we can actually read off any value to about three significant digits.Hard and tedious problem to determine where to place labels. Usually done as vector graphics, rather than raster graphics for precision.
http://omnimap.com/catalog/cats/fish/fish-contour.htm
4/17/2003 R. Crawfis, Ohio State Univ. 8
Divide and Conquer
Partition space into rectangular sub-regions.
4/17/2003 R. Crawfis, Ohio State Univ. 9
Dividing Cubes/Squares
Generates Points and renders themRendering points is faster than polygonsPrinciple - Divide a square until contour passes thru the cell
1 2 3 4 3
2 7 8 6 2
3 7 9 7 3
1 3 6 6 3
0 1 1 3 2
Iso-value=54/17/2003 R. Crawfis, Ohio State Univ. 10
Dividing Cubes
1. Create a cell2. Determine if the cell is a surface cell3. Subdivide surface cells to image resolution4. Determine intensity or color of refined cell5. Output a point for each remaining surface cell
4/17/2003 R. Crawfis, Ohio State Univ. 11
Step 3: Subdivide
Subdivide each cell such that the resolution is higher than the image resolution. For example, when a 1282
volume is rendered to a 5122 image, cells containing the contour will be divided to 4x4x4 smaller cubes.
classify subdivide output points
4/17/2003 R. Crawfis, Ohio State Univ. 12
Surface TrackingGiven function S(t,x,y,z) that returns 1 if (x,y,z) is on the surface t and 0 otherwiseNeeded: a seed voxel p that is on the surface.
1 2 3 4 3
2 7 8 6 2
3 7 9 7 3
1 3 6 6 3
0 1 1 3 2
Iso-value=5Seed cell
3
4/17/2003 R. Crawfis, Ohio State Univ. 13
Surface TrackingLet Q be a queue of voxels.
Push p onto QFlag p as “visited”While Q is not empty do
Pop q from Q and output it.For each voxel v in the neighborhood of q doIf S(t, v) = 1 then
If v was not visited thenPush v onto QFlag it as “visited”
end {while}
4/17/2003 R. Crawfis, Ohio State Univ. 14
Tracking and Smooth Curves
Recall that the gradient to a scalar field is normal to the isolines.Therefore, the curve will be towards the direction perpendicular to the gradient.Can also use the gradient to calculate tangents for each point on the curve to generate smooth curves.
4/17/2003 R. Crawfis, Ohio State Univ. 15
Restricted Topological Cases
Filled circle vertices indicate scalar value is above the contour valueUnfilled ones which scalar values are below the contour values
•A closed curve can not be contained in the cell.•The curve can only enter and exit the cell once per edge.
4/17/2003 R. Crawfis, Ohio State Univ. 16
Not Allowed
4/17/2003 R. Crawfis, Ohio State Univ. 17
Linear Topology
The restricted set is topologically equivalent to linear segments.Topologically equivalent if we restrict the edge intersections to lie at the mid-points of each edge.
4/17/2003 R. Crawfis, Ohio State Univ. 18
Using Symmetry to Reduce to 5
Contour ambiguity: either solidor dash lines look OK
4
4/17/2003 R. Crawfis, Ohio State Univ. 19
2D Iso-contour (0)
Remember bi-linear interpolation
p2 p3
p0 p1
P =?p4 p5
To know the value of P, we can first compute p4 andP5 and then linearly interpolateP
4/17/2003 R. Crawfis, Ohio State Univ. 20
2D Iso-contour (1)
Consider a simple case: one cell data set
The problem of extracting an iso-contour is an inverse of value interpolation. That is:
p2 p3
p0 p1
Given f(p0)=v0, f(p1)=v1, f(p2)=v2, f(p3)=v3
Find the point(s) P within the cell that have values
F(p) = C
4/17/2003 R. Crawfis, Ohio State Univ. 21
2D Iso-contour (2)
p2 p3
p0 p1
We can solve the problem based on linear interpolation
(1) Identify edges that contain points P that have value f(P) = C
(2) Calculate the positions of P
(3) Connect the points with lines
4/17/2003 R. Crawfis, Ohio State Univ. 22
2D Iso-contouring – Step 1
(1) Identify edges that contain points P that have value f(P) = C
v1 v2
If v1 < C < v2 then the edge contains such a point
4/17/2003 R. Crawfis, Ohio State Univ. 23
2D Iso-contouring – Step 2
(2) Calculate the position of P
Use linear interpolation:
P = P1 + (C-v1)/(v2-v1) * (P2 – P1)v1 v2
Pp1 p2
C
4/17/2003 R. Crawfis, Ohio State Univ. 24
2D Iso-contouring – Step 3
p2 p3
p0 p1
Connect the points with line(s)
Based on the principle of linear variation, all the points on the line have values equal C
5
4/17/2003 R. Crawfis, Ohio State Univ. 25
Inside or Outside?
Just a naming convention
1. If a value is smaller than the iso-value, we call it “Outside”2. If a value is greater than the iso-value, we call it “Inside”
p2 p3
p0 p1- +inside cell
p2 p3
p0 p1-
outside cell4/17/2003 R. Crawfis, Ohio State Univ. 26
Contouring in 3D
Treat volume as a set of 2D slicesApply 2D Contouring algorithm on each slice.Or given as a set of hand-drawn contours
Stitch the slices together.
4/17/2003 R. Crawfis, Ohio State Univ. 27
Contour Stitching••Problem:Problem:
Given: 2 twoGiven: 2 two--dimensional dimensional closedclosed curvescurvesCurve #1 has Curve #1 has mm pointspointsCurve #2 has Curve #2 has nn pointspoints
Which point(s) does vertex Which point(s) does vertex ii on curve one correspond to on curve one correspond to on curve two?on curve two? ?
?
i
4/17/2003 R. Crawfis, Ohio State Univ. 28
A Solution
Fuchs, et. al.Optimization problem1 stitch consists of:⌧2 spans between curves⌧1 contour segment
Triangles of {Pi,Qj,Pi+1} or {Qj+1,Pi,Qj}⌧Consistent normal directions
Pi Pi+1
Qj
4/17/2003 R. Crawfis, Ohio State Univ. 29
Fuchs, et. al.
Left spanPiQj => go up
Right span (either)Pi+1Qj => go downPiQj+1 => go down
4/17/2003 R. Crawfis, Ohio State Univ. 30
Fuchs, et. al.
ConstraintsEach contour segment is used once and only once.If a span appears as a left span, then it must also appear as a right span.If a span appears as a right span, then it must also appear as a left span.
6
4/17/2003 R. Crawfis, Ohio State Univ. 31
Fuchs, et. al.
This produces an acceptable surface (from a topological point of view)
No holes
We would like an optimal one in some sense.
4/17/2003 R. Crawfis, Ohio State Univ. 32
Fuchs et. al.
Graph problemVertices Vij = span between Pi and QjEdges are constructed from a left span to a right span.
Only two valid right spans for a left span.
PPii
QQjj QQj+1j+1
PPi+1i+1
4/17/2003 R. Crawfis, Ohio State Univ. 33
Fuchs, et. al.
Organize these edges as a grid or matrix.
PP
i
j
PiQjPi+1
QjPiQj+1
4/17/2003 R. Crawfis, Ohio State Univ. 34
Fuchs, et. al.
Acceptable graphsExactly one vertical arc between Pi and Pi+1
Exactly one horiz. arc between Qj and Qj+1
Either⌧indegree(Vij) = outdegree(Vij) = 0⌧both > 0
• (if a right, also has to be a left)
4/17/2003 R. Crawfis, Ohio State Univ. 35
Fuchs, et. al.
Claim:An acceptable graph, S, is weakly connected.
Lemma 2Only 0 or 1 vertex of S has an indegree = 2.⌧E.g., Two cones touching in the center.
All other vertices have indegree=1(recall indegree = outdegree)
4/17/2003 R. Crawfis, Ohio State Univ. 36
Fuchs, et. al.
Thereom 1: S is an acceptable surface if and only if:
S has one and only one horizontal arc between adjacent columns.S has one and only one vertical arc between adjacent rows.S is Eulerian (closed walk with every arc only once).
7
4/17/2003 R. Crawfis, Ohio State Univ. 37
Fuchs, et. al.
Number of arcs is thus m+n.Many possible solutions still!!!Associate costs with each edge
Area of resulting triangleAspect ratio of resulting triangle
4/17/2003 R. Crawfis, Ohio State Univ. 38
Fuchs, et. al.
Note that Vi0 is in S for some i.Note that V0j is in S for some j. With the weights (costs), we can compute the minimum path from a starting node Vi0.
Since we do not know which Vi0, we compute the paths for all of them and take the minimum.⌧Some cost saving are achievable.
4/17/2003 R. Crawfis, Ohio State Univ. 39
Marching Cubes
Predominant method used today.Efficient and simpleIt was independently reported by Wyvilland McPeeters in 1986, Lorenson and Cline in 1987
4/17/2003 R. Crawfis, Ohio State Univ. 40
Marching Cubes
Treat each cube individualNo 2D contour curves
Allow intersections only on the edges or at vertices.Pre-calculate all of the necessary information to construct a surface.
4/17/2003 R. Crawfis, Ohio State Univ. 41
Marching Cubes
Consider a single cubeAll vertices above the contour thresholdAll vertices belowMixed above and below
+ +
+
+ +
+
-+
4/17/2003 R. Crawfis, Ohio State Univ. 42
Marching Cubes
Binary label each node => (above/below) Examine all possible cases of above or below for each vertex.8 vertices implies 256 possible cases.
+ +
+
+ +
+
-+
8
4/17/2003 R. Crawfis, Ohio State Univ. 43
How many cases?
Now we have 8 vertices
So it is: 2 = 2568
How many unique topological cases?
4/17/2003 R. Crawfis, Ohio State Univ. 44
Case Reduction
Value Symmetry
+
+
_ _
_
__
_+
+
_
_
+
+
+
+
4/17/2003 R. Crawfis, Ohio State Univ. 45
Case Reduction
Rotation Symmetry
+
+
_ _
_
__
__
_
+
+
_ _
__
4/17/2003 R. Crawfis, Ohio State Univ. 46
Case Reduction
Mirror Symmetry
+
+
_ +
_
+_
__
+
+
+
+ _
__
By inspection, we can reduce 256 14
4/17/2003 R. Crawfis, Ohio State Univ. 47
Marching Cube - Summary
Create a cubeClassify each voxelBuild an indexLookup edge listInterpolate triangle verticesCalculate and interpolate normals
4/17/2003 R. Crawfis, Ohio State Univ. 48
Step 1: Create a Cube
Consider a cube defined by eight data values: four from slice K, and four from slice K+ 1
9
4/17/2003 R. Crawfis, Ohio State Univ. 49
Step 2: Classify Each Voxel
Binary classification of each vertex of the cube as to whether it lies
outside the surface (voxel value < isosurface value)or inside the surface (voxel value <= isosurfacevalue).
4/17/2003 R. Crawfis, Ohio State Univ. 50
Step 3: Build an Index
Use the binary labeling of each voxel to create an 8-bit index:
8 vertices - 256 casesRequires a canonical ordering of the cube.
4/17/2003 R. Crawfis, Ohio State Univ. 51
Step 4: Look-up the Topology
Given the index for each cell, a table lookup is performed to identify the edges that has intersections with the iso-surface.Also requires a canonical ordering of the edges: e1, e2, …, e12
0123
14
e1, e3, e5…
Index intersection edges
e1
e2
e3
e4e5
e6
e7e8
e9 e10
e11 e12
4/17/2003 R. Crawfis, Ohio State Univ. 52
Step 4: Look-up the Topology
all 256 cases could be derived from 15 base cases.Difficult to determine rotational symmetry and map it correctly to the table.
4/17/2003 R. Crawfis, Ohio State Univ. 53
Step 4: Example
Index = 10001101triangle 1 = e4,e7,e12triangle 2 = e1, e7, e4triangle 3 = e1, e6, e7triangle 4 = e1, e10, e6
e1e10
e6
e7e12
e4
v1 v2
v7
e2
4/17/2003 R. Crawfis, Ohio State Univ. 54
Step 5: Interpolate Triangle Vertices
For each edge, find the vertex location along the edge using linear interpolation of the voxel values.
10
4/17/2003 R. Crawfis, Ohio State Univ. 55
Step 6: Compute Normals
Calculate the normal at each cube vertexUse linear interpolation to interpolate the polygon vertex normal
4/17/2003 R. Crawfis, Ohio State Univ. 56
Why is it called marching cubes?
Linear search through cells
•Row by row, layer by layer•Reuse the interpolated pointsfor adjacent cells
No neighborhood informationNo neighborhood informationis required!!!is required!!!
4/17/2003 R. Crawfis, Ohio State Univ. 57
Problems
Ambiguities: Are the curves below right or wrong?
4/17/2003 R. Crawfis, Ohio State Univ. 58
Problems
Inconsistencies: Does the result produce the correct topology?An iso-contour surface should always be a manifold.
We know whether these cases are right or wrong.
wrong
4/17/2003 R. Crawfis, Ohio State Univ. 59
2D Contouring Ambiguity
Break contour Join contour
or
Either choices areacceptable becausecontour lines are continuousand closed
Independent of otherchoices
4/17/2003 R. Crawfis, Ohio State Univ. 60
Marching Cubes
Topological inconsistencies in the 15 cases
Turns out positive and negative are not symmetric.
+ +
+
+ +
+- -
+ -
-
+ +
---
11
4/17/2003 R. Crawfis, Ohio State Univ. 61
A Bad Example
Resolution:Favor positive pathways thru the voxel(or negative, but be consistent).
Case 3 Case 3
Case 3Case 6
(compliment symmetry) 4/17/2003 R. Crawfis, Ohio State Univ. 62
Ambiguous CasesAmbiguous cases:3, 4, 6, 7, 10, 12, 13Adjacent vertices: different statesDiagonal vertices: same stateCase 4 is not usually considered ambiguous, but we could favor a tunnel through the long diagonal.
or
or
4/17/2003 R. Crawfis, Ohio State Univ. 63
Ambiguous Cases
The ambiguous cases lead to a continuous manifold, but due to improper sampling of the volume, a (somewhat arbitrary) decision can be made on whether to close two curves or connect them.
Asymptotic Decider - by Nielson and Hamann(IEEE Vis’91) examines neighboring cells to determine this choice.
4/17/2003 R. Crawfis, Ohio State Univ. 64
Asymptotic Decider
Based on bilinear interpolation over faces
B01
B00 B10
B11
(s,t)B(s,t) = (1-s, s) B00 B01
B10 B111-tt
The contour curves of B:
{(s,t) | B(s,t) = α } are hyperbolas
4/17/2003 R. Crawfis, Ohio State Univ. 65
Asymptotic Decider (2)
(0,0)
(1,1)
Where the hyperbolasgo through the cell depends on the valuesat the corners, I.e., B00, B01, B10, B11
4/17/2003 R. Crawfis, Ohio State Univ. 66
Asymptotic Decider (3)
(0,0)
(1,1)
Asymptote
(Sα, Tα)
If α < B(Sα, Tα)
12
4/17/2003 R. Crawfis, Ohio State Univ. 67
Asymptotic Decider (4)
(1,1)
Asymptote
(Sα, Tα)
(0,0)
If α > B(Sα, Tα)
4/17/2003 R. Crawfis, Ohio State Univ. 68
Asymptotic Decider (5)
(1,1) (Sα, Tα)
(0,0)
Sα = B00 - B01 B00 + B11 – B01 – B10
Tα= B00 – B10 B00 + B11 – B01 – B10
B(Sα,Tα) = B00 B11 + B10 B01 B00 + B11 – B01 – B10
4/17/2003 R. Crawfis, Ohio State Univ. 69
Asymptotic Decider (6)
Based on the result of asymptotic decider, we expand the marching cube case 3, 6, 12, 10, 7, 13(These are the cases with at least one ambiguiousfaces).
4/17/2003 R. Crawfis, Ohio State Univ. 70
Marching Cubes Demo
Animating the contour valueSpecial functions for contouringVarying speeds and numbers of triangles
4/17/2003 R. Crawfis, Ohio State Univ. 71
Marching Cubes
Data Structures/Tablesstatic int const HexaEdges[12][2] = { {0,1}, {1,2}, {2,3}, {3,0},
{4,5}, {5,6}, {6,7}, {7,4},{0,4}, {1,5}, {3,7}, {2,6}};
typedef struct {EDGE_LIST HexaEdges[16];
} HEXA_TRIANGLE_CASES;
/* Edges to intersect. Three at a time form a triangle. */
static const HEXA_TRIANGLE_CASES HexaTriCases[] = {{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* 0 */{ 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* 1 */{ 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* 2 */{ 1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* 3 */
...
4/17/2003 R. Crawfis, Ohio State Univ. 72
Marching Cubes - How simple
/* Determine the marching cubes index */for ( i=0, index = 0; i < 8; i++)
if (val1[nodes[i]] >= thresh) /* If the nodal value is above the */index |= CASE_MASK[i]; /* threshold, set the appropriate bit. */
triCase = HexaTriCases[index]; /* triCase indexes into the MC table. */edge = triCase->HexaEdges; /* edge points to the list of intersected edges */
for ( ; edge[0] > -1; edge += 3 ) /* stop if we hit the -1 flag */{for (i=0; i<3; i++) /* Calculate and store the three edge intersections */{
vert = HexaEdges[edge[i]];n0 = nodes[vert[0]];n1 = nodes[vert[1]];t = (thresh - val1[n0]) / (val1[n1] - val1[n0]);tri_ptr[i] = add_intersection( n0, n1, t ); /* Save an index to the pt. */
}add_triangle( tri_ptr[0], tri_ptr[1], tri_ptr[2], zoneID); /* Store the triangle */
}}