mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-26 15:26:12 +01:00
remove trailing whitespace and convert to unix line endings
This commit is contained in:
parent
b4abf3a2b2
commit
47a9c6e038
@ -362,5 +362,4 @@ void Triangle::DebugPrint()
|
|||||||
cout << points_[2]->x << "," << points_[2]->y << endl;
|
cout << points_[2]->x << "," << points_[2]->y << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -320,6 +320,4 @@ inline void Triangle::IsInterior(bool b)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -1,123 +1,122 @@
|
|||||||
/*
|
/*
|
||||||
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||||
* http://code.google.com/p/poly2tri/
|
* http://code.google.com/p/poly2tri/
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||||
* used to endorse or promote products derived from this software without specific
|
* used to endorse or promote products derived from this software without specific
|
||||||
* prior written permission.
|
* prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
// Otherwise #defines like M_PI are undeclared under Visual Studio
|
// Otherwise #defines like M_PI are undeclared under Visual Studio
|
||||||
#define _USE_MATH_DEFINES
|
#define _USE_MATH_DEFINES
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
|
||||||
const double PI_3div4 = 3 * M_PI / 4;
|
const double PI_3div4 = 3 * M_PI / 4;
|
||||||
const double PI_div2 = 1.57079632679489661923;
|
const double PI_div2 = 1.57079632679489661923;
|
||||||
const double EPSILON = 1e-12;
|
const double EPSILON = 1e-12;
|
||||||
|
|
||||||
enum Orientation { CW, CCW, COLLINEAR };
|
enum Orientation { CW, CCW, COLLINEAR };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forumla to calculate signed area<br>
|
* Forumla to calculate signed area<br>
|
||||||
* Positive if CCW<br>
|
* Positive if CCW<br>
|
||||||
* Negative if CW<br>
|
* Negative if CW<br>
|
||||||
* 0 if collinear<br>
|
* 0 if collinear<br>
|
||||||
* <pre>
|
* <pre>
|
||||||
* A[P1,P2,P3] = (x1*y2 - y1*x2) + (x2*y3 - y2*x3) + (x3*y1 - y3*x1)
|
* A[P1,P2,P3] = (x1*y2 - y1*x2) + (x2*y3 - y2*x3) + (x3*y1 - y3*x1)
|
||||||
* = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)
|
* = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
Orientation Orient2d(Point& pa, Point& pb, Point& pc)
|
Orientation Orient2d(Point& pa, Point& pb, Point& pc)
|
||||||
{
|
{
|
||||||
double detleft = (pa.x - pc.x) * (pb.y - pc.y);
|
double detleft = (pa.x - pc.x) * (pb.y - pc.y);
|
||||||
double detright = (pa.y - pc.y) * (pb.x - pc.x);
|
double detright = (pa.y - pc.y) * (pb.x - pc.x);
|
||||||
double val = detleft - detright;
|
double val = detleft - detright;
|
||||||
if (val > -EPSILON && val < EPSILON) {
|
if (val > -EPSILON && val < EPSILON) {
|
||||||
return COLLINEAR;
|
return COLLINEAR;
|
||||||
} else if (val > 0) {
|
} else if (val > 0) {
|
||||||
return CCW;
|
return CCW;
|
||||||
}
|
}
|
||||||
return CW;
|
return CW;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
|
bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
|
||||||
{
|
{
|
||||||
double pdx = pd.x;
|
double pdx = pd.x;
|
||||||
double pdy = pd.y;
|
double pdy = pd.y;
|
||||||
double adx = pa.x - pdx;
|
double adx = pa.x - pdx;
|
||||||
double ady = pa.y - pdy;
|
double ady = pa.y - pdy;
|
||||||
double bdx = pb.x - pdx;
|
double bdx = pb.x - pdx;
|
||||||
double bdy = pb.y - pdy;
|
double bdy = pb.y - pdy;
|
||||||
|
|
||||||
double adxbdy = adx * bdy;
|
double adxbdy = adx * bdy;
|
||||||
double bdxady = bdx * ady;
|
double bdxady = bdx * ady;
|
||||||
double oabd = adxbdy - bdxady;
|
double oabd = adxbdy - bdxady;
|
||||||
|
|
||||||
if (oabd <= EPSILON) {
|
if (oabd <= EPSILON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double cdx = pc.x - pdx;
|
double cdx = pc.x - pdx;
|
||||||
double cdy = pc.y - pdy;
|
double cdy = pc.y - pdy;
|
||||||
|
|
||||||
double cdxady = cdx * ady;
|
double cdxady = cdx * ady;
|
||||||
double adxcdy = adx * cdy;
|
double adxcdy = adx * cdy;
|
||||||
double ocad = cdxady - adxcdy;
|
double ocad = cdxady - adxcdy;
|
||||||
|
|
||||||
if (ocad <= EPSILON) {
|
if (ocad <= EPSILON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
|
bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
|
||||||
{
|
{
|
||||||
double oadb = (pa.x - pb.x)*(pd.y - pb.y) - (pd.x - pb.x)*(pa.y - pb.y);
|
double oadb = (pa.x - pb.x)*(pd.y - pb.y) - (pd.x - pb.x)*(pa.y - pb.y);
|
||||||
if (oadb >= -EPSILON) {
|
if (oadb >= -EPSILON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double oadc = (pa.x - pc.x)*(pd.y - pc.y) - (pd.x - pc.x)*(pa.y - pc.y);
|
double oadc = (pa.x - pc.x)*(pd.y - pc.y) - (pd.x - pc.x)*(pa.y - pc.y);
|
||||||
if (oadc <= EPSILON) {
|
if (oadc <= EPSILON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||||
* http://code.google.com/p/poly2tri/
|
* http://code.google.com/p/poly2tri/
|
||||||
*
|
*
|
||||||
@ -35,5 +35,4 @@
|
|||||||
#include "common/shapes.h"
|
#include "common/shapes.h"
|
||||||
#include "sweep/cdt.h"
|
#include "sweep/cdt.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -105,5 +105,4 @@ AdvancingFront::~AdvancingFront()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -115,4 +115,4 @@ inline void AdvancingFront::set_search(Node* node)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,72 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||||
* http://code.google.com/p/poly2tri/
|
* http://code.google.com/p/poly2tri/
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||||
* used to endorse or promote products derived from this software without specific
|
* used to endorse or promote products derived from this software without specific
|
||||||
* prior written permission.
|
* prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include "cdt.h"
|
#include "cdt.h"
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
|
||||||
CDT::CDT(std::vector<Point*> polyline)
|
CDT::CDT(std::vector<Point*> polyline)
|
||||||
{
|
{
|
||||||
sweep_context_ = new SweepContext(polyline);
|
sweep_context_ = new SweepContext(polyline);
|
||||||
sweep_ = new Sweep;
|
sweep_ = new Sweep;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDT::AddHole(std::vector<Point*> polyline)
|
void CDT::AddHole(std::vector<Point*> polyline)
|
||||||
{
|
{
|
||||||
sweep_context_->AddHole(polyline);
|
sweep_context_->AddHole(polyline);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDT::AddPoint(Point* point) {
|
void CDT::AddPoint(Point* point) {
|
||||||
sweep_context_->AddPoint(point);
|
sweep_context_->AddPoint(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDT::Triangulate()
|
void CDT::Triangulate()
|
||||||
{
|
{
|
||||||
sweep_->Triangulate(*sweep_context_);
|
sweep_->Triangulate(*sweep_context_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<p2t::Triangle*> CDT::GetTriangles()
|
std::vector<p2t::Triangle*> CDT::GetTriangles()
|
||||||
{
|
{
|
||||||
return sweep_context_->GetTriangles();
|
return sweep_context_->GetTriangles();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<p2t::Triangle*> CDT::GetMap()
|
std::list<p2t::Triangle*> CDT::GetMap()
|
||||||
{
|
{
|
||||||
return sweep_context_->GetMap();
|
return sweep_context_->GetMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
CDT::~CDT()
|
CDT::~CDT()
|
||||||
{
|
{
|
||||||
delete sweep_context_;
|
delete sweep_context_;
|
||||||
delete sweep_;
|
delete sweep_;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,105 +1,105 @@
|
|||||||
/*
|
/*
|
||||||
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||||
* http://code.google.com/p/poly2tri/
|
* http://code.google.com/p/poly2tri/
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||||
* used to endorse or promote products derived from this software without specific
|
* used to endorse or promote products derived from this software without specific
|
||||||
* prior written permission.
|
* prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CDT_H
|
#ifndef CDT_H
|
||||||
#define CDT_H
|
#define CDT_H
|
||||||
|
|
||||||
#include "advancing_front.h"
|
#include "advancing_front.h"
|
||||||
#include "sweep_context.h"
|
#include "sweep_context.h"
|
||||||
#include "sweep.h"
|
#include "sweep.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Mason Green <mason.green@gmail.com>
|
* @author Mason Green <mason.green@gmail.com>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
|
||||||
class CDT
|
class CDT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor - add polyline with non repeating points
|
* Constructor - add polyline with non repeating points
|
||||||
*
|
*
|
||||||
* @param polyline
|
* @param polyline
|
||||||
*/
|
*/
|
||||||
CDT(std::vector<Point*> polyline);
|
CDT(std::vector<Point*> polyline);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor - clean up memory
|
* Destructor - clean up memory
|
||||||
*/
|
*/
|
||||||
~CDT();
|
~CDT();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a hole
|
* Add a hole
|
||||||
*
|
*
|
||||||
* @param polyline
|
* @param polyline
|
||||||
*/
|
*/
|
||||||
void AddHole(std::vector<Point*> polyline);
|
void AddHole(std::vector<Point*> polyline);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a steiner point
|
* Add a steiner point
|
||||||
*
|
*
|
||||||
* @param point
|
* @param point
|
||||||
*/
|
*/
|
||||||
void AddPoint(Point* point);
|
void AddPoint(Point* point);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triangulate - do this AFTER you've added the polyline, holes, and Steiner points
|
* Triangulate - do this AFTER you've added the polyline, holes, and Steiner points
|
||||||
*/
|
*/
|
||||||
void Triangulate();
|
void Triangulate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get CDT triangles
|
* Get CDT triangles
|
||||||
*/
|
*/
|
||||||
std::vector<Triangle*> GetTriangles();
|
std::vector<Triangle*> GetTriangles();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get triangle map
|
* Get triangle map
|
||||||
*/
|
*/
|
||||||
std::list<Triangle*> GetMap();
|
std::list<Triangle*> GetMap();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internals
|
* Internals
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SweepContext* sweep_context_;
|
SweepContext* sweep_context_;
|
||||||
Sweep* sweep_;
|
Sweep* sweep_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load Diff
@ -33,7 +33,7 @@
|
|||||||
* Zalik, B.(2008)'Sweep-line algorithm for constrained Delaunay triangulation',
|
* Zalik, B.(2008)'Sweep-line algorithm for constrained Delaunay triangulation',
|
||||||
* International Journal of Geographical Information Science
|
* International Journal of Geographical Information Science
|
||||||
*
|
*
|
||||||
* "FlipScan" Constrained Edge Algorithm invented by Thomas Åhlén, thahlen@gmail.com
|
* "FlipScan" Constrained Edge Algorithm invented by Thomas ?hl?n, thahlen@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SWEEP_H
|
#ifndef SWEEP_H
|
||||||
@ -49,17 +49,17 @@ struct Point;
|
|||||||
struct Edge;
|
struct Edge;
|
||||||
class Triangle;
|
class Triangle;
|
||||||
|
|
||||||
class Sweep
|
class Sweep
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triangulate
|
* Triangulate
|
||||||
*
|
*
|
||||||
* @param tcx
|
* @param tcx
|
||||||
*/
|
*/
|
||||||
void Triangulate(SweepContext& tcx);
|
void Triangulate(SweepContext& tcx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor - clean up memory
|
* Destructor - clean up memory
|
||||||
*/
|
*/
|
||||||
@ -69,7 +69,7 @@ private:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Start sweeping the Y-sorted point set from bottom to top
|
* Start sweeping the Y-sorted point set from bottom to top
|
||||||
*
|
*
|
||||||
* @param tcx
|
* @param tcx
|
||||||
*/
|
*/
|
||||||
void SweepPoints(SweepContext& tcx);
|
void SweepPoints(SweepContext& tcx);
|
||||||
@ -86,8 +86,8 @@ private:
|
|||||||
Node& PointEvent(SweepContext& tcx, Point& point);
|
Node& PointEvent(SweepContext& tcx, Point& point);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param tcx
|
* @param tcx
|
||||||
* @param edge
|
* @param edge
|
||||||
* @param node
|
* @param node
|
||||||
@ -98,7 +98,7 @@ private:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new front triangle and legalize it
|
* Creates a new front triangle and legalize it
|
||||||
*
|
*
|
||||||
* @param tcx
|
* @param tcx
|
||||||
* @param point
|
* @param point
|
||||||
* @param node
|
* @param node
|
||||||
@ -168,8 +168,8 @@ private:
|
|||||||
* @param n
|
* @param n
|
||||||
*/
|
*/
|
||||||
void FillAdvancingFront(SweepContext& tcx, Node& n);
|
void FillAdvancingFront(SweepContext& tcx, Node& n);
|
||||||
|
|
||||||
// Decision-making about when to Fill hole.
|
// Decision-making about when to Fill hole.
|
||||||
// Contributed by ToolmakerSteve2
|
// Contributed by ToolmakerSteve2
|
||||||
bool LargeHole_DontFill(Node* node);
|
bool LargeHole_DontFill(Node* node);
|
||||||
bool AngleExceeds90Degrees(Point* origin, Point* pa, Point* pb);
|
bool AngleExceeds90Degrees(Point* origin, Point* pa, Point* pb);
|
||||||
@ -235,22 +235,22 @@ private:
|
|||||||
/**
|
/**
|
||||||
* After a flip we have two triangles and know that only one will still be
|
* After a flip we have two triangles and know that only one will still be
|
||||||
* intersecting the edge. So decide which to contiune with and legalize the other
|
* intersecting the edge. So decide which to contiune with and legalize the other
|
||||||
*
|
*
|
||||||
* @param tcx
|
* @param tcx
|
||||||
* @param o - should be the result of an orient2d( eq, op, ep )
|
* @param o - should be the result of an orient2d( eq, op, ep )
|
||||||
* @param t - triangle 1
|
* @param t - triangle 1
|
||||||
* @param ot - triangle 2
|
* @param ot - triangle 2
|
||||||
* @param p - a point shared by both triangles
|
* @param p - a point shared by both triangles
|
||||||
* @param op - another point shared by both triangles
|
* @param op - another point shared by both triangles
|
||||||
* @return returns the triangle still intersecting the edge
|
* @return returns the triangle still intersecting the edge
|
||||||
*/
|
*/
|
||||||
Triangle& NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op);
|
Triangle& NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When we need to traverse from one triangle to the next we need
|
* When we need to traverse from one triangle to the next we need
|
||||||
* the point in current triangle that is the opposite point to the next
|
* the point in current triangle that is the opposite point to the next
|
||||||
* triangle.
|
* triangle.
|
||||||
*
|
*
|
||||||
* @param ep
|
* @param ep
|
||||||
* @param eq
|
* @param eq
|
||||||
* @param ot
|
* @param ot
|
||||||
@ -261,10 +261,10 @@ private:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan part of the FlipScan algorithm<br>
|
* Scan part of the FlipScan algorithm<br>
|
||||||
* When a triangle pair isn't flippable we will scan for the next
|
* When a triangle pair isn't flippable we will scan for the next
|
||||||
* point that is inside the flip triangle scan area. When found
|
* point that is inside the flip triangle scan area. When found
|
||||||
* we generate a new flipEdgeEvent
|
* we generate a new flipEdgeEvent
|
||||||
*
|
*
|
||||||
* @param tcx
|
* @param tcx
|
||||||
* @param ep - last point on the edge we are traversing
|
* @param ep - last point on the edge we are traversing
|
||||||
* @param eq - first point on the edge we are traversing
|
* @param eq - first point on the edge we are traversing
|
||||||
@ -282,4 +282,4 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -194,4 +194,4 @@ SweepContext::~SweepContext()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,186 +1,186 @@
|
|||||||
/*
|
/*
|
||||||
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||||
* http://code.google.com/p/poly2tri/
|
* http://code.google.com/p/poly2tri/
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||||
* used to endorse or promote products derived from this software without specific
|
* used to endorse or promote products derived from this software without specific
|
||||||
* prior written permission.
|
* prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SWEEP_CONTEXT_H
|
#ifndef SWEEP_CONTEXT_H
|
||||||
#define SWEEP_CONTEXT_H
|
#define SWEEP_CONTEXT_H
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
|
||||||
// Inital triangle factor, seed triangle will extend 30% of
|
// Inital triangle factor, seed triangle will extend 30% of
|
||||||
// PointSet width to both left and right.
|
// PointSet width to both left and right.
|
||||||
const double kAlpha = 0.3;
|
const double kAlpha = 0.3;
|
||||||
|
|
||||||
struct Point;
|
struct Point;
|
||||||
class Triangle;
|
class Triangle;
|
||||||
struct Node;
|
struct Node;
|
||||||
struct Edge;
|
struct Edge;
|
||||||
class AdvancingFront;
|
class AdvancingFront;
|
||||||
|
|
||||||
class SweepContext {
|
class SweepContext {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
SweepContext(std::vector<Point*> polyline);
|
SweepContext(std::vector<Point*> polyline);
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~SweepContext();
|
~SweepContext();
|
||||||
|
|
||||||
void set_head(Point* p1);
|
void set_head(Point* p1);
|
||||||
|
|
||||||
Point* head();
|
Point* head();
|
||||||
|
|
||||||
void set_tail(Point* p1);
|
void set_tail(Point* p1);
|
||||||
|
|
||||||
Point* tail();
|
Point* tail();
|
||||||
|
|
||||||
size_t point_count();
|
size_t point_count();
|
||||||
|
|
||||||
Node& LocateNode(Point& point);
|
Node& LocateNode(Point& point);
|
||||||
|
|
||||||
void RemoveNode(Node* node);
|
void RemoveNode(Node* node);
|
||||||
|
|
||||||
void CreateAdvancingFront(std::vector<Node*> nodes);
|
void CreateAdvancingFront(std::vector<Node*> nodes);
|
||||||
|
|
||||||
/// Try to map a node to all sides of this triangle that don't have a neighbor
|
/// Try to map a node to all sides of this triangle that don't have a neighbor
|
||||||
void MapTriangleToNodes(Triangle& t);
|
void MapTriangleToNodes(Triangle& t);
|
||||||
|
|
||||||
void AddToMap(Triangle* triangle);
|
void AddToMap(Triangle* triangle);
|
||||||
|
|
||||||
Point* GetPoint(size_t index);
|
Point* GetPoint(size_t index);
|
||||||
|
|
||||||
Point* GetPoints();
|
Point* GetPoints();
|
||||||
|
|
||||||
void RemoveFromMap(Triangle* triangle);
|
void RemoveFromMap(Triangle* triangle);
|
||||||
|
|
||||||
void AddHole(std::vector<Point*> polyline);
|
void AddHole(std::vector<Point*> polyline);
|
||||||
|
|
||||||
void AddPoint(Point* point);
|
void AddPoint(Point* point);
|
||||||
|
|
||||||
AdvancingFront* front();
|
AdvancingFront* front();
|
||||||
|
|
||||||
void MeshClean(Triangle& triangle);
|
void MeshClean(Triangle& triangle);
|
||||||
|
|
||||||
std::vector<Triangle*> GetTriangles();
|
std::vector<Triangle*> GetTriangles();
|
||||||
std::list<Triangle*> GetMap();
|
std::list<Triangle*> GetMap();
|
||||||
|
|
||||||
std::vector<Edge*> edge_list;
|
std::vector<Edge*> edge_list;
|
||||||
|
|
||||||
struct Basin {
|
struct Basin {
|
||||||
Node* left_node;
|
Node* left_node;
|
||||||
Node* bottom_node;
|
Node* bottom_node;
|
||||||
Node* right_node;
|
Node* right_node;
|
||||||
double width;
|
double width;
|
||||||
bool left_highest;
|
bool left_highest;
|
||||||
|
|
||||||
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL), width(0.0), left_highest(false)
|
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL), width(0.0), left_highest(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
left_node = NULL;
|
left_node = NULL;
|
||||||
bottom_node = NULL;
|
bottom_node = NULL;
|
||||||
right_node = NULL;
|
right_node = NULL;
|
||||||
width = 0.0;
|
width = 0.0;
|
||||||
left_highest = false;
|
left_highest = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EdgeEvent {
|
struct EdgeEvent {
|
||||||
Edge* constrained_edge;
|
Edge* constrained_edge;
|
||||||
bool right;
|
bool right;
|
||||||
|
|
||||||
EdgeEvent() : constrained_edge(NULL), right(false)
|
EdgeEvent() : constrained_edge(NULL), right(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Basin basin;
|
Basin basin;
|
||||||
EdgeEvent edge_event;
|
EdgeEvent edge_event;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend class Sweep;
|
friend class Sweep;
|
||||||
|
|
||||||
std::vector<Triangle*> triangles_;
|
std::vector<Triangle*> triangles_;
|
||||||
std::list<Triangle*> map_;
|
std::list<Triangle*> map_;
|
||||||
std::vector<Point*> points_;
|
std::vector<Point*> points_;
|
||||||
|
|
||||||
// Advancing front
|
// Advancing front
|
||||||
AdvancingFront* front_;
|
AdvancingFront* front_;
|
||||||
// head point used with advancing front
|
// head point used with advancing front
|
||||||
Point* head_;
|
Point* head_;
|
||||||
// tail point used with advancing front
|
// tail point used with advancing front
|
||||||
Point* tail_;
|
Point* tail_;
|
||||||
|
|
||||||
Node *af_head_, *af_middle_, *af_tail_;
|
Node *af_head_, *af_middle_, *af_tail_;
|
||||||
|
|
||||||
void InitTriangulation();
|
void InitTriangulation();
|
||||||
void InitEdges(std::vector<Point*> polyline);
|
void InitEdges(std::vector<Point*> polyline);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline AdvancingFront* SweepContext::front()
|
inline AdvancingFront* SweepContext::front()
|
||||||
{
|
{
|
||||||
return front_;
|
return front_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t SweepContext::point_count()
|
inline size_t SweepContext::point_count()
|
||||||
{
|
{
|
||||||
return points_.size();
|
return points_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SweepContext::set_head(Point* p1)
|
inline void SweepContext::set_head(Point* p1)
|
||||||
{
|
{
|
||||||
head_ = p1;
|
head_ = p1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Point* SweepContext::head()
|
inline Point* SweepContext::head()
|
||||||
{
|
{
|
||||||
return head_;
|
return head_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SweepContext::set_tail(Point* p1)
|
inline void SweepContext::set_tail(Point* p1)
|
||||||
{
|
{
|
||||||
tail_ = p1;
|
tail_ = p1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Point* SweepContext::tail()
|
inline Point* SweepContext::tail()
|
||||||
{
|
{
|
||||||
return tail_;
|
return tail_;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
926
testbed/main.cc
926
testbed/main.cc
@ -1,463 +1,463 @@
|
|||||||
/*
|
/*
|
||||||
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||||
* http://code.google.com/p/poly2tri/
|
* http://code.google.com/p/poly2tri/
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||||
* used to endorse or promote products derived from this software without specific
|
* used to endorse or promote products derived from this software without specific
|
||||||
* prior written permission.
|
* prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <GL/glfw.h>
|
#include <GL/glfw.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "../poly2tri/poly2tri.h"
|
#include "../poly2tri/poly2tri.h"
|
||||||
using namespace p2t;
|
using namespace p2t;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void ShutDown(int return_code);
|
void ShutDown(int return_code);
|
||||||
void MainLoop(const double zoom);
|
void MainLoop(const double zoom);
|
||||||
void Draw(const double zoom);
|
void Draw(const double zoom);
|
||||||
void DrawMap(const double zoom);
|
void DrawMap(const double zoom);
|
||||||
void ConstrainedColor(bool constrain);
|
void ConstrainedColor(bool constrain);
|
||||||
double StringToDouble(const std::string& s);
|
double StringToDouble(const std::string& s);
|
||||||
double Random(double (*fun)(double), double xmin, double xmax);
|
double Random(double (*fun)(double), double xmin, double xmax);
|
||||||
double Fun(double x);
|
double Fun(double x);
|
||||||
|
|
||||||
/// Dude hole examples
|
/// Dude hole examples
|
||||||
vector<Point*> CreateHeadHole();
|
vector<Point*> CreateHeadHole();
|
||||||
vector<Point*> CreateChestHole();
|
vector<Point*> CreateChestHole();
|
||||||
|
|
||||||
float rotate_y = 0,
|
float rotate_y = 0,
|
||||||
rotate_z = 0;
|
rotate_z = 0;
|
||||||
const float rotations_per_tick = .2;
|
const float rotations_per_tick = .2;
|
||||||
|
|
||||||
/// Screen center x
|
/// Screen center x
|
||||||
double cx = 0.0;
|
double cx = 0.0;
|
||||||
/// Screen center y
|
/// Screen center y
|
||||||
double cy = 0.0;
|
double cy = 0.0;
|
||||||
|
|
||||||
/// Constrained triangles
|
/// Constrained triangles
|
||||||
vector<Triangle*> triangles;
|
vector<Triangle*> triangles;
|
||||||
/// Triangle map
|
/// Triangle map
|
||||||
list<Triangle*> map;
|
list<Triangle*> map;
|
||||||
/// Polylines
|
/// Polylines
|
||||||
vector< vector<Point*> > polylines;
|
vector< vector<Point*> > polylines;
|
||||||
|
|
||||||
/// Draw the entire triangle map?
|
/// Draw the entire triangle map?
|
||||||
bool draw_map = false;
|
bool draw_map = false;
|
||||||
/// Create a random distribution of points?
|
/// Create a random distribution of points?
|
||||||
bool random_distribution = false;
|
bool random_distribution = false;
|
||||||
|
|
||||||
template <class C> void FreeClear( C & cntr ) {
|
template <class C> void FreeClear( C & cntr ) {
|
||||||
for ( typename C::iterator it = cntr.begin();
|
for ( typename C::iterator it = cntr.begin();
|
||||||
it != cntr.end(); ++it ) {
|
it != cntr.end(); ++it ) {
|
||||||
delete * it;
|
delete * it;
|
||||||
}
|
}
|
||||||
cntr.clear();
|
cntr.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
int num_points = 0;
|
int num_points = 0;
|
||||||
double max, min;
|
double max, min;
|
||||||
double zoom;
|
double zoom;
|
||||||
|
|
||||||
if (argc != 5) {
|
if (argc != 5) {
|
||||||
cout << "-== USAGE ==-" << endl;
|
cout << "-== USAGE ==-" << endl;
|
||||||
cout << "Load Data File: p2t filename center_x center_y zoom" << endl;
|
cout << "Load Data File: p2t filename center_x center_y zoom" << endl;
|
||||||
cout << "Example: ./build/p2t testbed/data/dude.dat 500 500 1" << endl;
|
cout << "Example: ./build/p2t testbed/data/dude.dat 500 500 1" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(string(argv[1]) == "random") {
|
if(string(argv[1]) == "random") {
|
||||||
num_points = atoi(argv[2]);
|
num_points = atoi(argv[2]);
|
||||||
random_distribution = true;
|
random_distribution = true;
|
||||||
char* pEnd;
|
char* pEnd;
|
||||||
max = strtod(argv[3], &pEnd);
|
max = strtod(argv[3], &pEnd);
|
||||||
min = -max;
|
min = -max;
|
||||||
cx = cy = 0;
|
cx = cy = 0;
|
||||||
zoom = atof(argv[4]);
|
zoom = atof(argv[4]);
|
||||||
} else {
|
} else {
|
||||||
zoom = atof(argv[4]);
|
zoom = atof(argv[4]);
|
||||||
cx = atof(argv[2]);
|
cx = atof(argv[2]);
|
||||||
cy = atof(argv[3]);
|
cy = atof(argv[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<p2t::Point*> polyline;
|
vector<p2t::Point*> polyline;
|
||||||
|
|
||||||
if(random_distribution) {
|
if(random_distribution) {
|
||||||
// Create a simple bounding box
|
// Create a simple bounding box
|
||||||
polyline.push_back(new Point(min,min));
|
polyline.push_back(new Point(min,min));
|
||||||
polyline.push_back(new Point(min,max));
|
polyline.push_back(new Point(min,max));
|
||||||
polyline.push_back(new Point(max,max));
|
polyline.push_back(new Point(max,max));
|
||||||
polyline.push_back(new Point(max,min));
|
polyline.push_back(new Point(max,min));
|
||||||
} else {
|
} else {
|
||||||
// Load pointset from file
|
// Load pointset from file
|
||||||
|
|
||||||
// Parse and tokenize data file
|
// Parse and tokenize data file
|
||||||
string line;
|
string line;
|
||||||
ifstream myfile(argv[1]);
|
ifstream myfile(argv[1]);
|
||||||
if (myfile.is_open()) {
|
if (myfile.is_open()) {
|
||||||
while (!myfile.eof()) {
|
while (!myfile.eof()) {
|
||||||
getline(myfile, line);
|
getline(myfile, line);
|
||||||
if (line.size() == 0) {
|
if (line.size() == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
istringstream iss(line);
|
istringstream iss(line);
|
||||||
vector<string> tokens;
|
vector<string> tokens;
|
||||||
copy(istream_iterator<string>(iss), istream_iterator<string>(),
|
copy(istream_iterator<string>(iss), istream_iterator<string>(),
|
||||||
back_inserter<vector<string> >(tokens));
|
back_inserter<vector<string> >(tokens));
|
||||||
double x = StringToDouble(tokens[0]);
|
double x = StringToDouble(tokens[0]);
|
||||||
double y = StringToDouble(tokens[1]);
|
double y = StringToDouble(tokens[1]);
|
||||||
polyline.push_back(new Point(x, y));
|
polyline.push_back(new Point(x, y));
|
||||||
num_points++;
|
num_points++;
|
||||||
}
|
}
|
||||||
myfile.close();
|
myfile.close();
|
||||||
} else {
|
} else {
|
||||||
cout << "File not opened" << endl;
|
cout << "File not opened" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Number of constrained edges = " << polyline.size() << endl;
|
cout << "Number of constrained edges = " << polyline.size() << endl;
|
||||||
polylines.push_back(polyline);
|
polylines.push_back(polyline);
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform triangulation!
|
* Perform triangulation!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
double init_time = glfwGetTime();
|
double init_time = glfwGetTime();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* STEP 1: Create CDT and add primary polyline
|
* STEP 1: Create CDT and add primary polyline
|
||||||
* NOTE: polyline must be a simple polygon. The polyline's points
|
* NOTE: polyline must be a simple polygon. The polyline's points
|
||||||
* constitute constrained edges. No repeat points!!!
|
* constitute constrained edges. No repeat points!!!
|
||||||
*/
|
*/
|
||||||
CDT* cdt = new CDT(polyline);
|
CDT* cdt = new CDT(polyline);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* STEP 2: Add holes or Steiner points if necessary
|
* STEP 2: Add holes or Steiner points if necessary
|
||||||
*/
|
*/
|
||||||
|
|
||||||
string s(argv[1]);
|
string s(argv[1]);
|
||||||
if(s.find("dude.dat", 0) != string::npos) {
|
if(s.find("dude.dat", 0) != string::npos) {
|
||||||
// Add head hole
|
// Add head hole
|
||||||
vector<Point*> head_hole = CreateHeadHole();
|
vector<Point*> head_hole = CreateHeadHole();
|
||||||
num_points += head_hole.size();
|
num_points += head_hole.size();
|
||||||
cdt->AddHole(head_hole);
|
cdt->AddHole(head_hole);
|
||||||
// Add chest hole
|
// Add chest hole
|
||||||
vector<Point*> chest_hole = CreateChestHole();
|
vector<Point*> chest_hole = CreateChestHole();
|
||||||
num_points += chest_hole.size();
|
num_points += chest_hole.size();
|
||||||
cdt->AddHole(chest_hole);
|
cdt->AddHole(chest_hole);
|
||||||
polylines.push_back(head_hole);
|
polylines.push_back(head_hole);
|
||||||
polylines.push_back(chest_hole);
|
polylines.push_back(chest_hole);
|
||||||
} else if (random_distribution) {
|
} else if (random_distribution) {
|
||||||
max-=(1e-4);
|
max-=(1e-4);
|
||||||
min+=(1e-4);
|
min+=(1e-4);
|
||||||
for(int i = 0; i < num_points; i++) {
|
for(int i = 0; i < num_points; i++) {
|
||||||
double x = Random(Fun, min, max);
|
double x = Random(Fun, min, max);
|
||||||
double y = Random(Fun, min, max);
|
double y = Random(Fun, min, max);
|
||||||
cdt->AddPoint(new Point(x, y));
|
cdt->AddPoint(new Point(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* STEP 3: Triangulate!
|
* STEP 3: Triangulate!
|
||||||
*/
|
*/
|
||||||
cdt->Triangulate();
|
cdt->Triangulate();
|
||||||
|
|
||||||
double dt = glfwGetTime() - init_time;
|
double dt = glfwGetTime() - init_time;
|
||||||
|
|
||||||
triangles = cdt->GetTriangles();
|
triangles = cdt->GetTriangles();
|
||||||
map = cdt->GetMap();
|
map = cdt->GetMap();
|
||||||
|
|
||||||
cout << "Number of points = " << num_points << endl;
|
cout << "Number of points = " << num_points << endl;
|
||||||
cout << "Number of triangles = " << triangles.size() << endl;
|
cout << "Number of triangles = " << triangles.size() << endl;
|
||||||
cout << "Elapsed time (ms) = " << dt*1000.0 << endl;
|
cout << "Elapsed time (ms) = " << dt*1000.0 << endl;
|
||||||
|
|
||||||
MainLoop(zoom);
|
MainLoop(zoom);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|
||||||
delete cdt;
|
delete cdt;
|
||||||
|
|
||||||
// Free points
|
// Free points
|
||||||
for(int i = 0; i < polylines.size(); i++) {
|
for(int i = 0; i < polylines.size(); i++) {
|
||||||
vector<Point*> poly = polylines[i];
|
vector<Point*> poly = polylines[i];
|
||||||
FreeClear(poly);
|
FreeClear(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShutDown(0);
|
ShutDown(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
const int window_width = 800,
|
const int window_width = 800,
|
||||||
window_height = 600;
|
window_height = 600;
|
||||||
|
|
||||||
if (glfwInit() != GL_TRUE)
|
if (glfwInit() != GL_TRUE)
|
||||||
ShutDown(1);
|
ShutDown(1);
|
||||||
// 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed
|
// 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed
|
||||||
if (glfwOpenWindow(window_width, window_height, 5, 6, 5, 0, 0, 0, GLFW_WINDOW) != GL_TRUE)
|
if (glfwOpenWindow(window_width, window_height, 5, 6, 5, 0, 0, 0, GLFW_WINDOW) != GL_TRUE)
|
||||||
ShutDown(1);
|
ShutDown(1);
|
||||||
|
|
||||||
glfwSetWindowTitle("Poly2Tri - C++");
|
glfwSetWindowTitle("Poly2Tri - C++");
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutDown(int return_code)
|
void ShutDown(int return_code)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(return_code);
|
exit(return_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainLoop(const double zoom)
|
void MainLoop(const double zoom)
|
||||||
{
|
{
|
||||||
// the time of the previous frame
|
// the time of the previous frame
|
||||||
double old_time = glfwGetTime();
|
double old_time = glfwGetTime();
|
||||||
// this just loops as long as the program runs
|
// this just loops as long as the program runs
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
// calculate time elapsed, and the amount by which stuff rotates
|
// calculate time elapsed, and the amount by which stuff rotates
|
||||||
double current_time = glfwGetTime(),
|
double current_time = glfwGetTime(),
|
||||||
delta_rotate = (current_time - old_time) * rotations_per_tick * 360;
|
delta_rotate = (current_time - old_time) * rotations_per_tick * 360;
|
||||||
old_time = current_time;
|
old_time = current_time;
|
||||||
|
|
||||||
// escape to quit, arrow keys to rotate view
|
// escape to quit, arrow keys to rotate view
|
||||||
// Check if ESC key was pressed or window was closed
|
// Check if ESC key was pressed or window was closed
|
||||||
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
|
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
|
||||||
|
|
||||||
if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
|
if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
|
||||||
rotate_y += delta_rotate;
|
rotate_y += delta_rotate;
|
||||||
if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS)
|
if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS)
|
||||||
rotate_y -= delta_rotate;
|
rotate_y -= delta_rotate;
|
||||||
// z axis always rotates
|
// z axis always rotates
|
||||||
rotate_z += delta_rotate;
|
rotate_z += delta_rotate;
|
||||||
|
|
||||||
// Draw the scene
|
// Draw the scene
|
||||||
if (draw_map) {
|
if (draw_map) {
|
||||||
DrawMap(zoom);
|
DrawMap(zoom);
|
||||||
} else {
|
} else {
|
||||||
Draw(zoom);
|
Draw(zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// swap back and front buffers
|
// swap back and front buffers
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetZoom(double zoom, double cx, double cy, double width, double height)
|
void ResetZoom(double zoom, double cx, double cy, double width, double height)
|
||||||
{
|
{
|
||||||
double left = -width / zoom;
|
double left = -width / zoom;
|
||||||
double right = width / zoom;
|
double right = width / zoom;
|
||||||
double bottom = -height / zoom;
|
double bottom = -height / zoom;
|
||||||
double top = height / zoom;
|
double top = height / zoom;
|
||||||
|
|
||||||
// Reset viewport
|
// Reset viewport
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
// Reset ortho view
|
// Reset ortho view
|
||||||
glOrtho(left, right, bottom, top, 1, -1);
|
glOrtho(left, right, bottom, top, 1, -1);
|
||||||
glTranslatef(-cx, -cy, 0);
|
glTranslatef(-cx, -cy, 0);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
// Clear the screen
|
// Clear the screen
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw(const double zoom)
|
void Draw(const double zoom)
|
||||||
{
|
{
|
||||||
// reset zoom
|
// reset zoom
|
||||||
Point center = Point(cx, cy);
|
Point center = Point(cx, cy);
|
||||||
|
|
||||||
ResetZoom(zoom, center.x, center.y, 800, 600);
|
ResetZoom(zoom, center.x, center.y, 800, 600);
|
||||||
|
|
||||||
for (int i = 0; i < triangles.size(); i++) {
|
for (int i = 0; i < triangles.size(); i++) {
|
||||||
Triangle& t = *triangles[i];
|
Triangle& t = *triangles[i];
|
||||||
Point& a = *t.GetPoint(0);
|
Point& a = *t.GetPoint(0);
|
||||||
Point& b = *t.GetPoint(1);
|
Point& b = *t.GetPoint(1);
|
||||||
Point& c = *t.GetPoint(2);
|
Point& c = *t.GetPoint(2);
|
||||||
|
|
||||||
// Red
|
// Red
|
||||||
glColor3f(1, 0, 0);
|
glColor3f(1, 0, 0);
|
||||||
|
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
glVertex2f(a.x, a.y);
|
glVertex2f(a.x, a.y);
|
||||||
glVertex2f(b.x, b.y);
|
glVertex2f(b.x, b.y);
|
||||||
glVertex2f(c.x, c.y);
|
glVertex2f(c.x, c.y);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
// green
|
// green
|
||||||
glColor3f(0, 1, 0);
|
glColor3f(0, 1, 0);
|
||||||
|
|
||||||
for(int i = 0; i < polylines.size(); i++) {
|
for(int i = 0; i < polylines.size(); i++) {
|
||||||
vector<Point*> poly = polylines[i];
|
vector<Point*> poly = polylines[i];
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
for(int j = 0; j < poly.size(); j++) {
|
for(int j = 0; j < poly.size(); j++) {
|
||||||
glVertex2f(poly[j]->x, poly[j]->y);
|
glVertex2f(poly[j]->x, poly[j]->y);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawMap(const double zoom)
|
void DrawMap(const double zoom)
|
||||||
{
|
{
|
||||||
// reset zoom
|
// reset zoom
|
||||||
Point center = Point(cx, cy);
|
Point center = Point(cx, cy);
|
||||||
|
|
||||||
ResetZoom(zoom, center.x, center.y, 800, 600);
|
ResetZoom(zoom, center.x, center.y, 800, 600);
|
||||||
|
|
||||||
list<Triangle*>::iterator it;
|
list<Triangle*>::iterator it;
|
||||||
for (it = map.begin(); it != map.end(); it++) {
|
for (it = map.begin(); it != map.end(); it++) {
|
||||||
Triangle& t = **it;
|
Triangle& t = **it;
|
||||||
Point& a = *t.GetPoint(0);
|
Point& a = *t.GetPoint(0);
|
||||||
Point& b = *t.GetPoint(1);
|
Point& b = *t.GetPoint(1);
|
||||||
Point& c = *t.GetPoint(2);
|
Point& c = *t.GetPoint(2);
|
||||||
|
|
||||||
ConstrainedColor(t.constrained_edge[2]);
|
ConstrainedColor(t.constrained_edge[2]);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex2f(a.x, a.y);
|
glVertex2f(a.x, a.y);
|
||||||
glVertex2f(b.x, b.y);
|
glVertex2f(b.x, b.y);
|
||||||
glEnd( );
|
glEnd( );
|
||||||
|
|
||||||
ConstrainedColor(t.constrained_edge[0]);
|
ConstrainedColor(t.constrained_edge[0]);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex2f(b.x, b.y);
|
glVertex2f(b.x, b.y);
|
||||||
glVertex2f(c.x, c.y);
|
glVertex2f(c.x, c.y);
|
||||||
glEnd( );
|
glEnd( );
|
||||||
|
|
||||||
ConstrainedColor(t.constrained_edge[1]);
|
ConstrainedColor(t.constrained_edge[1]);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex2f(c.x, c.y);
|
glVertex2f(c.x, c.y);
|
||||||
glVertex2f(a.x, a.y);
|
glVertex2f(a.x, a.y);
|
||||||
glEnd( );
|
glEnd( );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConstrainedColor(bool constrain)
|
void ConstrainedColor(bool constrain)
|
||||||
{
|
{
|
||||||
if (constrain) {
|
if (constrain) {
|
||||||
// Green
|
// Green
|
||||||
glColor3f(0, 1, 0);
|
glColor3f(0, 1, 0);
|
||||||
} else {
|
} else {
|
||||||
// Red
|
// Red
|
||||||
glColor3f(1, 0, 0);
|
glColor3f(1, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Point*> CreateHeadHole() {
|
vector<Point*> CreateHeadHole() {
|
||||||
|
|
||||||
vector<Point*> head_hole;
|
vector<Point*> head_hole;
|
||||||
head_hole.push_back(new Point(325, 437));
|
head_hole.push_back(new Point(325, 437));
|
||||||
head_hole.push_back(new Point(320, 423));
|
head_hole.push_back(new Point(320, 423));
|
||||||
head_hole.push_back(new Point(329, 413));
|
head_hole.push_back(new Point(329, 413));
|
||||||
head_hole.push_back(new Point(332, 423));
|
head_hole.push_back(new Point(332, 423));
|
||||||
|
|
||||||
return head_hole;
|
return head_hole;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Point*> CreateChestHole() {
|
vector<Point*> CreateChestHole() {
|
||||||
|
|
||||||
vector<Point*> chest_hole;
|
vector<Point*> chest_hole;
|
||||||
chest_hole.push_back(new Point(320.72342,480));
|
chest_hole.push_back(new Point(320.72342,480));
|
||||||
chest_hole.push_back(new Point(338.90617,465.96863));
|
chest_hole.push_back(new Point(338.90617,465.96863));
|
||||||
chest_hole.push_back(new Point(347.99754,480.61584));
|
chest_hole.push_back(new Point(347.99754,480.61584));
|
||||||
chest_hole.push_back(new Point(329.8148,510.41534));
|
chest_hole.push_back(new Point(329.8148,510.41534));
|
||||||
chest_hole.push_back(new Point(339.91632,480.11077));
|
chest_hole.push_back(new Point(339.91632,480.11077));
|
||||||
chest_hole.push_back(new Point(334.86556,478.09046));
|
chest_hole.push_back(new Point(334.86556,478.09046));
|
||||||
|
|
||||||
return chest_hole;
|
return chest_hole;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double StringToDouble(const std::string& s)
|
double StringToDouble(const std::string& s)
|
||||||
{
|
{
|
||||||
std::istringstream i(s);
|
std::istringstream i(s);
|
||||||
double x;
|
double x;
|
||||||
if (!(i >> x))
|
if (!(i >> x))
|
||||||
return 0;
|
return 0;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Fun(double x)
|
double Fun(double x)
|
||||||
{
|
{
|
||||||
return 2.5 + sin(10 * x) / x;
|
return 2.5 + sin(10 * x) / x;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Random(double (*fun)(double), double xmin = 0, double xmax = 1)
|
double Random(double (*fun)(double), double xmin = 0, double xmax = 1)
|
||||||
{
|
{
|
||||||
static double (*Fun)(double) = NULL, YMin, YMax;
|
static double (*Fun)(double) = NULL, YMin, YMax;
|
||||||
static bool First = true;
|
static bool First = true;
|
||||||
|
|
||||||
// Initialises random generator for first call
|
// Initialises random generator for first call
|
||||||
if (First)
|
if (First)
|
||||||
{
|
{
|
||||||
First = false;
|
First = false;
|
||||||
srand((unsigned) time(NULL));
|
srand((unsigned) time(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluates maximum of function
|
// Evaluates maximum of function
|
||||||
if (fun != Fun)
|
if (fun != Fun)
|
||||||
{
|
{
|
||||||
Fun = fun;
|
Fun = fun;
|
||||||
YMin = 0, YMax = Fun(xmin);
|
YMin = 0, YMax = Fun(xmin);
|
||||||
for (int iX = 1; iX < RAND_MAX; iX++)
|
for (int iX = 1; iX < RAND_MAX; iX++)
|
||||||
{
|
{
|
||||||
double X = xmin + (xmax - xmin) * iX / RAND_MAX;
|
double X = xmin + (xmax - xmin) * iX / RAND_MAX;
|
||||||
double Y = Fun(X);
|
double Y = Fun(X);
|
||||||
YMax = Y > YMax ? Y : YMax;
|
YMax = Y > YMax ? Y : YMax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets random values for X & Y
|
// Gets random values for X & Y
|
||||||
double X = xmin + (xmax - xmin) * rand() / RAND_MAX;
|
double X = xmin + (xmax - xmin) * rand() / RAND_MAX;
|
||||||
double Y = YMin + (YMax - YMin) * rand() / RAND_MAX;
|
double Y = YMin + (YMax - YMin) * rand() / RAND_MAX;
|
||||||
|
|
||||||
// Returns if valid and try again if not valid
|
// Returns if valid and try again if not valid
|
||||||
return Y < fun(X) ? X : Random(Fun, xmin, xmax);
|
return Y < fun(X) ? X : Random(Fun, xmin, xmax);
|
||||||
}
|
}
|
94
wscript
94
wscript
@ -1,47 +1,47 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
# waf 1.6.10
|
# waf 1.6.10
|
||||||
|
|
||||||
VERSION='0.3.3'
|
VERSION='0.3.3'
|
||||||
import sys
|
import sys
|
||||||
APPNAME='p2t'
|
APPNAME='p2t'
|
||||||
top = '.'
|
top = '.'
|
||||||
out = 'build'
|
out = 'build'
|
||||||
|
|
||||||
CPP_SOURCES = ['poly2tri/common/shapes.cc',
|
CPP_SOURCES = ['poly2tri/common/shapes.cc',
|
||||||
'poly2tri/sweep/cdt.cc',
|
'poly2tri/sweep/cdt.cc',
|
||||||
'poly2tri/sweep/advancing_front.cc',
|
'poly2tri/sweep/advancing_front.cc',
|
||||||
'poly2tri/sweep/sweep_context.cc',
|
'poly2tri/sweep/sweep_context.cc',
|
||||||
'poly2tri/sweep/sweep.cc',
|
'poly2tri/sweep/sweep.cc',
|
||||||
'testbed/main.cc']
|
'testbed/main.cc']
|
||||||
|
|
||||||
from waflib.Tools.compiler_cxx import cxx_compiler
|
from waflib.Tools.compiler_cxx import cxx_compiler
|
||||||
cxx_compiler['win32'] = ['g++']
|
cxx_compiler['win32'] = ['g++']
|
||||||
|
|
||||||
#Platform specific libs
|
#Platform specific libs
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
# MS Windows
|
# MS Windows
|
||||||
sys_libs = ['glfw', 'opengl32']
|
sys_libs = ['glfw', 'opengl32']
|
||||||
elif sys.platform == 'darwin':
|
elif sys.platform == 'darwin':
|
||||||
# Apple OSX
|
# Apple OSX
|
||||||
sys_libs = ['glfw']
|
sys_libs = ['glfw']
|
||||||
else:
|
else:
|
||||||
# GNU/Linux, BSD, etc
|
# GNU/Linux, BSD, etc
|
||||||
sys_libs = ['glfw', 'GL']
|
sys_libs = ['glfw', 'GL']
|
||||||
|
|
||||||
def options(opt):
|
def options(opt):
|
||||||
print(' set_options')
|
print(' set_options')
|
||||||
opt.load('compiler_cxx')
|
opt.load('compiler_cxx')
|
||||||
|
|
||||||
def configure(conf):
|
def configure(conf):
|
||||||
print(' calling the configuration')
|
print(' calling the configuration')
|
||||||
conf.load('compiler_cxx')
|
conf.load('compiler_cxx')
|
||||||
conf.env.CXXFLAGS = ['-O3', '-ffast-math']
|
conf.env.CXXFLAGS = ['-O3', '-ffast-math']
|
||||||
conf.env.DEFINES_P2T = ['P2T']
|
conf.env.DEFINES_P2T = ['P2T']
|
||||||
conf.env.LIB_P2T = sys_libs
|
conf.env.LIB_P2T = sys_libs
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
conf.env.FRAMEWORK = ['OpenGL', 'Cocoa']
|
conf.env.FRAMEWORK = ['OpenGL', 'Cocoa']
|
||||||
|
|
||||||
def build(bld):
|
def build(bld):
|
||||||
print(' building')
|
print(' building')
|
||||||
bld.program(features = 'cxx cxxprogram', source=CPP_SOURCES, target = 'p2t', uselib = 'P2T')
|
bld.program(features = 'cxx cxxprogram', source=CPP_SOURCES, target = 'p2t', uselib = 'P2T')
|
Loading…
Reference in New Issue
Block a user