rbpoly2tri 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/poly2tri/common/shapes.cc +334 -0
- data/ext/poly2tri/common/shapes.h +320 -0
- data/ext/poly2tri/common/utils.h +102 -0
- data/ext/poly2tri/poly2tri.h +39 -0
- data/ext/poly2tri/sweep/advancing_front.cc +108 -0
- data/ext/poly2tri/sweep/advancing_front.h +119 -0
- data/ext/poly2tri/sweep/cdt.cc +72 -0
- data/ext/poly2tri/sweep/cdt.h +69 -0
- data/ext/poly2tri/sweep/sweep.cc +820 -0
- data/ext/poly2tri/sweep/sweep.h +126 -0
- data/ext/poly2tri/sweep/sweep_context.cc +201 -0
- data/ext/poly2tri/sweep/sweep_context.h +185 -0
- data/ext/rbpoly2tri/extconf.rb +16 -0
- data/ext/rbpoly2tri/rbpoly2tri.cc +198 -0
- data/ext/throw_assert/assert.h +19 -0
- data/lib/rbpoly2tri.rb +1 -0
- metadata +62 -0
@@ -0,0 +1,102 @@
|
|
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 UTILS_H
|
33
|
+
#define UTILS_H
|
34
|
+
|
35
|
+
#include <exception>
|
36
|
+
#include <math.h>
|
37
|
+
|
38
|
+
namespace p2t {
|
39
|
+
|
40
|
+
const double PI_3div4 = 3 * M_PI / 4;
|
41
|
+
const double EPSILON = 1e-12;
|
42
|
+
|
43
|
+
enum Orientation { CW, CCW, COLLINEAR };
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Forumla to calculate signed area<br>
|
47
|
+
* Positive if CCW<br>
|
48
|
+
* Negative if CW<br>
|
49
|
+
* 0 if collinear<br>
|
50
|
+
* <pre>
|
51
|
+
* A[P1,P2,P3] = (x1*y2 - y1*x2) + (x2*y3 - y2*x3) + (x3*y1 - y3*x1)
|
52
|
+
* = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)
|
53
|
+
* </pre>
|
54
|
+
*/
|
55
|
+
Orientation Orient2d(Point& pa, Point& pb, Point& pc)
|
56
|
+
{
|
57
|
+
double detleft = (pa.x - pc.x) * (pb.y - pc.y);
|
58
|
+
double detright = (pa.y - pc.y) * (pb.x - pc.x);
|
59
|
+
double val = detleft - detright;
|
60
|
+
if (val > -EPSILON && val < EPSILON) {
|
61
|
+
return COLLINEAR;
|
62
|
+
} else if (val > 0) {
|
63
|
+
return CCW;
|
64
|
+
}
|
65
|
+
return CW;
|
66
|
+
}
|
67
|
+
|
68
|
+
bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
|
69
|
+
{
|
70
|
+
double pdx = pd.x;
|
71
|
+
double pdy = pd.y;
|
72
|
+
double adx = pa.x - pdx;
|
73
|
+
double ady = pa.y - pdy;
|
74
|
+
double bdx = pb.x - pdx;
|
75
|
+
double bdy = pb.y - pdy;
|
76
|
+
|
77
|
+
double adxbdy = adx * bdy;
|
78
|
+
double bdxady = bdx * ady;
|
79
|
+
double oabd = adxbdy - bdxady;
|
80
|
+
|
81
|
+
if (oabd <= EPSILON) {
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
|
85
|
+
double cdx = pc.x - pdx;
|
86
|
+
double cdy = pc.y - pdy;
|
87
|
+
|
88
|
+
double cdxady = cdx * ady;
|
89
|
+
double adxcdy = adx * cdy;
|
90
|
+
double ocad = cdxady - adxcdy;
|
91
|
+
|
92
|
+
if (ocad <= EPSILON) {
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
#endif
|
102
|
+
|
@@ -0,0 +1,39 @@
|
|
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 POLY2TRI_H
|
33
|
+
#define POLY2TRI_H
|
34
|
+
|
35
|
+
#include "common/shapes.h"
|
36
|
+
#include "sweep/cdt.h"
|
37
|
+
|
38
|
+
#endif
|
39
|
+
|
@@ -0,0 +1,108 @@
|
|
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
|
+
#include "advancing_front.h"
|
32
|
+
|
33
|
+
namespace p2t {
|
34
|
+
|
35
|
+
AdvancingFront::AdvancingFront(Node& head, Node& tail)
|
36
|
+
{
|
37
|
+
head_ = &head;
|
38
|
+
tail_ = &tail;
|
39
|
+
search_node_ = &head;
|
40
|
+
}
|
41
|
+
|
42
|
+
Node* AdvancingFront::LocateNode(const double& x)
|
43
|
+
{
|
44
|
+
Node* node = search_node_;
|
45
|
+
|
46
|
+
if (x < node->value) {
|
47
|
+
while ((node = node->prev) != NULL) {
|
48
|
+
if (x >= node->value) {
|
49
|
+
search_node_ = node;
|
50
|
+
return node;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
} else {
|
54
|
+
while ((node = node->next) != NULL) {
|
55
|
+
if (x < node->value) {
|
56
|
+
search_node_ = node->prev;
|
57
|
+
return node->prev;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return NULL;
|
62
|
+
}
|
63
|
+
|
64
|
+
Node* AdvancingFront::FindSearchNode(const double& x)
|
65
|
+
{
|
66
|
+
// TODO: implement BST index
|
67
|
+
return search_node_;
|
68
|
+
}
|
69
|
+
|
70
|
+
Node* AdvancingFront::LocatePoint(const Point* point)
|
71
|
+
{
|
72
|
+
const double px = point->x;
|
73
|
+
Node* node = FindSearchNode(px);
|
74
|
+
const double nx = node->point->x;
|
75
|
+
|
76
|
+
if (px == nx) {
|
77
|
+
if (point != node->point) {
|
78
|
+
// We might have two nodes with same x value for a short time
|
79
|
+
if (point == node->prev->point) {
|
80
|
+
node = node->prev;
|
81
|
+
} else if (point == node->next->point) {
|
82
|
+
node = node->next;
|
83
|
+
} else {
|
84
|
+
assert(0);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
} else if (px < nx) {
|
88
|
+
while ((node = node->prev) != NULL) {
|
89
|
+
if (point == node->point) {
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
} else {
|
94
|
+
while ((node = node->next) != NULL) {
|
95
|
+
if (point == node->point)
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
if(node) search_node_ = node;
|
100
|
+
return node;
|
101
|
+
}
|
102
|
+
|
103
|
+
AdvancingFront::~AdvancingFront()
|
104
|
+
{
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
@@ -0,0 +1,119 @@
|
|
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 ADVANCED_FRONT_H
|
33
|
+
#define ADVANCED_FRONT_H
|
34
|
+
|
35
|
+
#include "../common/shapes.h"
|
36
|
+
|
37
|
+
namespace p2t {
|
38
|
+
|
39
|
+
struct Node;
|
40
|
+
|
41
|
+
// Advancing front node
|
42
|
+
struct Node {
|
43
|
+
Point* point;
|
44
|
+
Triangle* triangle;
|
45
|
+
|
46
|
+
Node* next;
|
47
|
+
Node* prev;
|
48
|
+
|
49
|
+
double value;
|
50
|
+
|
51
|
+
Node(Point& p) : point(&p), triangle(NULL), value(p.x), next(NULL), prev(NULL)
|
52
|
+
{
|
53
|
+
}
|
54
|
+
|
55
|
+
Node(Point& p, Triangle& t) : point(&p), triangle(&t), value(p.x),
|
56
|
+
next(NULL), prev(NULL)
|
57
|
+
{
|
58
|
+
}
|
59
|
+
|
60
|
+
};
|
61
|
+
|
62
|
+
// Advancing front
|
63
|
+
class AdvancingFront {
|
64
|
+
public:
|
65
|
+
|
66
|
+
AdvancingFront(Node& head, Node& tail);
|
67
|
+
// Destructor
|
68
|
+
~AdvancingFront();
|
69
|
+
|
70
|
+
Node* head();
|
71
|
+
void set_head(Node* node);
|
72
|
+
Node* tail();
|
73
|
+
void set_tail(Node* node);
|
74
|
+
Node* search();
|
75
|
+
void set_search(Node* node);
|
76
|
+
|
77
|
+
/// Locate insertion point along advancing front
|
78
|
+
Node* LocateNode(const double& x);
|
79
|
+
|
80
|
+
Node* LocatePoint(const Point* point);
|
81
|
+
|
82
|
+
private:
|
83
|
+
|
84
|
+
Node* head_, *tail_, *search_node_;
|
85
|
+
|
86
|
+
Node* FindSearchNode(const double& x);
|
87
|
+
};
|
88
|
+
|
89
|
+
inline Node* AdvancingFront::head()
|
90
|
+
{
|
91
|
+
return head_;
|
92
|
+
}
|
93
|
+
inline void AdvancingFront::set_head(Node* node)
|
94
|
+
{
|
95
|
+
head_ = node;
|
96
|
+
}
|
97
|
+
|
98
|
+
inline Node* AdvancingFront::tail()
|
99
|
+
{
|
100
|
+
return tail_;
|
101
|
+
}
|
102
|
+
inline void AdvancingFront::set_tail(Node* node)
|
103
|
+
{
|
104
|
+
tail_ = node;
|
105
|
+
}
|
106
|
+
|
107
|
+
inline Node* AdvancingFront::search()
|
108
|
+
{
|
109
|
+
return search_node_;
|
110
|
+
}
|
111
|
+
|
112
|
+
inline void AdvancingFront::set_search(Node* node)
|
113
|
+
{
|
114
|
+
search_node_ = node;
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
#endif
|
@@ -0,0 +1,72 @@
|
|
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
|
+
#include "cdt.h"
|
32
|
+
|
33
|
+
namespace p2t {
|
34
|
+
|
35
|
+
CDT::CDT(std::vector<Point*> polyline)
|
36
|
+
{
|
37
|
+
sweep_context_ = new SweepContext(polyline);
|
38
|
+
sweep_ = new Sweep;
|
39
|
+
}
|
40
|
+
|
41
|
+
void CDT::AddHole(std::vector<Point*> polyline)
|
42
|
+
{
|
43
|
+
sweep_context_->AddHole(polyline);
|
44
|
+
}
|
45
|
+
|
46
|
+
void CDT::AddPoint(Point* point) {
|
47
|
+
sweep_context_->AddPoint(point);
|
48
|
+
}
|
49
|
+
|
50
|
+
void CDT::Triangulate()
|
51
|
+
{
|
52
|
+
sweep_->Triangulate(*sweep_context_);
|
53
|
+
}
|
54
|
+
|
55
|
+
std::vector<p2t::Triangle*> CDT::GetTriangles()
|
56
|
+
{
|
57
|
+
return sweep_context_->GetTriangles();
|
58
|
+
}
|
59
|
+
|
60
|
+
std::list<p2t::Triangle*> CDT::GetMap()
|
61
|
+
{
|
62
|
+
return sweep_context_->GetMap();
|
63
|
+
}
|
64
|
+
|
65
|
+
CDT::~CDT()
|
66
|
+
{
|
67
|
+
delete sweep_context_;
|
68
|
+
delete sweep_;
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
@@ -0,0 +1,69 @@
|
|
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 CDT_H
|
33
|
+
#define CDT_H
|
34
|
+
|
35
|
+
#include "advancing_front.h"
|
36
|
+
#include "sweep_context.h"
|
37
|
+
#include "sweep.h"
|
38
|
+
|
39
|
+
namespace p2t {
|
40
|
+
|
41
|
+
class CDT
|
42
|
+
{
|
43
|
+
public:
|
44
|
+
|
45
|
+
/// Constructor
|
46
|
+
CDT(std::vector<Point*> polyline);
|
47
|
+
/// Destructor
|
48
|
+
~CDT();
|
49
|
+
/// Add a hole
|
50
|
+
void AddHole(std::vector<Point*> polyline);
|
51
|
+
/// Add a single point
|
52
|
+
void AddPoint(Point* point);
|
53
|
+
/// Triangulate points
|
54
|
+
void Triangulate();
|
55
|
+
/// Get Delaunay triangles
|
56
|
+
std::vector<Triangle*> GetTriangles();
|
57
|
+
/// Get triangle map
|
58
|
+
std::list<Triangle*> GetMap();
|
59
|
+
|
60
|
+
private:
|
61
|
+
|
62
|
+
SweepContext* sweep_context_;
|
63
|
+
Sweep* sweep_;
|
64
|
+
|
65
|
+
};
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
#endif
|