KiCad PCB EDA Suite
sweep.h
Go to the documentation of this file.
1 /*
2  * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
3  * http://code.google.com/p/poly2tri/
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  * * Neither the name of Poly2Tri nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without specific
17  * prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
39 #ifndef SWEEP_H
40 #define SWEEP_H
41 
42 #include <vector>
43 
44 namespace p2t {
45 
46 class SweepContext;
47 struct Node;
48 struct Point;
49 struct Edge;
50 class Triangle;
51 
52 class Sweep
53 {
54 public:
55 
61  void Triangulate(SweepContext& tcx);
62 
66  ~Sweep();
67 
68 private:
69 
75  void SweepPoints(SweepContext& tcx);
76 
86  Node& PointEvent(SweepContext& tcx, Point& point);
87 
95  void EdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
96 
97  void EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point);
98 
107  Node& NewFrontTriangle(SweepContext& tcx, Point& point, Node& node);
108 
114  void Fill(SweepContext& tcx, Node& node);
115 
119  bool Legalize(SweepContext& tcx, Triangle& t);
120 
145  bool Incircle(Point& pa, Point& pb, Point& pc, Point& pd);
146 
161  void RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op);
162 
170  void FillAdvancingFront(SweepContext& tcx, Node& n);
171 
172  // Decision-making about when to Fill hole.
173  // Contributed by ToolmakerSteve2
174  bool LargeHole_DontFill(Node* node);
175  bool AngleExceeds90Degrees(Point* origin, Point* pa, Point* pb);
176  bool AngleExceedsPlus90DegreesOrIsNegative(Point* origin, Point* pa, Point* pb);
177  double Angle(Point& origin, Point& pa, Point& pb);
178 
184  double HoleAngle(Node& node);
185 
189  double BasinAngle(Node& node);
190 
200  void FillBasin(SweepContext& tcx, Node& node);
201 
208  void FillBasinReq(SweepContext& tcx, Node* node);
209 
210  bool IsShallow(SweepContext& tcx, Node& node);
211 
212  bool IsEdgeSideOfTriangle(Triangle& triangle, Point& ep, Point& eq);
213 
214  void FillEdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
215 
216  void FillRightAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
217 
218  void FillRightBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
219 
220  void FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
221 
222  void FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
223 
224  void FillLeftAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
225 
226  void FillLeftBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
227 
228  void FillLeftConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
229 
230  void FillLeftConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
231 
232  void FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* t, Point& p);
233 
246  Triangle& NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op);
247 
259  Point& NextFlipPoint(Point& ep, Point& eq, Triangle& ot, Point& op);
260 
274  void FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_triangle, Triangle& t, Point& p);
275 
277 
278  std::vector<Node*> nodes_;
279 
280 };
281 
282 }
283 
284 #endif
void FillLeftConvexEdgeEvent(SweepContext &tcx, Edge *edge, Node &node)
void SweepPoints(SweepContext &tcx)
Start sweeping the Y-sorted point set from bottom to top.
void FillLeftConcaveEdgeEvent(SweepContext &tcx, Edge *edge, Node &node)
void Triangulate(SweepContext &tcx)
Triangulate.
Triangle & NextFlipTriangle(SweepContext &tcx, int o, Triangle &t, Triangle &ot, Point &p, Point &op)
After a flip we have two triangles and know that only one will still be intersecting the edge...
void FillRightAboveEdgeEvent(SweepContext &tcx, Edge *edge, Node *node)
void FillLeftBelowEdgeEvent(SweepContext &tcx, Edge *edge, Node &node)
bool IsShallow(SweepContext &tcx, Node &node)
void Fill(SweepContext &tcx, Node &node)
Adds a triangle to the advancing front to fill a hole.
double BasinAngle(Node &node)
The basin angle is decided against the horizontal line [1,0].
void FillRightConvexEdgeEvent(SweepContext &tcx, Edge *edge, Node &node)
double HoleAngle(Node &node)
Node & NewFrontTriangle(SweepContext &tcx, Point &point, Node &node)
Creates a new front triangle and legalize it.
void FlipScanEdgeEvent(SweepContext &tcx, Point &ep, Point &eq, Triangle &flip_triangle, Triangle &t, Point &p)
Scan part of the FlipScan algorithm When a triangle pair isn't flippable we will scan for the next p...
void FillAdvancingFront(SweepContext &tcx, Node &n)
Fills holes in the Advancing Front.
void RotateTrianglePair(Triangle &t, Point &p, Triangle &ot, Point &op)
Rotates a triangle pair one vertex CW.
double Angle(Point &origin, Point &pa, Point &pb)
bool AngleExceedsPlus90DegreesOrIsNegative(Point *origin, Point *pa, Point *pb)
Point & NextFlipPoint(Point &ep, Point &eq, Triangle &ot, Point &op)
When we need to traverse from one triangle to the next we need the point in current triangle that is ...
bool Legalize(SweepContext &tcx, Triangle &t)
Returns true if triangle was legalized.
bool IsEdgeSideOfTriangle(Triangle &triangle, Point &ep, Point &eq)
void FinalizationPolygon(SweepContext &tcx)
bool LargeHole_DontFill(Node *node)
Node & PointEvent(SweepContext &tcx, Point &point)
Find closes node to the left of the new point and create a new triangle.
void FillRightConcaveEdgeEvent(SweepContext &tcx, Edge *edge, Node &node)
void FillEdgeEvent(SweepContext &tcx, Edge *edge, Node *node)
void FillBasinReq(SweepContext &tcx, Node *node)
Recursive algorithm to fill a Basin with triangles.
std::vector< Node * > nodes_
Definition: sweep.h:278
bool Incircle(Point &pa, Point &pb, Point &pc, Point &pd)
Requirement:
void FillRightBelowEdgeEvent(SweepContext &tcx, Edge *edge, Node &node)
void FlipEdgeEvent(SweepContext &tcx, Point &ep, Point &eq, Triangle *t, Point &p)
Sweep-line, Constrained Delauney Triangulation (CDT) See: Domiter, V.
Definition: shapes.h:41
bool AngleExceeds90Degrees(Point *origin, Point *pa, Point *pb)
~Sweep()
Destructor - clean up memory.
void FillLeftAboveEdgeEvent(SweepContext &tcx, Edge *edge, Node *node)
void FillBasin(SweepContext &tcx, Node &node)
Fills a basin that has formed on the Advancing Front to the right of given node.
void EdgeEvent(SweepContext &tcx, Edge *edge, Node *node)