/** * remove edges from vertices when the vertex is removed */ void BOP_Merge2::freeVerts(BOP_Index v, BOP_Vertex *vert) { BOP_Indexs edges = vert->getEdges(); BOP_Vertex *other; for( BOP_IT_Indexs it = edges.begin(); it != edges.end(); ++it) { BOP_Edge *edge = m_mesh->getEdge(*it); BOP_Indexs edges2; if( edge->getVertex1() != v ) other = m_mesh->getVertex( edge->getVertex1() ); else other = m_mesh->getVertex( edge->getVertex2() ); other->removeEdge(*it); vert->removeEdge(*it); } }
/** * Replaces a vertex index. * @param oldIndex old vertex index * @param newIndex new vertex index */ BOP_Index BOP_Mesh::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex) { BOP_IT_Indexs oldEdgeIndex; if (oldIndex==newIndex) return newIndex; // Update faces, edges and vertices BOP_Vertex *oldVertex = m_vertexs[oldIndex]; BOP_Vertex *newVertex = m_vertexs[newIndex]; BOP_Indexs oldEdges = oldVertex->getEdges(); // Update faces to the newIndex BOP_IT_Indexs oldEdgesEnd = oldEdges.end(); for(oldEdgeIndex=oldEdges.begin();oldEdgeIndex!=oldEdgesEnd; oldEdgeIndex++) { BOP_Edge *edge = m_edges[*oldEdgeIndex]; if ((edge->getVertex1()==oldIndex && edge->getVertex2()==newIndex) || (edge->getVertex2()==oldIndex && edge->getVertex1()==newIndex)) { // Remove old edge ==> set edge faces to BROKEN removeBrokenFaces( edge, this ); oldVertex->removeEdge(*oldEdgeIndex); newVertex->removeEdge(*oldEdgeIndex); } else { BOP_Indexs faces = edge->getFaces(); const BOP_IT_Indexs facesEnd = faces.end(); for(BOP_IT_Indexs face=faces.begin();face!=facesEnd;face++) { if (m_faces[*face]->getTAG()!=BROKEN) m_faces[*face]->replaceVertexIndex(oldIndex,newIndex); } } } oldEdgesEnd = oldEdges.end(); for(oldEdgeIndex=oldEdges.begin();oldEdgeIndex!=oldEdgesEnd; oldEdgeIndex++) { BOP_Edge * edge = m_edges[*oldEdgeIndex]; BOP_Edge * edge2; BOP_Index v1 = edge->getVertex1(); v1 = (v1==oldIndex?edge->getVertex2():v1); if ((edge2 = getEdge(newIndex,v1)) == NULL) { edge->replaceVertexIndex(oldIndex,newIndex); if ( edge->getVertex1() == edge->getVertex2() ) { removeBrokenFaces( edge, this ); oldVertex->removeEdge(*oldEdgeIndex); } #ifdef HASH rehashVertex(oldIndex,newIndex,v1); #endif newVertex->addEdge(*oldEdgeIndex); } else { BOP_Indexs faces = edge->getFaces(); const BOP_IT_Indexs facesEnd = faces.end(); for(BOP_IT_Indexs f=faces.begin();f!=facesEnd;f++) { if (m_faces[*f]->getTAG()!=BROKEN) edge2->addFace(*f); } BOP_Vertex *oppositeVertex = m_vertexs[v1]; oppositeVertex->removeEdge(*oldEdgeIndex); edge->replaceVertexIndex(oldIndex,newIndex); if ( edge->getVertex1() == edge->getVertex2() ) { removeBrokenFaces( edge, this ); oldVertex->removeEdge(*oldEdgeIndex); newVertex->removeEdge(*oldEdgeIndex); } #ifdef HASH rehashVertex(oldIndex,newIndex,v1); #endif } } oldVertex->setTAG(BROKEN); return newIndex; }