//get Adjacent Vertexes of a vertex void HalfEdgeMesh::getAdjacentVertexes(int vertexIndex, vector<int>& adjVtx_ids){ if(!isOnBoundary(vertexIndex)){ for(int i=0;i<HEHalfEdges.size();i++){ if(HEHalfEdges.at(i).origin==vertexIndex){ int next_edge_id=HEHalfEdges.at(i).next; int next_vtx_id=HEHalfEdges.at(next_edge_id).origin; adjVtx_ids.push_back(next_vtx_id); } } } else{ for(int i=0;i<HEHalfEdges.size();i++){ int next_edge_id=HEHalfEdges.at(i).next; int next_vtx_id=HEHalfEdges.at(next_edge_id).origin; if(HEHalfEdges.at(i).origin==vertexIndex){ adjVtx_ids.push_back(next_vtx_id); } else if(next_vtx_id==vertexIndex&&isOnBoundary(HEHalfEdges.at(i).origin)){ adjVtx_ids.push_back(HEHalfEdges.at(i).origin); } } } }
Vector3F AccCorner::computeNormal() const { if(isOnBoundary()) return *_centerNormal * (2.f / 3.f) + _edgeNormals[0] * (1.f / 6.f) + _edgeNormals[valence() - 1] * (1.f / 6.f); float e = 4.f; float c = 1.f; float sum = 0.f; Vector3F res; res.setZero(); Vector3F q; for(int i = 0; i < valence(); i++) { q = _edgeNormals[i]; res += q * e; sum += e; q = _cornerNormals[i]; res += q * c; sum += c; } sum += valence() * valence(); res += *_centerNormal * valence() * valence(); return res / sum; }
Vector3F AccCorner::computePosition() const { if(isOnBoundary()) return *_centerPosition * (2.f / 3.f) + _edgePositions[0] * (1.f / 6.f) + _edgePositions[valence() - 1] * (1.f / 6.f); float e = 4.f; float c = 1.f; float sum = 0.f; Vector3F res; Vector3F q; for(int i = 0; i < valence(); i++) { q = _edgePositions[i]; res += q * e; sum += e; q = _cornerPositions[i]; res += q * c; sum += c; } sum += valence() * valence(); res += *_centerPosition * valence() * valence(); res /= sum; return res; }
//get two sets of sequential Adjacent Vertexes of two vertexes that is in a half edge which is not a boundary edge void HalfEdgeMesh::getSequentialAdjacentVertexes(int he_id, vector<int>& adjVtx_ids0, vector<int>& adjVtx_ids1){ if(!isBoundary(HEHalfEdges.at(he_id))){ int twin_id=HEHalfEdges.at(he_id).twin; int tem_id=-1; int vtx0_id=HEHalfEdges.at(he_id).origin; int vtx1_id=HEHalfEdges.at(twin_id).origin; if(isOnBoundary(vtx0_id)){ vector<int> vtx_ids; getBoundaryAdjacentVertexes(vtx0_id, vtx_ids); int tem_next=-1; int tem_pre=-1; for(int i=0;i<HEHalfEdges.size();i++){ if(HEHalfEdges.at(i).origin==vtx0_id&&(HEHalfEdges.at(HEHalfEdges.at(i).next).origin==vtx_ids.at(0)||HEHalfEdges.at(HEHalfEdges.at(i).next).origin==vtx_ids.at(1))){ tem_next=HEHalfEdges.at(i).next; tem_pre=HEHalfEdges.at(i).prev; adjVtx_ids0.push_back(HEHalfEdges.at(tem_next).origin); break; } } tem_id=HEHalfEdges.at(tem_pre).twin; while(tem_id!=-1){ tem_next=HEHalfEdges.at(tem_id).next; tem_pre=HEHalfEdges.at(tem_id).prev; adjVtx_ids0.push_back(HEHalfEdges.at(tem_next).origin); tem_id=HEHalfEdges.at(tem_pre).twin; } adjVtx_ids0.push_back(HEHalfEdges.at(tem_pre).origin); vector<int> adjVtx_ids_tem; int index_tem=-1; for(int k=0;k<adjVtx_ids0.size();k++){ if(adjVtx_ids0.at(k)==vtx1_id){ index_tem=k; } } for(int k=index_tem;k<adjVtx_ids0.size();k++){ adjVtx_ids_tem.push_back(adjVtx_ids0.at(k)); } for(int k=0;k<index_tem;k++){ adjVtx_ids_tem.push_back(adjVtx_ids0.at(k)); } adjVtx_ids0=adjVtx_ids_tem; } else{ adjVtx_ids0.push_back(HEHalfEdges.at(twin_id).origin); while(twin_id!=tem_id){ if(tem_id==-1){ tem_id=twin_id; } int next_id=HEHalfEdges.at(tem_id).next; tem_id=HEHalfEdges.at(next_id).twin; adjVtx_ids0.push_back(HEHalfEdges.at(tem_id).origin); } invert(adjVtx_ids0); adjVtx_ids0.pop_back(); } tem_id=-1; if(isOnBoundary(vtx1_id)){ vector<int> vtx_ids; getBoundaryAdjacentVertexes(vtx1_id, vtx_ids); int tem_next=-1; int tem_pre=-1; for(int i=0;i<HEHalfEdges.size();i++){ if(HEHalfEdges.at(i).origin==vtx1_id&&(HEHalfEdges.at(HEHalfEdges.at(i).next).origin==vtx_ids.at(0)||HEHalfEdges.at(HEHalfEdges.at(i).next).origin==vtx_ids.at(1))){ tem_next=HEHalfEdges.at(i).next; tem_pre=HEHalfEdges.at(i).prev; adjVtx_ids1.push_back(HEHalfEdges.at(tem_next).origin); break; } } tem_id=HEHalfEdges.at(tem_pre).twin; while(tem_id!=-1){ tem_next=HEHalfEdges.at(tem_id).next; tem_pre=HEHalfEdges.at(tem_id).prev; adjVtx_ids1.push_back(HEHalfEdges.at(tem_next).origin); tem_id=HEHalfEdges.at(tem_pre).twin; } adjVtx_ids1.push_back(HEHalfEdges.at(tem_pre).origin); vector<int> adjVtx_ids_tem; int index_tem=-1; for(int k=0;k<adjVtx_ids1.size();k++){ if(adjVtx_ids1.at(k)==vtx0_id){ index_tem=k; } } for(int k=index_tem;k<adjVtx_ids1.size();k++){ adjVtx_ids_tem.push_back(adjVtx_ids1.at(k)); } for(int k=0;k<index_tem;k++){ adjVtx_ids_tem.push_back(adjVtx_ids1.at(k)); } adjVtx_ids1=adjVtx_ids_tem; } else{ adjVtx_ids1.push_back(HEHalfEdges.at(he_id).origin); while(he_id!=tem_id){ if(tem_id==-1){ tem_id=he_id; } int next_id=HEHalfEdges.at(tem_id).next; tem_id=HEHalfEdges.at(next_id).twin; adjVtx_ids1.push_back(HEHalfEdges.at(tem_id).origin); } invert(adjVtx_ids1); adjVtx_ids1.pop_back(); } } }