mirror of
https://github.com/jhasse/poly2tri.git
synced 2025-08-14 03:05:39 +02:00
uncrustified code
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Poly2Tri Copyright (c) 2009-2010, Mason Green
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
@@ -30,75 +30,78 @@
|
||||
*/
|
||||
#include "advancing_front.h"
|
||||
|
||||
AdvancingFront::AdvancingFront() {
|
||||
AdvancingFront::AdvancingFront()
|
||||
{
|
||||
head_ = tail_ = search_node_ = NULL;
|
||||
}
|
||||
|
||||
Node* AdvancingFront::Locate(const double& x) {
|
||||
|
||||
Node* node = search_node_;
|
||||
Node* AdvancingFront::Locate(const double& x)
|
||||
{
|
||||
Node* node = search_node_;
|
||||
|
||||
if(x < node->value) {
|
||||
if (x < node->value) {
|
||||
//printf("<: - %f,%f - %p\n", x, node->value, node->next);
|
||||
while((node = node->prev) != NULL) {
|
||||
if(x >= node->value) {
|
||||
while ((node = node->prev) != NULL) {
|
||||
if (x >= node->value) {
|
||||
search_node_ = node;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//printf("%p - %p\n", node, node->next);
|
||||
//printf(">: %f - %f\n", x, node->value);
|
||||
while((node = node->next) != NULL) {
|
||||
if(x < node->value) {
|
||||
while ((node = node->next) != NULL) {
|
||||
if (x < node->value) {
|
||||
search_node_ = node->prev;
|
||||
return node->prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* AdvancingFront::FindSearchNode(const double& x) {
|
||||
// TODO: implement BST index
|
||||
return search_node_;
|
||||
Node* AdvancingFront::FindSearchNode(const double& x)
|
||||
{
|
||||
// TODO: implement BST index
|
||||
return search_node_;
|
||||
}
|
||||
|
||||
Node* AdvancingFront::LocatePoint(Point* point) {
|
||||
|
||||
const double px = point->x;
|
||||
Node* node = FindSearchNode(px);
|
||||
const double nx = node->point->x;
|
||||
|
||||
if(px == nx) {
|
||||
if(point != node->point) {
|
||||
// We might have two nodes with same x value for a short time
|
||||
if(point == node->prev->point) {
|
||||
node = node->prev;
|
||||
} else if(point == node->next->point) {
|
||||
node = node->next;
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
} else if(px < nx) {
|
||||
while((node = node->prev) != NULL) {
|
||||
if(point == node->point) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while((node = node->next) != NULL) {
|
||||
if(point == node->point)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(node) search_node_ = node;
|
||||
return node;
|
||||
Node* AdvancingFront::LocatePoint(Point* point)
|
||||
{
|
||||
const double px = point->x;
|
||||
Node* node = FindSearchNode(px);
|
||||
const double nx = node->point->x;
|
||||
|
||||
if (px == nx) {
|
||||
if (point != node->point) {
|
||||
// We might have two nodes with same x value for a short time
|
||||
if (point == node->prev->point) {
|
||||
node = node->prev;
|
||||
} else if (point == node->next->point) {
|
||||
node = node->next;
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
} else if (px < nx) {
|
||||
while ((node = node->prev) != NULL) {
|
||||
if (point == node->point) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while ((node = node->next) != NULL) {
|
||||
if (point == node->point)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (node) search_node_ = node;
|
||||
return node;
|
||||
}
|
||||
|
||||
AdvancingFront::~AdvancingFront() {
|
||||
delete head_;
|
||||
delete search_node_;
|
||||
|
||||
AdvancingFront::~AdvancingFront()
|
||||
{
|
||||
delete head_;
|
||||
delete search_node_;
|
||||
delete tail_;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Poly2Tri Copyright (c) 2009-2010, Mason Green
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
@@ -34,66 +34,84 @@ struct Node;
|
||||
|
||||
// Advancing front node
|
||||
struct Node {
|
||||
|
||||
Point* point;
|
||||
Triangle* triangle;
|
||||
|
||||
|
||||
Node* next;
|
||||
Node* prev;
|
||||
|
||||
double value;
|
||||
|
||||
Node(Point& p) : point(&p), triangle(NULL), value(p.x), next(NULL), prev(NULL) {}
|
||||
|
||||
Node(Point& p, Triangle& t) : point(&p), triangle(&t), value(p.x),
|
||||
next(NULL), prev(NULL) {}
|
||||
|
||||
/*
|
||||
~Node() {
|
||||
printf("going... ");
|
||||
printf("bye node");
|
||||
printf(" ... gone!\n");
|
||||
double value;
|
||||
|
||||
Node(Point& p) : point(&p), triangle(NULL), value(p.x), next(NULL), prev(NULL)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
Node(Point& p, Triangle& t) : point(&p), triangle(&t), value(p.x),
|
||||
next(NULL), prev(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
~Node() {
|
||||
printf("going... ");
|
||||
printf("bye node");
|
||||
printf(" ... gone!\n");
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
// Advancing front
|
||||
class AdvancingFront {
|
||||
|
||||
public:
|
||||
|
||||
AdvancingFront();
|
||||
// Destructor
|
||||
~AdvancingFront();
|
||||
|
||||
Node* head();
|
||||
void set_head(Node* node);
|
||||
Node* tail();
|
||||
void set_tail(Node* node);
|
||||
Node* search();
|
||||
void set_search(Node* node);
|
||||
|
||||
/// Locate insertion point along advancing front
|
||||
Node* Locate(const double& x);
|
||||
|
||||
Node* LocatePoint(Point* point);
|
||||
|
||||
AdvancingFront();
|
||||
// Destructor
|
||||
~AdvancingFront();
|
||||
|
||||
Node* head();
|
||||
void set_head(Node* node);
|
||||
Node* tail();
|
||||
void set_tail(Node* node);
|
||||
Node* search();
|
||||
void set_search(Node* node);
|
||||
|
||||
/// Locate insertion point along advancing front
|
||||
Node* Locate(const double& x);
|
||||
|
||||
Node* LocatePoint(Point* point);
|
||||
|
||||
private:
|
||||
|
||||
Node* head_, *tail_, *search_node_;
|
||||
|
||||
Node* FindSearchNode(const double& x);
|
||||
|
||||
|
||||
Node* head_, *tail_, *search_node_;
|
||||
|
||||
Node* FindSearchNode(const double& x);
|
||||
};
|
||||
|
||||
inline Node* AdvancingFront::head() { return head_; }
|
||||
inline void AdvancingFront::set_head(Node* node) { head_ = node; }
|
||||
inline Node* AdvancingFront::head()
|
||||
{
|
||||
return head_;
|
||||
}
|
||||
inline void AdvancingFront::set_head(Node* node)
|
||||
{
|
||||
head_ = node;
|
||||
}
|
||||
|
||||
inline Node* AdvancingFront::tail() { return tail_; }
|
||||
inline void AdvancingFront::set_tail(Node* node) { tail_ = node; }
|
||||
inline Node* AdvancingFront::tail()
|
||||
{
|
||||
return tail_;
|
||||
}
|
||||
inline void AdvancingFront::set_tail(Node* node)
|
||||
{
|
||||
tail_ = node;
|
||||
}
|
||||
|
||||
inline Node* AdvancingFront::search() { return search_node_; }
|
||||
inline Node* AdvancingFront::search()
|
||||
{
|
||||
return search_node_;
|
||||
}
|
||||
|
||||
inline void AdvancingFront::set_search(Node* node) { search_node_ = node; }
|
||||
inline void AdvancingFront::set_search(Node* node)
|
||||
{
|
||||
search_node_ = node;
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Poly2Tri Copyright (c) 2009-2010, Mason Green
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
@@ -30,29 +30,34 @@
|
||||
*/
|
||||
#include "cdt.h"
|
||||
|
||||
CDT::CDT(Point** polyline, const int& point_count) {
|
||||
sweep_context_ = new SweepContext(polyline, point_count);
|
||||
sweep_ = new Sweep;
|
||||
CDT::CDT(Point** polyline, const int& point_count)
|
||||
{
|
||||
sweep_context_ = new SweepContext(polyline, point_count);
|
||||
sweep_ = new Sweep;
|
||||
}
|
||||
|
||||
void CDT::AddHole(const Point poly_line[], const int point_count) {
|
||||
|
||||
void CDT::AddHole(const Point poly_line[], const int point_count)
|
||||
{
|
||||
}
|
||||
|
||||
void CDT::Triangulate() {
|
||||
sweep_->Triangulate(*sweep_context_);
|
||||
void CDT::Triangulate()
|
||||
{
|
||||
sweep_->Triangulate(*sweep_context_);
|
||||
}
|
||||
|
||||
std::vector<Triangle*> CDT::GetTriangles() {
|
||||
std::vector<Triangle*> CDT::GetTriangles()
|
||||
{
|
||||
return sweep_context_->GetTriangles();
|
||||
}
|
||||
|
||||
std::list<Triangle*> CDT::GetMap() {
|
||||
std::list<Triangle*> CDT::GetMap()
|
||||
{
|
||||
return sweep_context_->GetMap();
|
||||
}
|
||||
|
||||
CDT::~CDT() {
|
||||
delete sweep_context_;
|
||||
delete sweep_;
|
||||
CDT::~CDT()
|
||||
{
|
||||
delete sweep_context_;
|
||||
delete sweep_;
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Poly2Tri Copyright (c) 2009-2010, Mason Green
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
@@ -33,28 +33,26 @@
|
||||
#include "sweep_context.h"
|
||||
#include "sweep.h"
|
||||
|
||||
class CDT
|
||||
class CDT
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/// Constructor
|
||||
CDT(Point** poly_line, const int& point_count);
|
||||
/// Add a hole
|
||||
void AddHole(const Point poly_line[], const int point_count);
|
||||
/// Triangulate points
|
||||
void Triangulate();
|
||||
/// Get Delaunay triangles
|
||||
std::vector<Triangle*> GetTriangles();
|
||||
/// Get triangle map
|
||||
std::list<Triangle*> CDT::GetMap();
|
||||
|
||||
/// Constructor
|
||||
CDT(Point** poly_line, const int& point_count);
|
||||
/// Add a hole
|
||||
void AddHole(const Point poly_line[], const int point_count);
|
||||
/// Triangulate points
|
||||
void Triangulate();
|
||||
/// Get Delaunay triangles
|
||||
std::vector<Triangle*> GetTriangles();
|
||||
/// Get triangle map
|
||||
std::list<Triangle*> CDT::GetMap();
|
||||
|
||||
private:
|
||||
|
||||
SweepContext* sweep_context_;
|
||||
Sweep* sweep_;
|
||||
|
||||
/// Destructor
|
||||
~CDT();
|
||||
|
||||
SweepContext* sweep_context_;
|
||||
Sweep* sweep_;
|
||||
|
||||
/// Destructor
|
||||
~CDT();
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Poly2Tri Copyright (c) 2009-2010, Mason Green
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
@@ -34,16 +34,16 @@
|
||||
// Excludes exterior triangles outside constrained edges
|
||||
// Depth first search
|
||||
|
||||
void Mesh::clean(Triangle& triangle)
|
||||
void Mesh::clean(Triangle& triangle)
|
||||
{
|
||||
/*
|
||||
if(triangle != NULL && !triangle.interior)
|
||||
{
|
||||
triangle.interior = true;
|
||||
triangles += triangle;
|
||||
for(i <- 0 until 3)
|
||||
if(!triangle.edges(i))
|
||||
clean(triangle.neighbors(i));
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if(triangle != NULL && !triangle.interior)
|
||||
{
|
||||
triangle.interior = true;
|
||||
triangles += triangle;
|
||||
for(i <- 0 until 3)
|
||||
if(!triangle.edges(i))
|
||||
clean(triangle.neighbors(i));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Poly2Tri Copyright (c) 2009-2010, Mason Green
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
@@ -33,18 +33,16 @@ using namespace std;
|
||||
|
||||
class Triangle;
|
||||
|
||||
class Mesh
|
||||
class Mesh
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/// Triangles that constitute the mesh
|
||||
vector<Triangle> map;
|
||||
|
||||
// Debug triangles
|
||||
//val debug = new ArrayBuffer[Triangle]
|
||||
//val triangles = new ArrayBuffer[Triangle]
|
||||
|
||||
void clean(Triangle& triangle);
|
||||
|
||||
|
||||
/// Triangles that constitute the mesh
|
||||
vector<Triangle> map;
|
||||
|
||||
// Debug triangles
|
||||
//val debug = new ArrayBuffer[Triangle]
|
||||
//val triangles = new ArrayBuffer[Triangle]
|
||||
|
||||
void clean(Triangle& triangle);
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Poly2Tri Copyright (c) 2009-2010, Mason Green
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
@@ -33,8 +33,8 @@
|
||||
* Sweep-line, Constrained Delauney Triangulation (CDT) See: Domiter, V. and
|
||||
* Zalik, B.(2008)'Sweep-line algorithm for constrained Delaunay triangulation',
|
||||
* International Journal of Geographical Information Science
|
||||
*
|
||||
* "FlipScan" Constrained Edge Algorithm invented by Thomas <20>hl<68>n, thahlen@gmail.com
|
||||
*
|
||||
* "FlipScan" Constrained Edge Algorithm invented by Thomas <20>hl<68>n, thahlen@gmail.com
|
||||
*/
|
||||
|
||||
class SweepContext;
|
||||
@@ -44,71 +44,69 @@ struct Edge;
|
||||
class Triangle;
|
||||
|
||||
class Sweep {
|
||||
|
||||
public:
|
||||
|
||||
void Triangulate(SweepContext& tcx);
|
||||
void Triangulate(SweepContext& tcx);
|
||||
|
||||
private:
|
||||
|
||||
void SweepPoints(SweepContext& tcx);
|
||||
|
||||
Node& PointEvent(SweepContext& tcx, Point& point);
|
||||
|
||||
void EdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point);
|
||||
|
||||
Node& NewFrontTriangle(SweepContext& tcx, Point& point, Node& node);
|
||||
|
||||
void Fill(SweepContext& tcx, Node& node);
|
||||
|
||||
bool Legalize(SweepContext& tcx, Triangle& t);
|
||||
|
||||
bool Incircle(Point& pa, Point& pb, Point& pc, Point& pd);
|
||||
void SweepPoints(SweepContext& tcx);
|
||||
|
||||
void RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op);
|
||||
|
||||
void FillAdvancingFront(SweepContext& tcx, Node& n);
|
||||
|
||||
double HoleAngle(Node& node);
|
||||
|
||||
double BasinAngle(Node& node);
|
||||
|
||||
void FillBasin(SweepContext& tcx, Node& node);
|
||||
|
||||
void FillBasinReq(SweepContext& tcx, Node& node);
|
||||
|
||||
bool IsShallow(SweepContext& tcx, Node& node);
|
||||
|
||||
bool IsEdgeSideOfTriangle(Triangle& triangle, Point& ep, Point& eq);
|
||||
|
||||
void FillEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillRightAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
Node& PointEvent(SweepContext& tcx, Point& point);
|
||||
|
||||
void FillRightBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
void EdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
void EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point);
|
||||
|
||||
void FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillLeftAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
Node& NewFrontTriangle(SweepContext& tcx, Point& point, Node& node);
|
||||
|
||||
void FillLeftBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
void Fill(SweepContext& tcx, Node& node);
|
||||
|
||||
void FillLeftConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
bool Legalize(SweepContext& tcx, Triangle& t);
|
||||
|
||||
void FillLeftConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& t, Point& p);
|
||||
|
||||
Triangle& NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op);
|
||||
|
||||
Point& NextFlipPoint(Point& ep, Point& eq, Triangle& ot, Point& op );
|
||||
|
||||
void FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_triangle, Triangle& t, Point& p);
|
||||
bool Incircle(Point& pa, Point& pb, Point& pc, Point& pd);
|
||||
|
||||
void FinalizationPolygon(SweepContext& tcx);
|
||||
void RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op);
|
||||
|
||||
void FillAdvancingFront(SweepContext& tcx, Node& n);
|
||||
|
||||
double HoleAngle(Node& node);
|
||||
|
||||
double BasinAngle(Node& node);
|
||||
|
||||
void FillBasin(SweepContext& tcx, Node& node);
|
||||
|
||||
void FillBasinReq(SweepContext& tcx, Node& node);
|
||||
|
||||
bool IsShallow(SweepContext& tcx, Node& node);
|
||||
|
||||
bool IsEdgeSideOfTriangle(Triangle& triangle, Point& ep, Point& eq);
|
||||
|
||||
void FillEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillRightAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillRightBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillLeftAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillLeftBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillLeftConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FillLeftConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
|
||||
|
||||
void FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& t, Point& p);
|
||||
|
||||
Triangle& NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op);
|
||||
|
||||
Point& NextFlipPoint(Point& ep, Point& eq, Triangle& ot, Point& op);
|
||||
|
||||
void FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_triangle, Triangle& t, Point& p);
|
||||
|
||||
void FinalizationPolygon(SweepContext& tcx);
|
||||
};
|
||||
|
@@ -4,157 +4,162 @@
|
||||
#include <GL/glfw.h>
|
||||
#include "advancing_front.h"
|
||||
|
||||
SweepContext::SweepContext(Point** polyline, const int& point_count) {
|
||||
|
||||
SweepContext::SweepContext(Point** polyline, const int& point_count)
|
||||
{
|
||||
basin = Basin();
|
||||
edge_event = EdgeEvent();
|
||||
|
||||
|
||||
points_ = polyline;
|
||||
point_count_ = point_count;
|
||||
|
||||
|
||||
InitEdges(points_, point_count_);
|
||||
InitTriangulation();
|
||||
|
||||
}
|
||||
|
||||
std::vector<Triangle*> SweepContext::GetTriangles() {
|
||||
std::vector<Triangle*> SweepContext::GetTriangles()
|
||||
{
|
||||
return triangles_;
|
||||
}
|
||||
|
||||
std::list<Triangle*> SweepContext::GetMap() {
|
||||
std::list<Triangle*> SweepContext::GetMap()
|
||||
{
|
||||
return map_;
|
||||
}
|
||||
|
||||
void SweepContext::InitTriangulation() {
|
||||
|
||||
void SweepContext::InitTriangulation()
|
||||
{
|
||||
double xmax(points_[0]->x), xmin(points_[0]->x);
|
||||
double ymax(points_[0]->y), ymin(points_[0]->y);
|
||||
|
||||
// Calculate bounds.
|
||||
for(int i = 0; i < point_count_; i++) {
|
||||
|
||||
// Calculate bounds.
|
||||
for (int i = 0; i < point_count_; i++) {
|
||||
Point p = *points_[i];
|
||||
if(p.x > xmax)
|
||||
xmax = p.x;
|
||||
if(p.x < xmin)
|
||||
xmin = p.x;
|
||||
if(p.y > ymax)
|
||||
ymax = p.y;
|
||||
if(p.y < ymin)
|
||||
ymin = p.y;
|
||||
if (p.x > xmax)
|
||||
xmax = p.x;
|
||||
if (p.x < xmin)
|
||||
xmin = p.x;
|
||||
if (p.y > ymax)
|
||||
ymax = p.y;
|
||||
if (p.y < ymin)
|
||||
ymin = p.y;
|
||||
}
|
||||
|
||||
double dx = kAlpha * ( xmax - xmin );
|
||||
double dy = kAlpha * ( ymax - ymin );
|
||||
double dx = kAlpha * (xmax - xmin);
|
||||
double dy = kAlpha * (ymax - ymin);
|
||||
head_ = new Point(xmax + dx, ymin - dy);
|
||||
tail_ = new Point(xmin - dx, ymin - dy);
|
||||
|
||||
|
||||
// Sort points along y-axis
|
||||
double init_time = glfwGetTime();
|
||||
std::sort(points_, points_ + point_count_, cmp);
|
||||
double dt = glfwGetTime() - init_time;
|
||||
printf("Sort time (secs) = %f\n", dt);
|
||||
|
||||
/*
|
||||
|
||||
printf("*************************\n");
|
||||
for(int i = 0; i < point_count_; i++) {
|
||||
for (int i = 0; i < point_count_; i++) {
|
||||
printf("%f,%f ", points_[i]->x, points_[i]->y);
|
||||
printf("%p\n", points_[i]);
|
||||
}
|
||||
|
||||
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
|
||||
for(int i = 0; i < edge_list.size(); i++) {
|
||||
edge_list[i]->p->DebugPrint(); edge_list[i]->q->DebugPrint();
|
||||
printf("%p, %p\n", edge_list[i]->p, edge_list[i]->q);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
|
||||
for(int i = 0; i < edge_list.size(); i++) {
|
||||
edge_list[i]->p->DebugPrint(); edge_list[i]->q->DebugPrint();
|
||||
printf("%p, %p\n", edge_list[i]->p, edge_list[i]->q);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void SweepContext::InitEdges(Point** polyline, const int& point_count) {
|
||||
|
||||
for(int i = 0; i < point_count; i++) {
|
||||
void SweepContext::InitEdges(Point** polyline, const int& point_count)
|
||||
{
|
||||
for (int i = 0; i < point_count; i++) {
|
||||
int j = i < point_count - 1 ? i + 1 : 0;
|
||||
edge_list.push_back(new Edge(*polyline[i], *polyline[j]));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
for(int i = 0; i < edge_list.size(); i++) {
|
||||
edge_list[i]->p->DebugPrint(); edge_list[i]->q->DebugPrint();
|
||||
printf("%p, %p\n", edge_list[i]->p, edge_list[i]->q);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
Point* SweepContext::GetPoint(const int& index) {
|
||||
return points_[index];
|
||||
for(int i = 0; i < edge_list.size(); i++) {
|
||||
edge_list[i]->p->DebugPrint(); edge_list[i]->q->DebugPrint();
|
||||
printf("%p, %p\n", edge_list[i]->p, edge_list[i]->q);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void SweepContext::AddToMap(Triangle* triangle ) {
|
||||
Point* SweepContext::GetPoint(const int& index)
|
||||
{
|
||||
return points_[index];
|
||||
}
|
||||
|
||||
void SweepContext::AddToMap(Triangle* triangle)
|
||||
{
|
||||
map_.push_back(triangle);
|
||||
}
|
||||
|
||||
Node& SweepContext::LocateNode(Point& point) {
|
||||
// TODO implement search tree
|
||||
return *front_->Locate(point.x);
|
||||
Node& SweepContext::LocateNode(Point& point)
|
||||
{
|
||||
// TODO implement search tree
|
||||
return *front_->Locate(point.x);
|
||||
}
|
||||
|
||||
void SweepContext::CreateAdvancingFront() {
|
||||
|
||||
// Initial triangle
|
||||
Triangle* triangle = new Triangle(*points_[0], *tail_, *head_);
|
||||
void SweepContext::CreateAdvancingFront()
|
||||
{
|
||||
// Initial triangle
|
||||
Triangle* triangle = new Triangle(*points_[0], *tail_, *head_);
|
||||
|
||||
map_.push_back(triangle);
|
||||
|
||||
front_ = new AdvancingFront;
|
||||
|
||||
front_->set_head(new Node(*triangle->GetPoint(1)));
|
||||
front_->head()->triangle = triangle;
|
||||
Node* middle = new Node(*triangle->GetPoint(0));
|
||||
middle->triangle = triangle;
|
||||
front_->set_tail(new Node(*triangle->GetPoint(2)));
|
||||
front_->set_search(middle);
|
||||
|
||||
// TODO: More intuitive if head is middles next and not previous?
|
||||
// so swap head and tail
|
||||
front_->head()->next = middle;
|
||||
middle->next = front_->tail();
|
||||
middle->prev = front_->head();
|
||||
front_->tail()->prev = middle;
|
||||
|
||||
map_.push_back(triangle);
|
||||
|
||||
front_ = new AdvancingFront;
|
||||
|
||||
front_->set_head(new Node(*triangle->GetPoint(1)));
|
||||
front_->head()->triangle = triangle;
|
||||
Node* middle = new Node(*triangle->GetPoint(0));
|
||||
middle->triangle = triangle;
|
||||
front_->set_tail(new Node(*triangle->GetPoint(2)));
|
||||
front_->set_search(middle);
|
||||
|
||||
// TODO: More intuitive if head is middles next and not previous?
|
||||
// so swap head and tail
|
||||
front_->head()->next = middle;
|
||||
middle->next = front_->tail();
|
||||
middle->prev = front_->head();
|
||||
front_->tail()->prev = middle;
|
||||
}
|
||||
|
||||
void SweepContext::RemoveNode(Node* node) {
|
||||
delete node;
|
||||
|
||||
void SweepContext::RemoveNode(Node* node)
|
||||
{
|
||||
delete node;
|
||||
}
|
||||
|
||||
void SweepContext::MapTriangleToNodes(Triangle& t) {
|
||||
for(int i=0; i<3; i++) {
|
||||
if(t.GetNeighbor(i) == NULL) {
|
||||
|
||||
void SweepContext::MapTriangleToNodes(Triangle& t)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (t.GetNeighbor(i) == NULL) {
|
||||
Node* n = front_->LocatePoint(t.PointCW(*t.GetPoint(i)));
|
||||
if(n)
|
||||
if (n)
|
||||
n->triangle = &t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SweepContext::RemoveFromMap(Triangle* triangle) {
|
||||
map_.remove(triangle);
|
||||
}
|
||||
|
||||
void SweepContext::MeshClean(Triangle& triangle ) {
|
||||
|
||||
if(&triangle != NULL && !triangle.IsInterior()) {
|
||||
triangle.IsInterior(true);
|
||||
triangles_.push_back(&triangle);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(!triangle.constrained_edge[i])
|
||||
MeshClean(*triangle.GetNeighbor(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SweepContext::~SweepContext() {
|
||||
void SweepContext::RemoveFromMap(Triangle* triangle)
|
||||
{
|
||||
map_.remove(triangle);
|
||||
}
|
||||
|
||||
void SweepContext::MeshClean(Triangle& triangle)
|
||||
{
|
||||
if (&triangle != NULL && !triangle.IsInterior()) {
|
||||
triangle.IsInterior(true);
|
||||
triangles_.push_back(&triangle);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!triangle.constrained_edge[i])
|
||||
MeshClean(*triangle.GetNeighbor(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SweepContext::~SweepContext()
|
||||
{
|
||||
delete head_;
|
||||
delete tail_;
|
||||
delete front_;
|
||||
|
@@ -31,7 +31,7 @@
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
// 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.
|
||||
const double kAlpha = 0.3;
|
||||
|
||||
@@ -41,124 +41,141 @@ struct Node;
|
||||
struct Edge;
|
||||
class AdvancingFront;
|
||||
|
||||
|
||||
class SweepContext {
|
||||
|
||||
class SweepContext {
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
SweepContext(Point** polyline, const int& point_count);
|
||||
// Destructor
|
||||
~SweepContext();
|
||||
|
||||
//void MeshClean(Triangle& triangle);
|
||||
// Get Advancing Front
|
||||
//AdvancingFront front();
|
||||
|
||||
void set_head(Point* p1);
|
||||
Point* head();
|
||||
// Constructor
|
||||
SweepContext(Point** polyline, const int& point_count);
|
||||
// Destructor
|
||||
~SweepContext();
|
||||
|
||||
void set_tail(Point* p1 );
|
||||
Point* tail();
|
||||
|
||||
int point_count();
|
||||
|
||||
Node& LocateNode(Point& point);
|
||||
void RemoveNode(Node* node);
|
||||
|
||||
void CreateAdvancingFront();
|
||||
|
||||
// Try to map a node to all sides of this triangle that don't have a neighbor
|
||||
void MapTriangleToNodes(Triangle& t);
|
||||
|
||||
void AddToMap(Triangle* triangle);
|
||||
|
||||
Point* GetPoint(const int& index);
|
||||
Point* GetPoints();
|
||||
|
||||
void RemoveFromMap(Triangle* triangle);
|
||||
|
||||
AdvancingFront* front();
|
||||
|
||||
void MeshClean(Triangle& triangle);
|
||||
|
||||
std::vector<Triangle*> GetTriangles();
|
||||
std::list<Triangle*> GetMap();
|
||||
|
||||
std::vector<Edge*> edge_list;
|
||||
|
||||
struct Basin {
|
||||
|
||||
Node* left_node;
|
||||
Node* bottom_node;
|
||||
Node* right_node;
|
||||
double width;
|
||||
bool left_highest;
|
||||
|
||||
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL),
|
||||
width(0.0), left_highest(false) {}
|
||||
|
||||
void Clear() {
|
||||
left_node = NULL;
|
||||
bottom_node = NULL;
|
||||
right_node = NULL;
|
||||
width = 0.0;
|
||||
left_highest = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct EdgeEvent {
|
||||
|
||||
Edge* constrained_edge;
|
||||
bool right;
|
||||
|
||||
EdgeEvent() : constrained_edge(NULL), right(false) {}
|
||||
|
||||
};
|
||||
|
||||
Basin basin;
|
||||
EdgeEvent edge_event;
|
||||
|
||||
private:
|
||||
//void MeshClean(Triangle& triangle);
|
||||
// Get Advancing Front
|
||||
//AdvancingFront front();
|
||||
|
||||
std::vector<Triangle*> triangles_;
|
||||
std::list<Triangle*> map_;
|
||||
|
||||
Point** points_;
|
||||
int point_count_;
|
||||
|
||||
// Advancing front
|
||||
AdvancingFront* front_;
|
||||
// head point used with advancing front
|
||||
Point* head_;
|
||||
// tail point used with advancing front
|
||||
Point* tail_;
|
||||
|
||||
//EdgeEvent edgeEvent = new EdgeEvent();
|
||||
|
||||
void InitTriangulation();
|
||||
void InitEdges(Point** polyline, const int& point_count);
|
||||
|
||||
//void MeshCleanReq(Triangle& triangle )
|
||||
|
||||
/*
|
||||
class EdgeEvent {
|
||||
Edge* constrainedEdge;
|
||||
bool right;
|
||||
};
|
||||
*/
|
||||
|
||||
void set_head(Point* p1);
|
||||
Point* head();
|
||||
|
||||
void set_tail(Point* p1);
|
||||
Point* tail();
|
||||
|
||||
int point_count();
|
||||
|
||||
Node& LocateNode(Point& point);
|
||||
void RemoveNode(Node* node);
|
||||
|
||||
void CreateAdvancingFront();
|
||||
|
||||
// Try to map a node to all sides of this triangle that don't have a neighbor
|
||||
void MapTriangleToNodes(Triangle& t);
|
||||
|
||||
void AddToMap(Triangle* triangle);
|
||||
|
||||
Point* GetPoint(const int& index);
|
||||
Point* GetPoints();
|
||||
|
||||
void RemoveFromMap(Triangle* triangle);
|
||||
|
||||
AdvancingFront* front();
|
||||
|
||||
void MeshClean(Triangle& triangle);
|
||||
|
||||
std::vector<Triangle*> GetTriangles();
|
||||
std::list<Triangle*> GetMap();
|
||||
|
||||
std::vector<Edge*> edge_list;
|
||||
|
||||
struct Basin {
|
||||
Node* left_node;
|
||||
Node* bottom_node;
|
||||
Node* right_node;
|
||||
double width;
|
||||
bool left_highest;
|
||||
|
||||
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL),
|
||||
width(0.0), left_highest(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
left_node = NULL;
|
||||
bottom_node = NULL;
|
||||
right_node = NULL;
|
||||
width = 0.0;
|
||||
left_highest = false;
|
||||
}
|
||||
};
|
||||
|
||||
inline AdvancingFront* SweepContext::front() { return front_; }
|
||||
struct EdgeEvent {
|
||||
Edge* constrained_edge;
|
||||
bool right;
|
||||
|
||||
inline int SweepContext::point_count() { return point_count_; }
|
||||
EdgeEvent() : constrained_edge(NULL), right(false)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
inline void SweepContext::set_head(Point* p1) { head_ = p1; }
|
||||
Basin basin;
|
||||
EdgeEvent edge_event;
|
||||
|
||||
inline Point* SweepContext::head() { return head_; }
|
||||
private:
|
||||
|
||||
inline void SweepContext::set_tail(Point* p1) { tail_ = p1; }
|
||||
std::vector<Triangle*> triangles_;
|
||||
std::list<Triangle*> map_;
|
||||
|
||||
inline Point* SweepContext::tail() { return tail_; }
|
||||
Point** points_;
|
||||
int point_count_;
|
||||
|
||||
// Advancing front
|
||||
AdvancingFront* front_;
|
||||
// head point used with advancing front
|
||||
Point* head_;
|
||||
// tail point used with advancing front
|
||||
Point* tail_;
|
||||
|
||||
//EdgeEvent edgeEvent = new EdgeEvent();
|
||||
|
||||
void InitTriangulation();
|
||||
void InitEdges(Point** polyline, const int& point_count);
|
||||
|
||||
//void MeshCleanReq(Triangle& triangle )
|
||||
|
||||
/*
|
||||
class EdgeEvent {
|
||||
Edge* constrainedEdge;
|
||||
bool right;
|
||||
};
|
||||
*/
|
||||
};
|
||||
|
||||
inline AdvancingFront* SweepContext::front()
|
||||
{
|
||||
return front_;
|
||||
}
|
||||
|
||||
inline int SweepContext::point_count()
|
||||
{
|
||||
return point_count_;
|
||||
}
|
||||
|
||||
inline void SweepContext::set_head(Point* p1)
|
||||
{
|
||||
head_ = p1;
|
||||
}
|
||||
|
||||
inline Point* SweepContext::head()
|
||||
{
|
||||
return head_;
|
||||
}
|
||||
|
||||
inline void SweepContext::set_tail(Point* p1)
|
||||
{
|
||||
tail_ = p1;
|
||||
}
|
||||
|
||||
inline Point* SweepContext::tail()
|
||||
{
|
||||
return tail_;
|
||||
}
|
||||
|
Reference in New Issue
Block a user