libosmscout 1.1.1
Loading...
Searching...
No Matches
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
39namespace p2t {
40
41// Inital triangle factor, seed triangle will extend 30% of
42// PointSet width to both left and right.
43const double kAlpha = 0.3;
44
45struct Point;
46class Triangle;
47struct Node;
48struct Edge;
49class AdvancingFront;
50
52public:
53
55explicit SweepContext(const std::vector<Point*> &polyline);
58
59void set_head(Point* p1);
60
61Point* head();
62
63void set_tail(Point* p1);
64
65Point* tail();
66
67int point_count();
68
70
71void RemoveNode(Node* node);
72
73void CreateAdvancingFront(std::vector<Node*> nodes);
74
77
78void AddToMap(Triangle* triangle);
79
80Point* GetPoint(const int& index);
81
83
84void RemoveFromMap(Triangle* triangle);
85
86void AddHole(const std::vector<Point*> &polyline);
87
88void AddPoint(Point* point);
89
91
92void MeshClean(Triangle& triangle);
93
94std::vector<Triangle*> GetTriangles();
95std::list<Triangle*> GetMap();
96
97std::vector<Edge*> edge_list;
98
99struct Basin {
103 double width;
105
106 Basin() : left_node(nullptr), bottom_node(nullptr), right_node(nullptr), width(0.0), left_highest(false)
107 {
108 }
109
110 void Clear()
111 {
112 left_node = nullptr;
113 bottom_node = nullptr;
114 right_node = nullptr;
115 width = 0.0;
116 left_highest = false;
117 }
118};
119
120struct EdgeEvent {
122 bool right;
123
124 EdgeEvent() : constrained_edge(nullptr), right(false)
125 {
126 }
127};
128
131
132private:
133
134friend class Sweep;
135
136std::vector<Triangle*> triangles_;
137std::list<Triangle*> map_;
138std::vector<Point*> points_;
139
140// Advancing front
141AdvancingFront* front_;
142// head point used with advancing front
143Point* head_;
144// tail point used with advancing front
145Point* tail_;
146
147Node *af_head_, *af_middle_, *af_tail_;
148
149void InitTriangulation();
150void InitEdges(std::vector<Point*> polyline);
151
152};
153
155{
156 return front_;
157}
158
160{
161 return points_.size();
162}
163
165{
166 head_ = p1;
167}
168
170{
171 return head_;
172}
173
175{
176 tail_ = p1;
177}
178
180{
181 return tail_;
182}
183
184}
185
186#endif
Definition advancing_front.h:62
void CreateAdvancingFront(std::vector< Node * > nodes)
void RemoveNode(Node *node)
void AddPoint(Point *point)
Point * tail()
Definition sweep_context.h:179
Point * head()
Definition sweep_context.h:169
std::list< Triangle * > GetMap()
void MeshClean(Triangle &triangle)
AdvancingFront * front()
Definition sweep_context.h:154
~SweepContext()
Destructor.
int point_count()
Definition sweep_context.h:159
Node & LocateNode(Point &point)
void AddHole(const std::vector< Point * > &polyline)
Point * GetPoint(const int &index)
Basin basin
Definition sweep_context.h:129
void RemoveFromMap(Triangle *triangle)
SweepContext(const std::vector< Point * > &polyline)
Constructor.
EdgeEvent edge_event
Definition sweep_context.h:130
friend class Sweep
Definition sweep_context.h:134
void AddToMap(Triangle *triangle)
void MapTriangleToNodes(Triangle &t)
Try to map a node to all sides of this triangle that don't have a neighbor.
std::vector< Edge * > edge_list
Definition sweep_context.h:97
void set_head(Point *p1)
Definition sweep_context.h:164
void set_tail(Point *p1)
Definition sweep_context.h:174
std::vector< Triangle * > GetTriangles()
Point * GetPoints()
Definition shapes.h:150
Definition shapes.h:41
const double kAlpha
Definition sweep_context.h:43
Definition shapes.h:123
Definition advancing_front.h:42
Definition shapes.h:45
Definition sweep_context.h:99
void Clear()
Definition sweep_context.h:110
Basin()
Definition sweep_context.h:106
Node * right_node
Definition sweep_context.h:102
bool left_highest
Definition sweep_context.h:104
Node * bottom_node
Definition sweep_context.h:101
Node * left_node
Definition sweep_context.h:100
double width
Definition sweep_context.h:103
Definition sweep_context.h:120
Edge * constrained_edge
Definition sweep_context.h:121
EdgeEvent()
Definition sweep_context.h:124
bool right
Definition sweep_context.h:122