void display() { // Set up correct OpenGL projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(dmin[0], dmax[0], dmin[1], dmax[1]); glMatrixMode(GL_MODELVIEW); // Specify that we want to draw triangle outlines glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Black on white. glClearColor(1,1,1,0); glColor3f(0,0,0); // Clear the screen. glClear(GL_COLOR_BUFFER_BIT); for(FaceID f: m.faces()){ glBegin(GL_POLYGON); for(Walker w = m.walker(f); !w.full_circle(); w = w.next()) glVertex3dv(m.pos(w.vertex()).get()); glEnd(); } // Draw flipper. glColor3f(1,0,0); glBegin(GL_LINES); Walker hew = m.walker(*flipper); glVertex3dv(m.pos(hew.vertex()).get()); glVertex3dv(m.pos(hew.opp().vertex()).get()); glEnd(); glFinish(); }
void dual(Manifold& m) { // Create new vertices. Each face becomes a vertex whose position // is the centre of the face int i = 0; FaceAttributeVector<int> ftouched; vector<Vec3d> vertices; vertices.resize(m.no_faces()); for(auto f : m.faces()) vertices[ftouched[f] = i++] = centre(m, f); // Create new faces. Each vertex is a new face with N=valency of vertex // edges. vector<int> faces; vector<int> indices; for(auto v : m.vertices()) if(valency(m, v) > 2 && !(boundary(m, v))) { // int N = circulate_vertex_ccw(m, v, (std::function<void(FaceID)>)[&](FaceID fid) { // indices.push_back(ftouched[fid]); // }); Walker w = m.walker(v); for(; !w.full_circle(); w = w.circulate_vertex_ccw()){ indices.push_back(ftouched[w.face()]); } int N = w.no_steps(); // Insert face valency in the face vector. faces.push_back(N); } // Clear the manifold before new geometry is inserted. m.clear(); // And build m.build( vertices.size(), reinterpret_cast<double*>(&vertices[0]), faces.size(), &faces[0], &indices[0]); }