cse 554 lecture 3: contouring iitaoju/cse554/lectures/...4 cse554 contouring ii slide 7 quadtrees...

21
1 CSE554 Contouring II Slide 1 CSE 554 Lecture 3: Contouring II CSE 554 Lecture 3: Contouring II Fall 2011 CSE554 Contouring II Slide 2 Review Review Iso-contours Points where a function evaluates to a same value (iso-value) Smooth thresholded boundaries Contouring methods Primal methods Marching Squares (2D) and Cubes (3D) Placing vertices on grid edges Dual methods Dual Contouring (2D,3D) Placing vertices in grid cells Primal Dual

Upload: others

Post on 14-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

1

CSE554 Contouring II Slide 1

CSE 554

Lecture 3: Contouring II

CSE 554

Lecture 3: Contouring II

Fall 2011

CSE554 Contouring II Slide 2

ReviewReview

• Iso-contours

– Points where a function evaluates to a same value (iso-value)

• Smooth thresholded boundaries

• Contouring methods

– Primal methods

• Marching Squares (2D) and Cubes (3D)

• Placing vertices on grid edges

– Dual methods

• Dual Contouring (2D,3D)

• Placing vertices in grid cellsPrimal Dual

Page 2: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

2

CSE554 Contouring II Slide 3

EfficiencyEfficiency

• Iso-contours is very often used for visualizing 3D volumes

– The volume data can be large (e.g, 1000^3)

• MRI, CT, Ultrasound, EM, etc.

– The user often needs to view surfaces at varying iso-values

• An efficient contouring algorithm is needed

– Optimized for viewing one volume at multiple iso-values

CSE554 Contouring II Slide 4

Marching Squares - RevisitedMarching Squares - Revisited

• Active square

– A grid square where {min, max} of 4 corner values encloses the iso-value

• Algorithm

– Visit each square.

– If active, create vertices and edges

• Time complexity: O(n+k)

• n: the number of all grid squares

• k: the number of active squares

1 2 3 2 1

2 3 4 3 2

3 4 5 4 3

2 3 4 3 2

1 2 3 2 1

Iso-value = 3.5

O(n)

O(k)

Page 3: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

3

CSE554 Contouring II Slide 5

0 50 100 150 200 250

0.2

0.4

0.6

0.8

1.0

1.2

0 50 100 150 200 250

0.2

0.4

0.6

0.8

1.0

1.2

Marching Squares - RevisitedMarching Squares - Revisited

Running time (seconds)

Iso-value

Only visiting each square and checking if it is active (without creating vertices and edges) O(n)

Marching Squares O(n+k)

CSE554 Contouring II Slide 6

Speeding Up ContouringSpeeding Up Contouring

• Data structures that allow faster query of active cells

– Quadtrees (2D), Octrees (3D)

• Hierarchical spatial structures for quickly pruning large areas of inactive cells

• Complexity: O(k*Log(n))

– Interval trees

• An optimal data structure for range finding

• Complexity: O(k+Log(n))

Page 4: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

4

CSE554 Contouring II Slide 7

Quadtrees (2D)Quadtrees (2D)

• Basic idea: coarse-to-fine search

– Start with the entire grid:

• If the {min, max} of all grid values does not enclose the iso-value, stop.

• Otherwise, divide the grid into four sub-grids and repeat the check within each sub-grid. If the sub-grid is a grid square, output contour there.

CSE554 Contouring II Slide 8

Quadtrees (2D)Quadtrees (2D)

• Basic idea: coarse-to-fine search

– Start with the entire grid:

• If the {min, max} of all grid values does not enclose the iso-value, stop.

• Otherwise, divide the grid into four sub-grids and repeat the check within each sub-grid. If the sub-grid is a grid square, output contour there.

Iso-value in {min,max}

Iso-value not in {min,max}

Page 5: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

5

CSE554 Contouring II Slide 9

Quadtrees (2D)Quadtrees (2D)

• Basic idea: coarse-to-fine search

– Start with the entire grid:

• If the {min, max} of all grid values does not enclose the iso-value, stop.

• Otherwise, divide the grid into four sub-grids and repeat the check within each sub-grid. If the sub-grid is a grid square, output contour there.

Iso-value in {min,max}

Iso-value not in {min,max}

CSE554 Contouring II Slide 10

Quadtrees (2D)Quadtrees (2D)

• Basic idea: coarse-to-fine search

– Start with the entire grid:

• If the {min, max} of all grid values does not enclose the iso-value, stop.

• Otherwise, divide the grid into four sub-grids and repeat the check within each sub-grid. If the sub-grid is a grid square, output contour there.

Iso-value in {min,max}

Iso-value not in {min,max}

Page 6: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

6

CSE554 Contouring II Slide 11

Quadtrees (2D)Quadtrees (2D)

• Basic idea: coarse-to-fine search

– Start with the entire grid:

• If the {min, max} of all grid values does not enclose the iso-value, stop.

• Otherwise, divide the grid into four sub-grids and repeat the check within each sub-grid. If the sub-grid is a grid square, output contour there.

Iso-value in {min,max}

Iso-value not in {min,max}

CSE554 Contouring II Slide 12

Quadtrees (2D)Quadtrees (2D)

• Basic idea: coarse-to-fine search

– Start with the entire grid:

• If the {min, max} of all grid values does not enclose the iso-value, stop.

• Otherwise, divide the grid into four sub-grids and repeat the check within each sub-grid. If the sub-grid is a single cell, output contour there.

Iso-value in {min,max}

Iso-value not in {min,max}

Page 7: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

7

CSE554 Contouring II Slide 13

Quadtrees (2D)Quadtrees (2D)

• A degree-4 tree

– Root node: entire grid

– Each node maintains:

• {min, max} in the enclosed part of the image

• (in a non-leaf node) 4 children nodes for the 4 quadrants

1 2 3

2 3 4

3 4 5

{1,5}

{1,3} {2,4} {2,4} {3,5}Grid

Level-1 nodes(leaves)

Root node

Quadtree

CSE554 Contouring II Slide 14

Quadtrees (2D)Quadtrees (2D)

• Tree building: bottom-up

– Each grid cell becomes a leaf node

– Assign a parent node to every group of 4 nodes

• Compute the {min, max} of the parent node from those of the children nodes

• Padding background leaf nodes (e.g., {-∞,-∞}) if the dimension of grid is not power of 2

{1,3} {2,4}

{3,5}{2,4}

1 2 3

2 3 4

3 4 5

{1,5}

Grid

Leaf nodes

Root node

Page 8: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

8

CSE554 Contouring II Slide 15

• Tree building: a recursive algorithm

Quadtrees (2D)Quadtrees (2D)

// A recursive function to build a single quadtree node

// for a sub-grid at corner (lowX, lowY) and with length len

buildNode (lowX, lowY, len)

1. If (lowX, lowY) is out of range: Return a leaf node with {-∞,-∞}

2. If len = 1: Return a leaf node with {min, max} of corner values

3. Else

1. c1 = buildNode (lowX, lowY, len/2)

2. c2 = buildNode (lowX + len/2, lowY, len/2)

3. c3 = buildNode (lowX, lowY + len/2, len/2)

4. c4 = buildNode (lowX + len/2, lowY + len/2, len/2)

5. Return a node with children {c1,…,c4} and {min, max} of all {min, max} of these children

// Building a quadtree for a grid whose longest dimension is len

Return buildNode (1, 1, 2^Ceiling[Log[2,len]])

CSE554 Contouring II Slide 16

Quadtrees (2D)Quadtrees (2D)

• Tree building: bottom-up

– Each grid cell becomes a leaf node

– Assign a parent node to every group of 4 nodes

• Compute the {min, max} of the parent node from those of the children nodes

• Padding background leaf nodes (e.g., {-∞,-∞}) if the dimension of grid is not power of 2

– Complexity: O(n)

• Total number of nodes in the tree is < 2n

• But we only need to do this once

{1,3} {2,4}

{3,5}{2,4}

1 2 3

2 3 4

3 4 5

{1,5}

Grid

Leaf nodes

Root node

Page 9: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

9

CSE554 Contouring II Slide 17

Quadtrees (2D)Quadtrees (2D)

• Contouring with a quadtree: top-down

– Starting from the root node

– If {min, max} of the node encloses the iso-value

• If the node is not a leaf, search within each of its children

• If the node is a leaf, contour in that grid cell

{1,5}

{1,3} {2,4}

{3,5}{2,4}

Leaf nodes

Root node

1 2 3

2 3 4

3 4 5

Grid

iso-value = 2.5

CSE554 Contouring II Slide 18

Quadtrees (2D)Quadtrees (2D)

// A recursive function to contour in a quadtree node

// for a sub-grid at corner (lowX, lowY) and with length len

contourNode (node, iso, lowX, lowY, len)

1. If iso is within {min, max} of node

1. If len = 1: do Marching Squares in this grid square

2. Else (let the 4 children be c1,…,c4)

1. contourNode (c1, iso, lowX, lowY, len/2)

2. contourNode (c2, iso, lowX + len/2, lowY, len/2)

3. contourNode (c3, iso, lowX, lowY + len/2, len/2)

4. contourNode (c4, iso, lowX + len/2, lowY + len/2, len/2)

// Contouring using a quadtree whose root node is Root

// for a grid whose longest dimension is len

contourNode (Root, iso, 1, 1, 2^Ceiling[Log[2,len]])

• Contouring with a quadtree: a recursive algorithm

Page 10: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

10

CSE554 Contouring II Slide 19

Quadtrees (2D)Quadtrees (2D)

• Contouring with a quadtree: top-down

– Starting from the root node

– If {min, max} of the node encloses the iso-value

• If the node is an intermediate node, search within each of its children nodes

• If the node is a leaf, output contour in that grid square

– Complexity: (at most) O(k*Log(n))

• The depth of the tree is Log(n)

• Much faster than O(k+n) (Marching Squares) if k<<n

{1,5}

{1,3} {2,4}

{3,5}{2,4}

Leaf nodes

Root node

1 2 3

2 3 4

3 4 5

Grid

iso-value = 2.5

CSE554 Contouring II Slide 20

0 50 100 150 200 250

0.2

0.4

0.6

0.8

1.0

1.2

Quadtrees (2D)Quadtrees (2D)

Running time (seconds)

Iso-value

Marching Squares O(n+k)

QuadtreeO(k*Log(n))

Page 11: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

11

CSE554 Contouring II Slide 21

Quadtrees (2D): SummaryQuadtrees (2D): Summary

• Algorithm

– Preprocessing: building the quad tree

• Independent of iso-values

– Contouring: traversing the quad tree

– Both are recursive algorithms

• Time complexity

– Tree building: O(n)

• Slow, but one-time only

– Contouring: O(k*Log(n))

CSE554 Contouring II Slide 22

Octrees (3D)Octrees (3D)

• Algorithm: similar to quadtrees

– Preprocessing: building the octree

• Each non-leaf node has 8 children nodes, one for each octant of grid

– Contouring: traversing the octree

– Both are recursive algorithms

• Time complexity: same as quadtrees

– Tree building: O(n)

• Slow, but one-time only

– Contouring: O(k*Log(n))

Page 12: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

12

CSE554 Contouring II Slide 23

Speeding Up ContouringSpeeding Up Contouring

• Data structures that allow faster query of active cells

– Quadtrees (2D), Octrees (3D)

• Hierarchical spatial structures for quickly pruning large areas of inactive cells

• Complexity: O(k*Log(n))

– Interval trees

• An optimal data structure for range finding

• Complexity: O(k+Log(n))

CSE554 Contouring II Slide 24

Interval TreesInterval Trees

• Basic idea

– Each grid cell occupies an interval of values {min, max}

• An active cell’s interval intersects the iso-value

– Stores all intervals in a search tree for efficient intersection queries

0 255

Iso-value

Page 13: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

13

CSE554 Contouring II Slide 25

Interval TreesInterval Trees

• A binary tree

– Root node: all intervals in the grid

– Each node maintains:

• δ: Median of end values of all intervals

• (in a non-leaf node) Two children nodes

– Left child: intervals strictly lower than δ

– Right child: intervals strictly higher than δ

• Two sorted lists of intervals intersecting δ

– Left list (AL): ascending order of min-end of each interval

– Right list (DR): descending order of max-end of each interval

CSE554 Contouring II Slide 26

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

δ=4 δ=10

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

AL: j,k,lDR: l,j,k

AL: mDR: m

AL: a,b,cDR: c,a,b

δ=12

Page 14: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

14

CSE554 Contouring II Slide 27

Interval TreesInterval Trees

• Tree building: top-down

– Starting with the root node (which includes all intervals)

– To create a node from a set of intervals,

• Find δ (the median of all ends of the intervals).

• Sort all intervals intersecting with δ into the AL, DR

• Construct the left (right) child from intervals strictly below (above) δ

– A recursive algorithm

CSE554 Contouring II Slide 28

Interval TreesInterval Trees

Intervals:

Interval tree:

Page 15: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

15

CSE554 Contouring II Slide 29

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

CSE554 Contouring II Slide 30

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

δ=4

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

AL: a,b,cDR: c,a,b

Page 16: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

16

CSE554 Contouring II Slide 31

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

δ=4 δ=10

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

AL: j,k,lDR: l,j,k

AL: a,b,cDR: c,a,b

CSE554 Contouring II Slide 32

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

δ=4 δ=10

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

AL: j,k,lDR: l,j,k

AL: mDR: m

AL: a,b,cDR: c,a,b

δ=12

Page 17: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

17

CSE554 Contouring II Slide 33

Interval TreesInterval Trees

• Tree building: top-down

– Starting with the root node (which includes all intervals)

– To create a node from a set of intervals,

• Find δ (the median of all ends of the intervals).

• Sort all intervals intersecting with δ into the AL, DR

• Construct the left (right) child from intervals strictly below (above) δ

– A recursive algorithm

– Complexity: O(n*Log(n))

• A linear sweep at each level of the tree

• Depth of the tree is Log(n)

• Again, this is one-time only

CSE554 Contouring II Slide 34

Interval TreesInterval Trees

• Intersection queries: top-down

– Starting with the root node

• If the iso-value is smaller than δ

– Scan through AL: output all intervals whose min-end is smaller than iso-value.

– Go to the left child node.

• If the iso-value is larger than δ

– Scan through DR: output all intervals whose max-end is larger than iso-value.

– Go to the right node.

• If iso-value equals δ

– Output AL (or DR).

Page 18: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

18

CSE554 Contouring II Slide 35

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

δ=4 δ=10

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

AL: j,k,lDR: l,j,k

AL: mDR: m

AL: a,b,cDR: c,a,b

δ=12

iso-value = 9

CSE554 Contouring II Slide 36

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

δ=4 δ=10

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

AL: j,k,lDR: l,j,k

AL: mDR: m

AL: a,b,cDR: c,a,b

δ=12

iso-value = 9

Page 19: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

19

CSE554 Contouring II Slide 37

Interval TreesInterval Trees

Intervals:

Interval tree:

δ=7

δ=4 δ=10

AL: d,e,f,g,h,iDR: i,e,g,h,d,f

AL: j,k,lDR: l,j,k

AL: mDR: m

AL: a,b,cDR: c,a,b

δ=12

iso-value = 9

CSE554 Contouring II Slide 38

Interval TreesInterval Trees

• Intersection queries: top-down

– Starting with the root node

• If the iso-value is smaller than δ

– Scan through AL: output all intervals whose min-end is smaller than iso-value.

– Go to the left child.

• If the iso-value is larger than δ

– Scan through DR: output all intervals whose max-end is larger than iso-value.

– Go to the right child.

• If iso-value equals δ

– Output AL (or DR).

– Complexity: O(k + Log(n))

• k: number of intersecting intervals (active cells)

• Much faster than O(k+n) (Marching squares/cubes)

Page 20: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

20

CSE554 Contouring II Slide 39

0 50 100 150 200 250

0.2

0.4

0.6

0.8

1.0

1.2

Interval TreesInterval Trees

Running time (seconds)

Iso-value

Marching Squares O(n+k)

QuadtreeO(k*Log(n))

Interval treeO(k+Log(n))

CSE554 Contouring II Slide 40

Interval Trees: SummaryInterval Trees: Summary

• Algorithm

– Preprocessing: building the interval tree

• Independent of iso-values

– Contouring: traversing the interval tree

– Both are recursive algorithms

• Tree-building and traversing are same in 2D and 3D

• Time complexity

– Tree building: O(n*log(n))

• Slow, but one-time

– Contouring: O(k+log(n))

Page 21: CSE 554 Lecture 3: Contouring IItaoju/cse554/lectures/...4 CSE554 Contouring II Slide 7 Quadtrees (2D) • Basic idea:coarse-to-fine search – Start with the entire grid: • If the

21

CSE554 Contouring II Slide 41

Further ReadingsFurther Readings

• Quadtree/Octrees:

– “Octrees for Faster Isosurface Generation”, Wilhelms and van Gelder (1992)

• Interval trees:

– “Dynamic Data Structures for Orthogonal Intersection Queries”, by Edelsbrunner (1980)

– “Speeding Up Isosurface Extraction Using Interval Trees”, by Cignoni et al. (1997)

CSE554 Contouring II Slide 42

Further ReadingsFurther Readings

• Other acceleration techniques:

– “Fast Iso-contouring for Improved Interactivity”, by Bajaj et al. (1996)

• Growing connected component of active cells from pre-computed seed locations

– “View Dependent Isosurface Extraction”, by Livnat and Hansen (1998)

• Culling invisible mesh parts

– “Interactive View-Dependent Rendering Of Large Isosurfaces”, by Gregorski et al. (2002)

• Level-of-detail: decreasing mesh resolution based on distance from the viewer Gregorski et al.

Livnat and Hansen