void keyfun(unsigned char c, int x, int y) { /* * A little game, try to flip an edge when user presses any key. * Not all edges can be flipped. Boundary edges cannot. Edges also * cannot be flipped if it will render the mesh invalid. */ if(boundary(m, *flipper)) // If this is a boundary edge just drop the idea. cout << "boundary edge" << endl; else if(precond_flip_edge(m, *flipper)) { m.flip_edge(*flipper); cout << "flipped" << endl; } else cout << "could not flip" << endl; do { ++flipper; // Get the next halfedge // If we have passed the last halfedge, go to the first. if(flipper==m.halfedges_end()) { flipper = m.halfedges_begin(); break; } } while(touched[*flipper] == 0); // Only visit halfedges marked '1' // Function call below informs glut that display should be called to // show the window again. glutPostRedisplay(); }
#include <GLGraphics/gel_glut.h> #include <CGLA/Vec2d.h> #include <CGLA/Mat3x3d.h> #include <CGLA/Mat3x3f.h> #include <CGLA/Mat4x4f.h> using namespace std; using namespace CGLA; using namespace HMesh; // The range of the input data. Vec2d dmin(99e99), dmax(-99e99); Manifold m; // The triangle mesh data structure. HalfEdgeIDIterator flipper = m.halfedges_begin(); // The halfedge we try to flip. HalfEdgeAttributeVector<int> touched; /* * Draw the triangle mesh. This function is called from GLUT (a library * which enables OpenGL drawing in windows.) */ void display() { // Set up correct OpenGL projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(dmin[0], dmax[0], dmin[1], dmax[1]); glMatrixMode(GL_MODELVIEW);