Upload
jessie-cameron
View
214
Download
0
Embed Size (px)
Citation preview
1www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Self-trimming Objective:
– We are given a polyloop that may self-intersect.
– We want to extract from it a set of manifold curves that bound the major areas enclosed by the original curve
Case study of how to design and implement a solution to this complex problem
– Metaphor
– Notation
– Approach
– Representations
– Data structures
– Debugging tools
– Implementation
– Documentation
2www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Example
inputinput resultresult
3www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Use a metaphor to invent a solutionInvent a metaphor The edges are streets There are sidewalks along the network of streets
Reformulate your problem using your metaphor terminology The sidewalks form closed-loop circuits We want to identify a subset of these circuits If we only take the streets along these circuits, there should be no crossings
Use this terminology to invent an approach Compute all crossings and splits streets at these crossings (1) Identify circuits (2) Identify the smallest area circuit that goes through a crossing (3) Delete (close) its streets and sidewalks (4) Repeat (3) and (4) as necessary
4www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Test example
(1) insert crossings(1) insert crossings
(2) trace circuits(2) trace circuits
(3) find smallest area circuit with crossing(3) find smallest area circuit with crossing
(4) delete its streets and sidewalks(4) delete its streets and sidewalks
(…) repeat (3) and (4) as necessary(…) repeat (3) and (4) as necessary
5www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Notation, primitive, operators Define your primitives
sidewalk s (1 block strip) Select visualization symbol
arrow along sidewalk Select operators and notation
s.n: next sidewalk (along circuit)s.o: opposite sidewalk (across street)s.v: vertex ID of crossing reached by ss.g: point where s.v is located
This is a fundamental step in solving the problem.Explore several ideas and do not hesitate to change
your notation.
s.ns.nss
s.os.os.vs.v
6www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Initialization of sidewalks
The input is an ordered set of verticesn(v) is the next vertex after v in cyclic order (use modulo)
Initialize Keep track of previous step
previous sidewalks ps, po, and previous vertex pv
For each vertex ID v doCreate two sidewalks s and o
s.o=o; o.o=s;
o.v=pv; s.v=v;
ps.n=s; o.n=po;
ps=s; po=o; pv=v;psps
ssoo
vvpvpv
popo
7www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Many cases, try to simplify the solution– Invent primitive steps
– Do not worry about order yet
Identify coincident vertices and merge them– mergeVertices(s,t)
Split edge when a vertex overlaps the tolerance zone around its interior – insertVertex(s,t)
Split edges at their intersections– splitEdges(s,t)
Insert crossings
tolerance zonetolerance zone
sstt
ss tt
ss
tt
8www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Fix the order
For each sidewalk, – identify its proper next n by computing angles for all sidewalks
leaving s.v
If (n!=s.n) swap them
sstt t.nt.n
s.ns.n
sstt
t.nt.ns.ns.n
9www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Trace the circuits
Define an algorithm at a high level
Do not commit to any particular data structure or implementation Associate a marker (color) with each sidewalk Set all markers to white As long as there is a white sidewalks s Pick a new color and trace the circuit of s
– using t=s; repeat { … t=t.n; }
– until you are back to s
s.ns.nss
s.os.os.vs.v
10www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Compute the area of each circuit
Pick a random point p Set area A=0; For each sidewalk s of circuit do
A+=signedAreaOfTriangle(P, s.g, s.o.g);
Return abs(A);
11www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Look for crossings in circuit
if (s.n.o.n!=s.o) s leads to a crossing
sss.os.o
s.ns.n
sss.os.o
s.ns.n
s.n.os.n.o s.n.os.n.o
12www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Delete loop
Fix the .n pointers of the remaining sidewalks before deleting the small loop
ss
s.ns.n
sss.ns.n
13www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Data structures
The simpler--the better Vertices: G[nv]; // table of points Sidewalks: integers in [0,ns]; Pointers from sidewalks:
N[s] // nextO[s] // oppositeV[s] // vertex integer ID
Notation-to-codes.n.o is O[N[s]]s.o=t.n is O[s]=N[t]
14www.gvu.gatech.edu/www.gvu.gatech.edu/~jarek~jarek
Jarek Rossignac,Jarek Rossignac, 2008 2008
Debugging tools Use graphics Have a global variable s Show s, s.n, s.o as red, green, blue arrows Use keys to move
s=s.ns=s.o
Check the integrity of your model Debug each operator A different key activates
– mergeVertices– insertVertex– splitEdgecheck each one before implementing the next
Show vertices (as dots). Crossings as larger dots. Display the streets of the smallest loop. Prepare test cases for each step.