added DrawMap

This commit is contained in:
zzzzrrr 2010-01-20 12:25:10 -05:00
parent 0bb55b95b8
commit fa9488baca
5 changed files with 54 additions and 3 deletions

View File

@ -47,6 +47,10 @@ std::vector<Triangle*> CDT::GetTriangles() {
return sweep_context_->GetTriangles(); return sweep_context_->GetTriangles();
} }
std::list<Triangle*> CDT::GetMap() {
return sweep_context_->GetMap();
}
CDT::~CDT() { CDT::~CDT() {
delete sweep_context_; delete sweep_context_;
delete sweep_; delete sweep_;

View File

@ -46,6 +46,8 @@ public:
void Triangulate(); void Triangulate();
/// Get Delaunay triangles /// Get Delaunay triangles
std::vector<Triangle*> GetTriangles(); std::vector<Triangle*> GetTriangles();
/// Get triangle map
std::list<Triangle*> CDT::GetMap();
private: private:

View File

@ -21,6 +21,10 @@ std::vector<Triangle*> SweepContext::GetTriangles() {
return triangles_; return triangles_;
} }
std::list<Triangle*> SweepContext::GetMap() {
return map_;
}
void SweepContext::InitTriangulation() { void SweepContext::InitTriangulation() {
double xmax(points_[0]->x), xmin(points_[0]->x); double xmax(points_[0]->x), xmin(points_[0]->x);

View File

@ -83,6 +83,7 @@ public:
void MeshClean(Triangle& triangle); void MeshClean(Triangle& triangle);
std::vector<Triangle*> GetTriangles(); std::vector<Triangle*> GetTriangles();
std::list<Triangle*> GetMap();
std::vector<Edge*> edge_list; std::vector<Edge*> edge_list;

View File

@ -46,13 +46,17 @@ void Init();
void ShutDown(int return_code); void ShutDown(int return_code);
void MainLoop(const double zoom); void MainLoop(const double zoom);
void Draw(const double zoom); void Draw(const double zoom);
void DrawMap(const double zoom);
void ConstrainedColor(bool constrain); void ConstrainedColor(bool constrain);
float rotate_y = 0, float rotate_y = 0,
rotate_z = 0; rotate_z = 0;
const float rotations_per_tick = .2; const float rotations_per_tick = .2;
/// Constrained triangles
vector<Triangle*> triangles; vector<Triangle*> triangles;
/// Triangle map
list<Triangle*> map;
double StringToDouble(const std::string& s) { double StringToDouble(const std::string& s) {
std::istringstream i(s); std::istringstream i(s);
@ -62,6 +66,8 @@ double StringToDouble(const std::string& s) {
return x; return x;
} }
bool draw_map = false;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc != 3) { if (argc != 3) {
@ -124,6 +130,7 @@ int main(int argc, char* argv[]) {
cout << "Elapsed time (secs) = " << dt << endl; cout << "Elapsed time (secs) = " << dt << endl;
triangles = cdt->GetTriangles(); triangles = cdt->GetTriangles();
map = cdt->GetMap();
MainLoop(atof(argv[2])); MainLoop(atof(argv[2]));
@ -184,7 +191,12 @@ void MainLoop(const double zoom)
rotate_z += delta_rotate; rotate_z += delta_rotate;
// Draw the scene // Draw the scene
Draw(zoom); if(draw_map) {
DrawMap(zoom);
} else {
Draw(zoom);
}
// swap back and front buffers // swap back and front buffers
glfwSwapBuffers(); 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 // reset zoom
Point center = Point(0, 0); 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<Triangle*>::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) { void ConstrainedColor(bool constrain) {
if(constrain) { if(constrain) {
// Green // Green