UMass Lowell Computer Science 91.504 Advanced Algorithms
Computational Geometry Prof. Karen Daniels
Spring, 2001
Lecture 7Lecture 7Geometric ModelingGeometric Modeling
Approximate Nearest Neighbor SearchingApproximate Nearest Neighbor SearchingMonday, 4/23/01Monday, 4/23/01
Part 2
Advanced TopicsAdvanced TopicsApplicationsApplicationsManufacturingManufacturingModeling/GraphicsModeling/GraphicsWireless NetworksWireless NetworksVisualizationVisualizationTechniquesTechniques(de)Randomization(de)RandomizationApproximationApproximationRobustnessRobustnessRepresentationsRepresentationsEpsilon-netEpsilon-netDecomposition treeDecomposition tree
Literature for Part II
Aspect Milenkovic/Daniels Wu/Li Arya et al. Goodrich/Ramos ShewchuckTitle Translational
PolygonContainmentand MinimalEnclosureusingMathematicalProgramming
Oncalculatingconnecteddominatingset forefficientrouting in adhoc wirelessnetworks
An optimal algorithmfor approximate nearestneighbor searching infixed dimensions
Bounded-IndependenceDerandomizationof GeometricPartitioning withApplications toParallel Fixed-DimensionalLinearProgramming
Triangle: Engineering a 2DQuality Mesh Generator andDelaunay Triangulator
Source Journal: ITOR Conf:Workshop onDiscrete Algand Methodsfor MOBILEComputing&Communications
Journal: ACM Journal: Discrete& Comp Geom
Conf: 1st Workshop on AppliedCG
ApplicationAreas
manufacturing dynamicwirelesscommunications
knowledge discovery;data mining; patternrecognition;classification; machinelearning; datacompression;multimedia databases;document retrieval;statistics
linearprogramming
geometric modeling; graphics
InputObjects
2D nonconvexpolygons
2D pointsrepresentinghosts
d-dimensional points range space PSLG of object
Literature for Part IIAspect Milenkovic/Daniels Wu/Li Arya et al. Goodrich/Ramos ShewchuckDimensionality
2D 2D arbitrary arbitrary 2D
Problem/Task
translationalcontainment;overlapelimination;distance-basedsubdivision;minimalenclosure;visibility
dominatingset
partitioning; nearest-neighbor query
geometricrandomization;geometricderandomization
(constrained) Delaunaytriangulation; robustness
Theory?Implementation?
both someexperiments
both theory implementation
ADTs &DataStructures
convex hull;visibilitypolygon
undirectedgraph
balanced box-decomposition tree
epsilon-net;epsilon-approximation
triangular mesh; (constrained)Delaunay triangulation;Voronoi diagram; convex hulls;Guibas/Stolfi quad-edge;triangular data structure; PSLG;splay tree; heap
AlgorithmicParadigms&Techniques
subdivision;approximatealgorithm;binary search
distributed;heuristic
geometricpreprocessing;approximationalgorithm
randomization;derandomization;parallel
sweep-line; geometric divide-and-conquer; incrementalinsertion
Math Topics Minkowskisum; linearprogramming;monotonicity;convexdistancefunction
graph theory:dominatingset
Minkowski metric;probability
VC-dimension;linearprogramming;probability
duality
Geometric Modeling
““Triangle: Engineering a 2D Quality Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Mesh Generator and Delaunay
Triangulator”Triangulator”Jonathan Richard ShewchuckJonathan Richard Shewchuck
http://www.cs.cmu.edu/~jrs/jrspapers.htmlhttp://www.cs.cmu.edu/~jrs/jrspapers.html
Goals
Construct 2D mesh of triangles Construct 2D mesh of triangles for geometric modeling that:for geometric modeling that: avoids small anglesavoids small angles
constrained Delaunay triangulationconstrained Delaunay triangulation is efficient in time and spaceis efficient in time and space
careful choice of data structures & careful choice of data structures & algorithmalgorithm
is robustis robust adaptive exact arithmeticadaptive exact arithmetic
C code at http://www.cs.cmu.edu/~quake/triangle.htmlC code at http://www.cs.cmu.edu/~quake/triangle.html
Approach: Overview
Based on Ruppert’s Based on Ruppert’s Delaunay Refinement Delaunay Refinement AlgorithmAlgorithm
InputInput: Planar Straight Line : Planar Straight Line Graph (PSLG)Graph (PSLG) collection of vertices and collection of vertices and
segmentssegments Step 1Step 1: Construct Delaunay : Construct Delaunay
triangulation of triangulation of point setpoint set
Approach: Overview (continued)
Step 2Step 2: : Start with the Start with the
Delaunay Delaunay triangulation of the triangulation of the point setpoint set
Add input segmentsAdd input segments segments become segments become
constraintsconstraints constrainedconstrained Delaunay Delaunay
triangulationtriangulation
some differencessome differences
Approach: Overview (continued)
Step 3Step 3: : Remove triangles from Remove triangles from
concavitiesconcavities ““triangle-eating virus”triangle-eating virus”
Step 4Step 4: : Refine mesh to satisfy Refine mesh to satisfy
additional constraints on additional constraints on triangle’s minimumtriangle’s minimum angle sizeangle size areaarea
Step 1: Construct Delaunay Triangulation of Point Set
Delaunay Triangulation Algorithms:Delaunay Triangulation Algorithms: O(nlogn) O(nlogn) expectedexpected time: time:
Randomized incremental insertionRandomized incremental insertion Edge flipping restores empty circle propertyEdge flipping restores empty circle property
O(nlogn) worst-case time:O(nlogn) worst-case time: Compute Voronoi diagram, then dualizeCompute Voronoi diagram, then dualize
Fortune’s plane sweep (parabolic front)Fortune’s plane sweep (parabolic front)
O(nlogn) worst-case time:O(nlogn) worst-case time: Divide-and-ConquerDivide-and-Conquer
alternating cuts alternating cuts
Shewchuck Shewchuck experimental experimental comparison comparison [speed, correctness][speed, correctness]
fastestfastest
slowestslowest[point location bottleneck][point location bottleneck]
deBerg handoutdeBerg handout
Delaunay Triangulation Algorithms: Divide-and-Conquer
O(nlogn) worst-case timeO(nlogn) worst-case time Recursively halve input vertex setRecursively halve input vertex set Stop when size = 2 or 3Stop when size = 2 or 3 Triangulate small setTriangulate small set
forms edge(s) or triangleforms edge(s) or triangle Merge 2 triangulationsMerge 2 triangulations
Ghost triangles allow fast convex Ghost triangles allow fast convex hull traversalhull traversal
Fit together like gear teethFit together like gear teeth
Step 2: Constrained Delaunay Triangulation
Force mesh to conform to input Force mesh to conform to input line segmentsline segments User Chooses Approach:User Chooses Approach:
Recursive segment subdivisionRecursive segment subdivision Insert segment midpointInsert segment midpoint Flip edges to restore Delaunay (empty circle) propertyFlip edges to restore Delaunay (empty circle) property
Constrained Delaunay triangulation (Constrained Delaunay triangulation (defaultdefault)) Insert entire segmentInsert entire segment Delete triangles it overlapsDelete triangles it overlaps Retriangulate regions on each side of segmentRetriangulate regions on each side of segment No new vertices are insertedNo new vertices are inserted
Step 4: Mesh Refinement
Refine mesh to satisfy additional constraints on minimum Refine mesh to satisfy additional constraints on minimum triangletriangle
angle sizeangle size areaarea
Insert new verticesInsert new vertices Flip edges to restore Delaunay (empty circle) propertyFlip edges to restore Delaunay (empty circle) property Halting Issue:Halting Issue:
Halts for angle constraint <= 27Halts for angle constraint <= 27oo
May not halt for angle constraint >= 33.9May not halt for angle constraint >= 33.9oo
Step 4: Mesh Refinement (continued)
Vertex Insertion Rules:Vertex Insertion Rules: Segment’s Diametral CircleSegment’s Diametral Circle
smallest circle containing smallest circle containing segmentsegment
any point in the circle any point in the circle encroachesencroaches on segment on segment
split encroached segmentsplit encroached segment insert vertex at midpointinsert vertex at midpoint
Triangle’s CircumcircleTriangle’s Circumcircle circle through all 3 verticescircle through all 3 vertices bad triangle:bad triangle:
angle too smallangle too small area too largearea too large
split bad trianglesplit bad triangle insert vertex at circumcenterinsert vertex at circumcenter
Step 4: Mesh Refinement (continued)
Implementation Issues: Representation
Ghost triangles:Ghost triangles: connected in ring about a “vertex connected in ring about a “vertex
at infinity”at infinity” facilitate convex hull traversalfacilitate convex hull traversal
+ Topologically richer + Topologically richer + Elegant+ Elegant- Slower- Slower- More memory - More memory
edge-basededge-based
representation tradeoffsrepresentation tradeoffs
triangle-basedtriangle-based
- Topologically less - Topologically less rich rich
- Longer code- Longer code+ Faster+ Faster+ Less memory+ Less memory
Shewchuck Shewchuck preferencepreference
Implementation Issues: Robustness
TestsTests Can influence program flow of controlCan influence program flow of control Can classify entities (e.g. sweep-line events)Can classify entities (e.g. sweep-line events) Depend on correctness of Depend on correctness of geometric predicatesgeometric predicates
Orientation (left/right/on)Orientation (left/right/on) In-Circle (in/out/on)In-Circle (in/out/on) Each computes sign of a determinantEach computes sign of a determinant
ConstructionsConstructions Represent geometric objectsRepresent geometric objects Often determine outputOften determine output
incorrectness can be seriousincorrectness can be serious
some incorrectness can sometimes be some incorrectness can sometimes be toleratedtolerated
Implementation Issues: Robustness (continued)
Ideal GoalIdeal Goal: : real arithmeticreal arithmetic for for some operationssome operations
ChallengeChallenge: : compounded compounded roundoff error in floating-point roundoff error in floating-point arithmetic calculations:arithmetic calculations: Tests: can cause programTests: can cause program
to hangto hang to crashto crash to produce incorrect outputto produce incorrect output
wrong topologywrong topology Constructions:Constructions:
can cause approximate resultscan cause approximate results
What causes What causes incorrectness?incorrectness?
Implementation Issues: Robustness (continued)
Arithmetic Alternatives to Floating-Point:Arithmetic Alternatives to Floating-Point: Integer or rational exact arithmeticInteger or rational exact arithmetic
fixed precisionfixed precision extended precisionextended precision
Floating point + Floating point + -testing-testing robust topological decisionsrobust topological decisions filter: filter:
identify adequate precision for an operation (identify adequate precision for an operation (bit complexitybit complexity) ) if expressible as multivariate polynomial, degree gives clueif expressible as multivariate polynomial, degree gives clue
floating-point comparisons except when correctness is threatenedfloating-point comparisons except when correctness is threatened adaptive precision: adaptive precision:
compute quantity (e.g. sign of determinant) via successively more accurate compute quantity (e.g. sign of determinant) via successively more accurate approximationsapproximations
stop when uncertainty in result is smallstop when uncertainty in result is small
No single solution fits all needs. Collection of techniques is needed.No single solution fits all needs. Collection of techniques is needed.
slow but sureslow but sure fast but loosefast but loose
exactexact floating-ptfloating-pthybridhybrid
time vs. error tradeofftime vs. error tradeoff
Implementation Issues: Robustness (continued)
Shewchuck uses:Shewchuck uses: multi-stage adaptive precisionmulti-stage adaptive precision for geometric primitives for geometric primitives
Orientation (left/right/on)Orientation (left/right/on) In-Circle (in/out/on)In-Circle (in/out/on) EachEach
computes sign of a determinantcomputes sign of a determinant takes floating-pt inputstakes floating-pt inputs stops when uncertainty in result is smallstops when uncertainty in result is small can reuse previous, less accurate approximationscan reuse previous, less accurate approximations
fast arbitrary precision arithmeticfast arbitrary precision arithmetic for small (yet extended) precision valuesfor small (yet extended) precision values
For general discussion of robustness issues and alternatives, see For general discussion of robustness issues and alternatives, see StrategicStrategic Directions in Computational Geometry Working Group ReportDirections in Computational Geometry Working Group Report
Approximate Nearest Neighbor Searching
““An Optimal Algorithm for An Optimal Algorithm for Approximate Nearest Neighbor Approximate Nearest Neighbor Searching in Fixed Dimensions”Searching in Fixed Dimensions”
Arya, Mount, Netanyahu, Arya, Mount, Netanyahu, Silverman, WuSilverman, Wu
Goals
Fast nearest neighbor query in Fast nearest neighbor query in dd--dimensional set of dimensional set of nn points: points: approximate nearest neighborapproximate nearest neighbor
distance within factor of (1+distance within factor of (1+) of true closest ) of true closest neighborneighbor
preprocess using O(preprocess using O(dndnloglognn) time, O() time, O(dndn) space) space Balanced-Box Decomposition (BDD) treeBalanced-Box Decomposition (BDD) tree note that space, time are indepenent of note that space, time are indepenent of
query in O(cquery in O(cd,d,loglognn) time) time
C++ code for simplified version is at http://www.cs.umd.edu/~mount/ANNC++ code for simplified version is at http://www.cs.umd.edu/~mount/ANN
Approach: Distance Assumptions
Use LUse Lpp (also called Minkowski) metric (also called Minkowski) metric assume it can be computed in O(d) timeassume it can be computed in O(d) time pth root need not be computed when comparing distancespth root need not be computed when comparing distances
Approximate nearest neighborApproximate nearest neighbor distance within factor of (1+distance within factor of (1+) of true closest neighbor p*) of true closest neighbor p*
Can change Can change or metric without rebuilding data or metric without rebuilding data structurestructure
pd
j
p
jjp qxqxqqd
1
12121 )()(),(
)*,()1(),( qpdistqpdist
Approach: Overview
Preprocess points:Preprocess points: Balanced-Box Decomposition (BDD) treeBalanced-Box Decomposition (BDD) tree
Query algorithm: for query point qQuery algorithm: for query point q Locate leaf cell containing q in O(log n) timeLocate leaf cell containing q in O(log n) time Priority search: Enumerate leaf cells in increasing Priority search: Enumerate leaf cells in increasing
distance order from qdistance order from q For each leaf cell, calculate distance from q to cell’s pointFor each leaf cell, calculate distance from q to cell’s point Keep track of closest point p seen so farKeep track of closest point p seen so far Stop when distance from q to leaf > dist(q,p)/(1+Stop when distance from q to leaf > dist(q,p)/(1+)) Return p as approximate nearest neighbor to q.Return p as approximate nearest neighbor to q.
Balanced Box Decomposition(BBD) Tree
Similar to kd-tree Similar to kd-tree [Samet handout][Samet handout] Binary treeBinary tree Tree structure stored in main Tree structure stored in main
memorymemory Cutting planes are orthogonal to Cutting planes are orthogonal to
axesaxes Alternating dimensionsAlternating dimensions
O(log n) heightO(log n) height Subdivides space into regions of Subdivides space into regions of
O(d) complexity using d-O(d) complexity using d-dimensional rectanglesdimensional rectangles
Can be built in O(dn log n) timeCan be built in O(dn log n) time
x1
x4x3
y1
x2
y2
y3
One possible One possible kd-like tree kd-like tree for the above for the above pointspoints(not a BDD (not a BDD tree, though)tree, though)
y1
x1 x1
27 y2
15
y2
y3
x2
8 9
x3
x4
3
4
6
<< >=>=
Balanced Box Decomposition(BBD) Tree (continued)
Distinguishing features of BBD tree:Distinguishing features of BBD tree: Cell is eitherCell is either
d-dimensional rectangle ord-dimensional rectangle or difference of 2 d-dimensional nested rectangles difference of 2 d-dimensional nested rectangles
In this sense, BDD tree is like:In this sense, BDD tree is like: Optimized kd-tree: partition points into roughly = sized setsOptimized kd-tree: partition points into roughly = sized sets
While descending in tree, number of points on path decreases While descending in tree, number of points on path decreases exponentiallyexponentially
Specialized Quadtree: aspect ratio of box is bounded by a Specialized Quadtree: aspect ratio of box is bounded by a constantconstant
While descending in tree, size of region on path decreases While descending in tree, size of region on path decreases exponentiallyexponentially
Leaf may be associated with more than 1 point in/on Leaf may be associated with more than 1 point in/on cell: O(n) nodecell: O(n) node
Inner boxes are “sticky”: if it is close to edge, it “sticks”Inner boxes are “sticky”: if it is close to edge, it “sticks”
subdivisionsubdivision
treetree
splitsplit
shrinkshrink
Splitting a Box: Midpoint
Splitting a Box: Middle-Interval
Packing Constraint
Priority Search from Query Point
Incremental Distance [Arya, Mount93]
Incrementally update distance from parent box to Incrementally update distance from parent box to each child when split is performedeach child when split is performed
Maintain sum of appropriate powers of coordinate Maintain sum of appropriate powers of coordinate differences between query point and nearest point differences between query point and nearest point of outer boxof outer box
Split: Split: Closer child has same distance as parentCloser child has same distance as parent Further child’s distance needs only 1-coordinate update Further child’s distance needs only 1-coordinate update
(along splitting dimension)(along splitting dimension) Makes a difference in higher dimensions!Makes a difference in higher dimensions!
Experiments
Experiments generated points from a variety of probability Experiments generated points from a variety of probability distributions:distributions:UniformUniform GaussianGaussian LaplaceLaplace Correlated GaussianCorrelated Gaussian
Correlated LaplacianCorrelated Laplacian Clustered GaussianClustered Gaussian Clustered SegmentsClustered Segments
Experiments
Experiments
Experiments
Conclusions
Algorithm is not necessarily practical for large Algorithm is not necessarily practical for large dimensionsdimensions But, for dimensions <= ~20, does wellBut, for dimensions <= ~20, does well
Shrinking helps with highly clustered datasets, but Shrinking helps with highly clustered datasets, but was not often needed in their experimentswas not often needed in their experiments Only needed for 5-20% of tree nodesOnly needed for 5-20% of tree nodes
BBD tree (in paper’s form) is primarily for BBD tree (in paper’s form) is primarily for static static point setpoint set But, auxiliary data structure could maintain changesBut, auxiliary data structure could maintain changes
Project Update
Project
ProposalProposal Monday, 4/9Monday, 4/9 2%2%Interim ReportInterim Report Monday, 4/23Monday, 4/23 5%5%Final PresentationFinal Presentation Monday, 5/7Monday, 5/7 8%8%Final SubmissionFinal Submission Monday, 5/14Monday, 5/14 10%10%
25% of course grade25% of course grade
DeliverableDeliverable Due DateDue Date Grade %Grade %
Guidelines: Final Submission AbstractAbstract: Concise overview (at most 1 page): Concise overview (at most 1 page) IntroductionIntroduction: :
Motivation: Why did you choose this project?Motivation: Why did you choose this project? Related Work: Context with respect to CG literatureRelated Work: Context with respect to CG literature Summary of ResultsSummary of Results
Main Body of Paper: (one or more sections)Main Body of Paper: (one or more sections) ConclusionConclusion::
Summary: What did you accomplish?Summary: What did you accomplish? Future Work: What would you do if you had more time?Future Work: What would you do if you had more time?
ReferencesReferences: : Bibliography (papers, books that you used)Bibliography (papers, books that you used)
Well- written final submissions with research content may be Well- written final submissions with research content may be eligible for publishing as UMass Lowell CS technical reports. eligible for publishing as UMass Lowell CS technical reports.
Guidelines: Final Submission
Main Body of Paper: Main Body of Paper: If your project involves Theory/ Algorithm:If your project involves Theory/ Algorithm:
Informal algorithm description (& example)Informal algorithm description (& example) PseudocodePseudocode Analysis:Analysis:
CorrectnessCorrectness Solutions generated by algorithm are correctSolutions generated by algorithm are correct account for account for
degenerate/boundary/special casesdegenerate/boundary/special cases If a correct solution exists, algorithm finds itIf a correct solution exists, algorithm finds it Control structures (loops, recursions,...) terminate correctly Control structures (loops, recursions,...) terminate correctly
Asymptotic Running Time and/or Space UsageAsymptotic Running Time and/or Space Usage
Guidelines: Final Submission
Main Body of Paper:Main Body of Paper: If your project involves Implementation:If your project involves Implementation:
Informal descriptionInformal description Resources & Environment: Resources & Environment:
what language did you code in?what language did you code in? what existing code did you use? (software libraries, etc.)what existing code did you use? (software libraries, etc.) what equipment did you use? (machine, OS, compiler)what equipment did you use? (machine, OS, compiler)
AssumptionsAssumptions parameter valuesparameter values
Test casesTest cases tables, figurestables, figures representative examplesrepresentative examples
Guidelines: Interim Report
Structured like Final Submission, except: Structured like Final Submission, except: no Abstract or Conclusionno Abstract or Conclusion fill in only what you’ve done so farfill in only what you’ve done so far can be revised latercan be revised later include a revised proposal if neededinclude a revised proposal if needed identify any issues you have encountered and identify any issues you have encountered and
your plan for resolving them your plan for resolving them