diff --git a/poly2tri/sweep/cdt.cc b/poly2tri/sweep/cdt.cc index 5410c8b..3987cc8 100644 --- a/poly2tri/sweep/cdt.cc +++ b/poly2tri/sweep/cdt.cc @@ -47,6 +47,10 @@ std::vector CDT::GetTriangles() { return sweep_context_->GetTriangles(); } +std::list CDT::GetMap() { + return sweep_context_->GetMap(); +} + CDT::~CDT() { delete sweep_context_; delete sweep_; diff --git a/poly2tri/sweep/cdt.h b/poly2tri/sweep/cdt.h index de49110..b7cc058 100644 --- a/poly2tri/sweep/cdt.h +++ b/poly2tri/sweep/cdt.h @@ -46,6 +46,8 @@ public: void Triangulate(); /// Get Delaunay triangles std::vector GetTriangles(); + /// Get triangle map + std::list CDT::GetMap(); private: diff --git a/poly2tri/sweep/sweep_context.cc b/poly2tri/sweep/sweep_context.cc index 150d54e..761829c 100644 --- a/poly2tri/sweep/sweep_context.cc +++ b/poly2tri/sweep/sweep_context.cc @@ -21,6 +21,10 @@ std::vector SweepContext::GetTriangles() { return triangles_; } +std::list SweepContext::GetMap() { + return map_; +} + void SweepContext::InitTriangulation() { double xmax(points_[0]->x), xmin(points_[0]->x); diff --git a/poly2tri/sweep/sweep_context.h b/poly2tri/sweep/sweep_context.h index 253e4e1..f0a63fb 100644 --- a/poly2tri/sweep/sweep_context.h +++ b/poly2tri/sweep/sweep_context.h @@ -83,6 +83,7 @@ public: void MeshClean(Triangle& triangle); std::vector GetTriangles(); + std::list GetMap(); std::vector edge_list; diff --git a/testbed/main.cc b/testbed/main.cc index 9ddd802..4aa2cdd 100644 --- a/testbed/main.cc +++ b/testbed/main.cc @@ -46,13 +46,17 @@ void Init(); void ShutDown(int return_code); void MainLoop(const double zoom); void Draw(const double zoom); +void DrawMap(const double zoom); void ConstrainedColor(bool constrain); float rotate_y = 0, rotate_z = 0; const float rotations_per_tick = .2; +/// Constrained triangles vector triangles; +/// Triangle map +list map; double StringToDouble(const std::string& s) { std::istringstream i(s); @@ -62,6 +66,8 @@ double StringToDouble(const std::string& s) { return x; } +bool draw_map = false; + int main(int argc, char* argv[]) { if (argc != 3) { @@ -124,6 +130,7 @@ int main(int argc, char* argv[]) { cout << "Elapsed time (secs) = " << dt << endl; triangles = cdt->GetTriangles(); + map = cdt->GetMap(); MainLoop(atof(argv[2])); @@ -184,7 +191,12 @@ void MainLoop(const double zoom) rotate_z += delta_rotate; // Draw the scene - Draw(zoom); + if(draw_map) { + DrawMap(zoom); + } else { + Draw(zoom); + } + // swap back and front buffers glfwSwapBuffers(); } @@ -214,8 +226,8 @@ void ResetZoom(double zoom, double cx, double cy, double width, double height) { } -void Draw(const double zoom) -{ +void Draw(const double zoom) { + // reset zoom Point center = Point(0, 0); @@ -250,6 +262,34 @@ void Draw(const double zoom) } +void DrawMap(const double zoom) { + + // reset zoom + Point center = Point(0, 0); + + ResetZoom(zoom, center.x, center.y, 800, 600); + + list::iterator it; + for (it = map.begin(); it != map.end(); it++) { + + Triangle& t = **it; + Point& a = *t.GetPoint(0); + Point& b = *t.GetPoint(1); + Point& c = *t.GetPoint(2); + + // Red + glColor3f(1, 0, 0); + + glBegin(GL_LINE_LOOP); + glVertex2f(a.x, a.y); + glVertex2f(b.x, b.y); + glVertex2f(c.x, c.y); + glEnd(); + + } + +} + void ConstrainedColor(bool constrain) { if(constrain) { // Green