KiCad PCB EDA Suite
sweep_context.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  */
31 
32 #ifndef SWEEP_CONTEXT_H
33 #define SWEEP_CONTEXT_H
34 
35 #include <list>
36 #include <vector>
37 #include <cstddef>
38 
39 namespace p2t {
40 // Inital triangle factor, seed triangle will extend 30% of
41 // PointSet width to both left and right.
42 const double kAlpha = 0.3;
43 
44 struct Point;
45 class Triangle;
46 struct Node;
47 struct Edge;
48 class AdvancingFront;
49 
51 {
52 public:
53 
55  SweepContext( std::vector<Point*> polyline );
57  ~SweepContext();
58 
59  void set_head( Point* p1 );
60 
61  Point* head();
62 
63  void set_tail( Point* p1 );
64 
65  Point* tail();
66 
67  int point_count();
68 
69  Node& LocateNode( Point& point );
70 
71  void RemoveNode( Node* node );
72 
73  void CreateAdvancingFront( std::vector<Node*> nodes );
74 
76  void MapTriangleToNodes( Triangle& t );
77 
78  void AddToMap( Triangle* triangle );
79 
80  Point* GetPoint( const int& index );
81 
82  Point* GetPoints();
83 
84  void RemoveFromMap( Triangle* triangle );
85 
86  void AddHole( std::vector<Point*> polyline );
87 
88  void AddPoint( Point* point );
89 
91 
92  void MeshClean( Triangle& triangle );
93 
94  std::vector<Triangle*> GetTriangles();
95 
96  std::list<Triangle*> GetMap();
97 
98  std::vector<Edge*> edge_list;
99 
100  struct Basin
101  {
105  double width;
107 
108  Basin() : left_node( NULL ), bottom_node( NULL ), right_node( NULL ), width( 0.0 ),
109  left_highest( false )
110  {
111  }
112 
113  void Clear()
114  {
115  left_node = NULL;
116  bottom_node = NULL;
117  right_node = NULL;
118  width = 0.0;
119  left_highest = false;
120  }
121  };
122 
123  struct EdgeEvent
124  {
126  bool right;
127 
128  EdgeEvent() : constrained_edge( NULL ), right( false )
129  {
130  }
131  };
132 
135 
136 private:
137 
138  friend class Sweep;
139 
140  std::vector<Triangle*> triangles_;
141  std::list<Triangle*> map_;
142  std::vector<Point*> points_;
143 
144 // Advancing front
146 // head point used with advancing front
148 // tail point used with advancing front
150 
152 
153  void InitTriangulation();
154  void InitEdges( std::vector<Point*> polyline );
155 };
156 
158 {
159  return front_;
160 }
161 
162 
164 {
165  return points_.size();
166 }
167 
168 
169 inline void SweepContext::set_head( Point* p1 )
170 {
171  head_ = p1;
172 }
173 
174 
176 {
177  return head_;
178 }
179 
180 
181 inline void SweepContext::set_tail( Point* p1 )
182 {
183  tail_ = p1;
184 }
185 
186 
188 {
189  return tail_;
190 }
191 }
192 
193 #endif
void InitTriangulation()
void AddToMap(Triangle *triangle)
~SweepContext()
Destructor.
std::list< Triangle * > GetMap()
Point * GetPoints()
void RemoveFromMap(Triangle *triangle)
std::list< Triangle * > map_
void MapTriangleToNodes(Triangle &t)
Try to map a node to all sides of this triangle that don't have a neighbor.
SweepContext(std::vector< Point * > polyline)
Constructor.
void InitEdges(std::vector< Point * > polyline)
void AddPoint(Point *point)
Point * GetPoint(const int &index)
const double kAlpha
Definition: sweep_context.h:42
void RemoveNode(Node *node)
EdgeEvent edge_event
Node & LocateNode(Point &point)
std::vector< Edge * > edge_list
Definition: sweep_context.h:98
void MeshClean(Triangle &triangle)
void set_tail(Point *p1)
AdvancingFront * front_
std::vector< Point * > points_
void set_head(Point *p1)
std::vector< Triangle * > triangles_
void CreateAdvancingFront(std::vector< Node * > nodes)
std::vector< Triangle * > GetTriangles()
Sweep-line, Constrained Delauney Triangulation (CDT) See: Domiter, V.
Definition: shapes.h:41
AdvancingFront * front()
void AddHole(std::vector< Point * > polyline)