mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-12-02 10:13:29 +01:00
code cleanup
This commit is contained in:
parent
1c348a9829
commit
696ef826bd
6
README
6
README
@ -1,4 +1,4 @@
|
|||||||
==================
|
==================
|
||||||
INSTALLATION GUIDE
|
INSTALLATION GUIDE
|
||||||
==================
|
==================
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ Dependencies
|
|||||||
Waf (http://code.google.com/p/waf/) is used to compile the testbed, and
|
Waf (http://code.google.com/p/waf/) is used to compile the testbed, and
|
||||||
the Python waf script (86kb) is included in the repositoty.
|
the Python waf script (86kb) is included in the repositoty.
|
||||||
|
|
||||||
Building the testbed
|
Building the Testbed
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
Posix/MSYS environment:
|
Posix/MSYS environment:
|
||||||
@ -37,4 +37,4 @@ p2t <data file> <zoom>
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
./build/default/p2.exe testbed/data/dude.dat 1.0
|
./build/default/p2t testbed/data/dude.dat 1.0
|
@ -30,9 +30,11 @@
|
|||||||
*/
|
*/
|
||||||
#include "advancing_front.h"
|
#include "advancing_front.h"
|
||||||
|
|
||||||
AdvancingFront::AdvancingFront()
|
AdvancingFront::AdvancingFront(Node& head, Node& tail)
|
||||||
{
|
{
|
||||||
head_ = tail_ = search_node_ = NULL;
|
head_ = &head;
|
||||||
|
tail_ = &tail;
|
||||||
|
search_node_ = &head;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* AdvancingFront::Locate(const double& x)
|
Node* AdvancingFront::Locate(const double& x)
|
||||||
@ -42,17 +44,20 @@ Node* AdvancingFront::Locate(const double& x)
|
|||||||
if (x < node->value) {
|
if (x < node->value) {
|
||||||
//printf("<: - %f,%f - %p\n", x, node->value, node->next);
|
//printf("<: - %f,%f - %p\n", x, node->value, node->next);
|
||||||
while ((node = node->prev) != NULL) {
|
while ((node = node->prev) != NULL) {
|
||||||
|
//printf("%p - %p\n", node, node->prev);
|
||||||
if (x >= node->value) {
|
if (x >= node->value) {
|
||||||
search_node_ = node;
|
search_node_ = node;
|
||||||
|
//printf("\nSN1: %p - %p\n", search_node_, search_node_->next);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//printf("%p - %p\n", node, node->next);
|
|
||||||
//printf(">: %f - %f\n", x, node->value);
|
//printf(">: %f - %f\n", x, node->value);
|
||||||
while ((node = node->next) != NULL) {
|
while ((node = node->next) != NULL) {
|
||||||
|
//printf("%p - %p\n", node, node->next);
|
||||||
if (x < node->value) {
|
if (x < node->value) {
|
||||||
search_node_ = node->prev;
|
search_node_ = node->prev;
|
||||||
|
//printf("\nSN2: %p - %p\n", search_node_, search_node_->next);
|
||||||
return node->prev;
|
return node->prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,11 +71,12 @@ Node* AdvancingFront::FindSearchNode(const double& x)
|
|||||||
return search_node_;
|
return search_node_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* AdvancingFront::LocatePoint(Point* point)
|
Node* AdvancingFront::LocatePoint(const Point* point)
|
||||||
{
|
{
|
||||||
const double px = point->x;
|
const double px = point->x;
|
||||||
Node* node = FindSearchNode(px);
|
Node* node = FindSearchNode(px);
|
||||||
const double nx = node->point->x;
|
const double nx = node->point->x;
|
||||||
|
printf("AF: %p - %p\n", node, node->next);
|
||||||
|
|
||||||
if (px == nx) {
|
if (px == nx) {
|
||||||
if (point != node->point) {
|
if (point != node->point) {
|
||||||
@ -85,17 +91,20 @@ Node* AdvancingFront::LocatePoint(Point* point)
|
|||||||
}
|
}
|
||||||
} else if (px < nx) {
|
} else if (px < nx) {
|
||||||
while ((node = node->prev) != NULL) {
|
while ((node = node->prev) != NULL) {
|
||||||
|
//printf("1 - %p - %p\n", node, node->next);
|
||||||
if (point == node->point) {
|
if (point == node->point) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while ((node = node->next) != NULL) {
|
while ((node = node->next) != NULL) {
|
||||||
|
//printf("2 - %p - %p\n", node, node->next);
|
||||||
if (point == node->point)
|
if (point == node->point)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node) search_node_ = node;
|
search_node_ = node;
|
||||||
|
printf("\nSN: %p - %p\n", search_node_, search_node_->next);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,20 +51,13 @@ struct Node {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
~Node() {
|
|
||||||
printf("going... ");
|
|
||||||
printf("bye node");
|
|
||||||
printf(" ... gone!\n");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Advancing front
|
// Advancing front
|
||||||
class AdvancingFront {
|
class AdvancingFront {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AdvancingFront();
|
AdvancingFront(Node& head, Node& tail);
|
||||||
// Destructor
|
// Destructor
|
||||||
~AdvancingFront();
|
~AdvancingFront();
|
||||||
|
|
||||||
@ -78,7 +71,7 @@ void set_search(Node* node);
|
|||||||
/// Locate insertion point along advancing front
|
/// Locate insertion point along advancing front
|
||||||
Node* Locate(const double& x);
|
Node* Locate(const double& x);
|
||||||
|
|
||||||
Node* LocatePoint(Point* point);
|
Node* LocatePoint(const Point* point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -46,14 +46,14 @@ void Sweep::Triangulate(SweepContext& tcx)
|
|||||||
void Sweep::SweepPoints(SweepContext& tcx)
|
void Sweep::SweepPoints(SweepContext& tcx)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < tcx.point_count(); i++) {
|
for (int i = 1; i < tcx.point_count(); i++) {
|
||||||
printf("%i = ", i);
|
|
||||||
Point& point = *tcx.GetPoint(i);
|
Point& point = *tcx.GetPoint(i);
|
||||||
printf("%f,%f\n", point.x, point.y);
|
printf("%i = %f,%f ", i, point.x, point.y);
|
||||||
Node& node = PointEvent(tcx, point);
|
Node& node = PointEvent(tcx, point);
|
||||||
|
printf("1...");
|
||||||
for (int i = 0; i < point.edge_list.size(); i++) {
|
for (int i = 0; i < point.edge_list.size(); i++) {
|
||||||
EdgeEvent(tcx, point.edge_list[i], node);
|
EdgeEvent(tcx, point.edge_list[i], node);
|
||||||
}
|
}
|
||||||
|
printf("2!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,8 @@ Node& Sweep::NewFrontTriangle(SweepContext& tcx, Point& point, Node& node)
|
|||||||
new_node->prev = &node;
|
new_node->prev = &node;
|
||||||
node.next->prev = new_node;
|
node.next->prev = new_node;
|
||||||
node.next = new_node;
|
node.next = new_node;
|
||||||
|
//printf("\n%p - %p - %p | ", new_node->prev, new_node, new_node->next);
|
||||||
|
//printf("%p - %p - %p\n", node.prev, &node, node.next);
|
||||||
if (!Legalize(tcx, *triangle)) {
|
if (!Legalize(tcx, *triangle)) {
|
||||||
tcx.MapTriangleToNodes(*triangle);
|
tcx.MapTriangleToNodes(*triangle);
|
||||||
}
|
}
|
||||||
@ -458,10 +459,10 @@ void Sweep::RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op)
|
|||||||
// the right side.
|
// the right side.
|
||||||
t.ClearNeighbors();
|
t.ClearNeighbors();
|
||||||
ot.ClearNeighbors();
|
ot.ClearNeighbors();
|
||||||
if (n1 != NULL) ot.MarkNeighbor(*n1);
|
if (n1) ot.MarkNeighbor(*n1);
|
||||||
if (n2 != NULL) t.MarkNeighbor(*n2);
|
if (n2) t.MarkNeighbor(*n2);
|
||||||
if (n3 != NULL) t.MarkNeighbor(*n3);
|
if (n3) t.MarkNeighbor(*n3);
|
||||||
if (n4 != NULL) ot.MarkNeighbor(*n4);
|
if (n4) ot.MarkNeighbor(*n4);
|
||||||
t.MarkNeighbor(ot);
|
t.MarkNeighbor(ot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ void SweepContext::InitTriangulation()
|
|||||||
double dt = glfwGetTime() - init_time;
|
double dt = glfwGetTime() - init_time;
|
||||||
printf("Sort time (secs) = %f\n", dt);
|
printf("Sort time (secs) = %f\n", dt);
|
||||||
|
|
||||||
|
/*
|
||||||
printf("*************************\n");
|
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("%f,%f ", points_[i]->x, points_[i]->y);
|
||||||
@ -103,26 +104,24 @@ Node& SweepContext::LocateNode(Point& point)
|
|||||||
|
|
||||||
void SweepContext::CreateAdvancingFront()
|
void SweepContext::CreateAdvancingFront()
|
||||||
{
|
{
|
||||||
|
Node *head, *middle, *tail;
|
||||||
// Initial triangle
|
// Initial triangle
|
||||||
Triangle* triangle = new Triangle(*points_[0], *tail_, *head_);
|
Triangle* triangle = new Triangle(*points_[0], *tail_, *head_);
|
||||||
|
|
||||||
map_.push_back(triangle);
|
map_.push_back(triangle);
|
||||||
|
|
||||||
front_ = new AdvancingFront;
|
head = new Node(*triangle->GetPoint(1), *triangle);
|
||||||
|
middle = new Node(*triangle->GetPoint(0), *triangle);
|
||||||
|
tail = new Node(*triangle->GetPoint(2));
|
||||||
|
|
||||||
front_->set_head(new Node(*triangle->GetPoint(1)));
|
front_ = new AdvancingFront(*head, *tail);
|
||||||
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?
|
// TODO: More intuitive if head is middles next and not previous?
|
||||||
// so swap head and tail
|
// so swap head and tail
|
||||||
front_->head()->next = middle;
|
head->next = middle;
|
||||||
middle->next = front_->tail();
|
middle->next = tail;
|
||||||
middle->prev = front_->head();
|
middle->prev = head;
|
||||||
front_->tail()->prev = middle;
|
tail->prev = middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::RemoveNode(Node* node)
|
void SweepContext::RemoveNode(Node* node)
|
||||||
|
@ -50,10 +50,6 @@ SweepContext(Point** polyline, const int& point_count);
|
|||||||
// Destructor
|
// Destructor
|
||||||
~SweepContext();
|
~SweepContext();
|
||||||
|
|
||||||
//void MeshClean(Triangle& triangle);
|
|
||||||
// Get Advancing Front
|
|
||||||
//AdvancingFront front();
|
|
||||||
|
|
||||||
void set_head(Point* p1);
|
void set_head(Point* p1);
|
||||||
Point* head();
|
Point* head();
|
||||||
|
|
||||||
@ -93,8 +89,7 @@ struct Basin {
|
|||||||
double width;
|
double width;
|
||||||
bool left_highest;
|
bool left_highest;
|
||||||
|
|
||||||
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL),
|
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL), width(0.0), left_highest(false)
|
||||||
width(0.0), left_highest(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,14 +135,6 @@ Point* tail_;
|
|||||||
void InitTriangulation();
|
void InitTriangulation();
|
||||||
void InitEdges(Point** polyline, const int& point_count);
|
void InitEdges(Point** polyline, const int& point_count);
|
||||||
|
|
||||||
//void MeshCleanReq(Triangle& triangle )
|
|
||||||
|
|
||||||
/*
|
|
||||||
class EdgeEvent {
|
|
||||||
Edge* constrainedEdge;
|
|
||||||
bool right;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline AdvancingFront* SweepContext::front()
|
inline AdvancingFront* SweepContext::front()
|
||||||
|
Loading…
Reference in New Issue
Block a user