mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-12-02 02:03:30 +01:00
added p2t namespace
This commit is contained in:
parent
793760887b
commit
5dbe785975
@ -31,6 +31,8 @@
|
|||||||
#include "shapes.h"
|
#include "shapes.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
Triangle::Triangle(Point& a, Point& b, Point& c)
|
Triangle::Triangle(Point& a, Point& b, Point& c)
|
||||||
{
|
{
|
||||||
points_[0] = &a; points_[1] = &b; points_[2] = &c;
|
points_[0] = &a; points_[1] = &b; points_[2] = &c;
|
||||||
@ -328,5 +330,5 @@ void Triangle::DebugPrint()
|
|||||||
cout << points_[2]->x << "," << points_[2]->y << endl;
|
cout << points_[2]->x << "," << points_[2]->y << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
struct Node;
|
struct Node;
|
||||||
struct Edge;
|
struct Edge;
|
||||||
|
|
||||||
@ -312,5 +314,8 @@ inline void Triangle::IsInterior(bool b)
|
|||||||
interior_ = b;
|
interior_ = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,17 +29,10 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef UTILS_H
|
|
||||||
#define UTILS_H
|
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
template<typename T, int size>
|
namespace p2t {
|
||||||
int array_length(T(&)[size])
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
const double PI_3div4 = 3 * M_PI / 4;
|
const double PI_3div4 = 3 * M_PI / 4;
|
||||||
const double EPSILON = 1e-12;
|
const double EPSILON = 1e-12;
|
||||||
@ -100,5 +93,5 @@ bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
@ -30,3 +30,4 @@
|
|||||||
*/
|
*/
|
||||||
#include "common/shapes.h"
|
#include "common/shapes.h"
|
||||||
#include "sweep/cdt.h"
|
#include "sweep/cdt.h"
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "advancing_front.h"
|
#include "advancing_front.h"
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
AdvancingFront::AdvancingFront(Node& head, Node& tail)
|
AdvancingFront::AdvancingFront(Node& head, Node& tail)
|
||||||
{
|
{
|
||||||
head_ = &head;
|
head_ = &head;
|
||||||
@ -104,3 +106,6 @@ AdvancingFront::~AdvancingFront()
|
|||||||
delete search_node_;
|
delete search_node_;
|
||||||
delete tail_;
|
delete tail_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "../common/shapes.h"
|
#include "../common/shapes.h"
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
struct Node;
|
struct Node;
|
||||||
|
|
||||||
// Advancing front node
|
// Advancing front node
|
||||||
@ -108,3 +110,5 @@ inline void AdvancingFront::set_search(Node* node)
|
|||||||
search_node_ = node;
|
search_node_ = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "cdt.h"
|
#include "cdt.h"
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
CDT::CDT(Point** polyline, const int& point_count)
|
CDT::CDT(Point** polyline, const int& point_count)
|
||||||
{
|
{
|
||||||
sweep_context_ = new SweepContext(polyline, point_count);
|
sweep_context_ = new SweepContext(polyline, point_count);
|
||||||
@ -45,12 +47,12 @@ void CDT::Triangulate()
|
|||||||
sweep_->Triangulate(*sweep_context_);
|
sweep_->Triangulate(*sweep_context_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Triangle*> CDT::GetTriangles()
|
std::vector<p2t::Triangle*> CDT::GetTriangles()
|
||||||
{
|
{
|
||||||
return sweep_context_->GetTriangles();
|
return sweep_context_->GetTriangles();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Triangle*> CDT::GetMap()
|
std::list<p2t::Triangle*> CDT::GetMap()
|
||||||
{
|
{
|
||||||
return sweep_context_->GetMap();
|
return sweep_context_->GetMap();
|
||||||
}
|
}
|
||||||
@ -61,3 +63,5 @@ CDT::~CDT()
|
|||||||
delete sweep_;
|
delete sweep_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include "sweep_context.h"
|
#include "sweep_context.h"
|
||||||
#include "sweep.h"
|
#include "sweep.h"
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
class CDT
|
class CDT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -55,3 +57,5 @@ Sweep* sweep_;
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~CDT();
|
~CDT();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
#include "advancing_front.h"
|
#include "advancing_front.h"
|
||||||
#include "../common/utils.h"
|
#include "../common/utils.h"
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
// Triangulate simple polygon with holes
|
// Triangulate simple polygon with holes
|
||||||
void Sweep::Triangulate(SweepContext& tcx)
|
void Sweep::Triangulate(SweepContext& tcx)
|
||||||
{
|
{
|
||||||
@ -801,4 +803,5 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sweep-line, Constrained Delauney Triangulation (CDT) See: Domiter, V. and
|
* Sweep-line, Constrained Delauney Triangulation (CDT) See: Domiter, V. and
|
||||||
* Zalik, B.(2008)'Sweep-line algorithm for constrained Delaunay triangulation',
|
* Zalik, B.(2008)'Sweep-line algorithm for constrained Delaunay triangulation',
|
||||||
@ -37,6 +36,8 @@
|
|||||||
* "FlipScan" Constrained Edge Algorithm invented by Thomas Åhlén, thahlen@gmail.com
|
* "FlipScan" Constrained Edge Algorithm invented by Thomas Åhlén, thahlen@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
class SweepContext;
|
class SweepContext;
|
||||||
struct Node;
|
struct Node;
|
||||||
struct Point;
|
struct Point;
|
||||||
@ -110,3 +111,5 @@ void FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_t
|
|||||||
|
|
||||||
void FinalizationPolygon(SweepContext& tcx);
|
void FinalizationPolygon(SweepContext& tcx);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
#include <GL/glfw.h>
|
#include <GL/glfw.h>
|
||||||
#include "advancing_front.h"
|
#include "advancing_front.h"
|
||||||
|
|
||||||
|
namespace p2t {
|
||||||
|
|
||||||
SweepContext::SweepContext(Point** polyline, const int& point_count)
|
SweepContext::SweepContext(Point** polyline, const int& point_count)
|
||||||
{
|
{
|
||||||
basin = Basin();
|
basin = Basin();
|
||||||
@ -168,3 +170,5 @@ SweepContext::~SweepContext()
|
|||||||
delete tail_;
|
delete tail_;
|
||||||
delete front_;
|
delete front_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
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;
|
||||||
@ -41,7 +43,6 @@ struct Node;
|
|||||||
struct Edge;
|
struct Edge;
|
||||||
class AdvancingFront;
|
class AdvancingFront;
|
||||||
|
|
||||||
|
|
||||||
class SweepContext {
|
class SweepContext {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -166,3 +167,5 @@ inline Point* SweepContext::tail()
|
|||||||
{
|
{
|
||||||
return tail_;
|
return tail_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "../poly2tri/poly2tri.h"
|
#include "../poly2tri/poly2tri.h"
|
||||||
|
using namespace p2t;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void ShutDown(int return_code);
|
void ShutDown(int return_code);
|
||||||
@ -76,6 +76,7 @@ bool draw_map = false;
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
if (argc != 5) {
|
if (argc != 5) {
|
||||||
cout << "Usage: p2t filename centerX centerY zoom" << endl;
|
cout << "Usage: p2t filename centerX centerY zoom" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -101,7 +102,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
string line;
|
string line;
|
||||||
ifstream myfile(argv[1]);
|
ifstream myfile(argv[1]);
|
||||||
vector<Point*> points;
|
vector<p2t::Point*> points;
|
||||||
if (myfile.is_open()) {
|
if (myfile.is_open()) {
|
||||||
while (!myfile.eof()) {
|
while (!myfile.eof()) {
|
||||||
getline(myfile, line);
|
getline(myfile, line);
|
||||||
|
Loading…
Reference in New Issue
Block a user