void GLMesh::fillBuffers(const std::vector<Eigen::Vector3f>& colors) { vertices.resize(3*(mesh.faces.size() - mesh.boundaries.size())); for (FaceCIter f = mesh.faces.begin(); f != mesh.faces.end(); f++) { if (!f->isBoundary()) { int i = 0; int fIdx = 3*f->index; HalfEdgeCIter h = f->he; do { VertexCIter v = h->vertex; // set vertex vertices[fIdx+i].position = v->position.cast<float>(); vertices[fIdx+i].normal = v->normal().cast<float>(); vertices[fIdx+i].color = colors[f->index]; vertices[fIdx+i].uv = v->uv.cast<float>(); i++; h = h->next; } while (h != f->he); // set barycenters vertices[fIdx+0].barycenter = Eigen::Vector3f(1.0, 0.0, 0.0); vertices[fIdx+1].barycenter = Eigen::Vector3f(0.0, 1.0, 0.0); vertices[fIdx+2].barycenter = Eigen::Vector3f(0.0, 0.0, 1.0); } } }
void Mesh::buildAreaMatrix(Eigen::SparseMatrix<double>& A) const { std::vector<Eigen::Triplet<double>> ATriplet; for (VertexCIter v = vertices.begin(); v != vertices.end(); v++) { ATriplet.push_back(Eigen::Triplet<double>(v->index, v->index, v->dualArea())); } A.setFromTriplets(ATriplet.begin(), ATriplet.end()); }
void MeshBuilder::checkIsolatedVertices(const Mesh& mesh) { for (VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v++) { if (v->isIsolated()) { std::cerr << "Warning: vertex " << v->index << " is isolated (not contained in any face)." << std::endl; } } }
void GLMesh::fillPickBuffers() { int tris = (int)(mesh.faces.size() - mesh.boundaries.size()); // add faces int i = 0; pickVertices.resize(3*tris); for (FaceCIter f = mesh.faces.begin(); f != mesh.faces.end(); f++) { if (!f->isBoundary()) { int j = 0; Eigen::Vector3f color = elementColor(f->index); HalfEdgeCIter h = f->he; do { // set vertex pickVertices[3*i+j].position = h->vertex->position.cast<float>(); pickVertices[3*i+j].color = color; j++; h = h->next; } while (h != f->he); i++; } } // add vertex faces int verts = 0; for (VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v++) { verts += v->degree(); if (v->isBoundary()) verts -= 1; } pickVertices.resize(3*(tris + verts)); for (VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v++) { Eigen::Vector3d n = 0.0015*v->normal(); Eigen::Vector3f p1 = (v->position + n).cast<float>(); Eigen::Vector3f color = elementColor(tris + v->index); HalfEdgeCIter h = v->he; do { if (!h->onBoundary) { Eigen::Vector3f p2 = (h->next->vertex->position + n).cast<float>(); Eigen::Vector3f p3 = (h->next->next->vertex->position + n).cast<float>(); pickVertices[3*i+0].position = p1; pickVertices[3*i+1].position = p1 + 0.125*(p2 - p1); pickVertices[3*i+2].position = p1 + 0.125*(p3 - p1); pickVertices[3*i+0].color = pickVertices[3*i+1].color = pickVertices[3*i+2].color = color; i++; } h = h->flip->next; } while (h != v->he); } }
void MeshIO :: checkIsolatedVertices( const Mesh& mesh ) { // print a warning if the mesh has any isolated vertices int vertexIndex = 0; for( VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v ++ ) { if( v->isIsolated() ) { cerr << "Warning: vertex " << vertexIndex << " is isolated (not contained in any face)." << endl; } vertexIndex++; } }
void MeshIO :: checkNonManifoldVertices( const Mesh& mesh ) { map<VertexCIter,int> nIncidentFaces; for( FaceCIter f = mesh.faces.begin(); f != mesh.faces.end(); f ++ ) { HalfEdgeCIter he = f->he; do { nIncidentFaces[he->vertex]++; he = he->next; } while( he != f->he ); } for( FaceCIter f = mesh.boundaries.begin(); f != mesh.boundaries.end(); f ++ ) { HalfEdgeCIter he = f->he; do { nIncidentFaces[he->vertex]++; he = he->next; } while( he != f->he ); } int vertexIndex = 0; for( VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v ++ ) { if( nIncidentFaces[v] != v->valence() ) { cerr << "Warning: vertex " << vertexIndex << " is nonmanifold." << endl; } vertexIndex++; } }
void Viewer :: drawIsolatedVertices( void ) { glPushAttrib( GL_ALL_ATTRIB_BITS ); glPointSize( 5 ); glHint( GL_POINT_SMOOTH_HINT, GL_NICEST ); glEnable( GL_POINT_SMOOTH ); glColor3f( 1., 0., 0. ); glBegin( GL_POINTS ); for( VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v ++ ) { if( v->isIsolated() ) { glVertex3dv( &v->position[0] ); } } glEnd(); glPopAttrib(); }
void Mesh::buildLaplacian(Eigen::SparseMatrix<double>& L) const { std::vector<Eigen::Triplet<double>> LTriplet; for (VertexCIter v = vertices.begin(); v != vertices.end(); v++) { HalfEdgeCIter he = v->he; double dualArea = v->dualArea(); double sumCoefficients = 0.0; do { // (cotA + cotB) / 2A double coefficient = 0.5 * (he->cotan() + he->flip->cotan()) / dualArea; sumCoefficients += coefficient; LTriplet.push_back(Eigen::Triplet<double>(v->index, he->flip->vertex->index, -coefficient)); he = he->flip->next; } while (he != v->he); LTriplet.push_back(Eigen::Triplet<double>(v->index, v->index, sumCoefficients)); } L.setFromTriplets(LTriplet.begin(), LTriplet.end()); }