diff --git a/README b/README index e72d3f9..74cc7b8 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -================== +================== INSTALLATION GUIDE ================== @@ -6,7 +6,7 @@ Dependencies ------------ Core poly2tri lib: - - Standard Template Library + - Standard Template Library Testbed: - gcc @@ -17,7 +17,7 @@ Dependencies Waf (http://code.google.com/p/waf/) is used to compile the testbed, and the Python waf script (86kb) is included in the repositoty. -Building the testbed +Building the Testbed ---------------------------------------------- Posix/MSYS environment: @@ -37,4 +37,4 @@ p2t Example: - ./build/default/p2.exe testbed/data/dude.dat 1.0 \ No newline at end of file + ./build/default/p2t testbed/data/dude.dat 1.0 \ No newline at end of file diff --git a/poly2tri/sweep/advancing_front.cc b/poly2tri/sweep/advancing_front.cc index df12b3b..0381385 100644 --- a/poly2tri/sweep/advancing_front.cc +++ b/poly2tri/sweep/advancing_front.cc @@ -30,9 +30,11 @@ */ #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) @@ -42,17 +44,20 @@ Node* AdvancingFront::Locate(const double& x) if (x < node->value) { //printf("<: - %f,%f - %p\n", x, node->value, node->next); while ((node = node->prev) != NULL) { + //printf("%p - %p\n", node, node->prev); if (x >= node->value) { search_node_ = node; + //printf("\nSN1: %p - %p\n", search_node_, search_node_->next); return node; } } } else { - //printf("%p - %p\n", node, node->next); //printf(">: %f - %f\n", x, node->value); while ((node = node->next) != NULL) { + //printf("%p - %p\n", node, node->next); if (x < node->value) { search_node_ = node->prev; + //printf("\nSN2: %p - %p\n", search_node_, search_node_->next); return node->prev; } } @@ -66,12 +71,13 @@ Node* AdvancingFront::FindSearchNode(const double& x) return search_node_; } -Node* AdvancingFront::LocatePoint(Point* point) +Node* AdvancingFront::LocatePoint(const Point* point) { const double px = point->x; Node* node = FindSearchNode(px); const double nx = node->point->x; - + printf("AF: %p - %p\n", node, node->next); + if (px == nx) { if (point != node->point) { // We might have two nodes with same x value for a short time @@ -85,17 +91,20 @@ Node* AdvancingFront::LocatePoint(Point* point) } } else if (px < nx) { while ((node = node->prev) != NULL) { + //printf("1 - %p - %p\n", node, node->next); if (point == node->point) { break; } } } else { while ((node = node->next) != NULL) { + //printf("2 - %p - %p\n", node, node->next); if (point == node->point) break; } } - if (node) search_node_ = node; + search_node_ = node; + printf("\nSN: %p - %p\n", search_node_, search_node_->next); return node; } diff --git a/poly2tri/sweep/advancing_front.h b/poly2tri/sweep/advancing_front.h index 15fd037..71e06f3 100644 --- a/poly2tri/sweep/advancing_front.h +++ b/poly2tri/sweep/advancing_front.h @@ -51,20 +51,13 @@ struct Node { { } - /* - ~Node() { - printf("going... "); - printf("bye node"); - printf(" ... gone!\n"); - } - */ }; // Advancing front class AdvancingFront { public: -AdvancingFront(); +AdvancingFront(Node& head, Node& tail); // Destructor ~AdvancingFront(); @@ -78,7 +71,7 @@ void set_search(Node* node); /// Locate insertion point along advancing front Node* Locate(const double& x); -Node* LocatePoint(Point* point); +Node* LocatePoint(const Point* point); private: diff --git a/poly2tri/sweep/sweep.cc b/poly2tri/sweep/sweep.cc index fb720f2..05af544 100644 --- a/poly2tri/sweep/sweep.cc +++ b/poly2tri/sweep/sweep.cc @@ -46,14 +46,14 @@ void Sweep::Triangulate(SweepContext& tcx) void Sweep::SweepPoints(SweepContext& tcx) { for (int i = 1; i < tcx.point_count(); i++) { - printf("%i = ", 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); - + printf("1..."); for (int i = 0; i < point.edge_list.size(); i++) { 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; node.next->prev = 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)) { tcx.MapTriangleToNodes(*triangle); } @@ -458,10 +459,10 @@ void Sweep::RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op) // the right side. t.ClearNeighbors(); ot.ClearNeighbors(); - if (n1 != NULL) ot.MarkNeighbor(*n1); - if (n2 != NULL) t.MarkNeighbor(*n2); - if (n3 != NULL) t.MarkNeighbor(*n3); - if (n4 != NULL) ot.MarkNeighbor(*n4); + if (n1) ot.MarkNeighbor(*n1); + if (n2) t.MarkNeighbor(*n2); + if (n3) t.MarkNeighbor(*n3); + if (n4) ot.MarkNeighbor(*n4); t.MarkNeighbor(ot); } @@ -595,7 +596,7 @@ void Sweep::FillRightBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node) if (Orient2d(*node.point, *node.next->point, *node.next->next->point) == CCW) { // Concave FillRightConcaveEdgeEvent(tcx, edge, node); - } else{ + } else{ // Convex FillRightConvexEdgeEvent(tcx, edge, node); // Retry this one diff --git a/poly2tri/sweep/sweep_context.cc b/poly2tri/sweep/sweep_context.cc index 3f0ed86..8ff9e45 100644 --- a/poly2tri/sweep/sweep_context.cc +++ b/poly2tri/sweep/sweep_context.cc @@ -55,6 +55,7 @@ void SweepContext::InitTriangulation() double dt = glfwGetTime() - init_time; printf("Sort time (secs) = %f\n", dt); + /* printf("*************************\n"); for (int i = 0; i < point_count_; i++) { printf("%f,%f ", points_[i]->x, points_[i]->y); @@ -103,26 +104,24 @@ Node& SweepContext::LocateNode(Point& point) void SweepContext::CreateAdvancingFront() { + Node *head, *middle, *tail; // 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); + head = new Node(*triangle->GetPoint(1), *triangle); + middle = new Node(*triangle->GetPoint(0), *triangle); + tail = new Node(*triangle->GetPoint(2)); + front_ = new AdvancingFront(*head, *tail); + // 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; + head->next = middle; + middle->next = tail; + middle->prev = head; + tail->prev = middle; } void SweepContext::RemoveNode(Node* node) diff --git a/poly2tri/sweep/sweep_context.h b/poly2tri/sweep/sweep_context.h index 19b0a3b..7e18233 100644 --- a/poly2tri/sweep/sweep_context.h +++ b/poly2tri/sweep/sweep_context.h @@ -50,10 +50,6 @@ 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(); @@ -93,8 +89,7 @@ struct Basin { double width; 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) { } @@ -140,14 +135,6 @@ Point* tail_; void InitTriangulation(); void InitEdges(Point** polyline, const int& point_count); -//void MeshCleanReq(Triangle& triangle ) - -/* - class EdgeEvent { - Edge* constrainedEdge; - bool right; - }; - */ }; inline AdvancingFront* SweepContext::front()