void ReTriangulation::legalizeTriangle(Vec3f point[], Vec3i& face, Vec3f& normal) { GeometricFunc func; Vec3f n=func.computeNormal(point); if(n*normal<0) { int temp=face[1]; face[1]=face[2]; face[2]=temp; } }
void ReTriangulation::legalizeTriangle(std::vector<Vec3f>* point, Vec3i& face, Vec3f& normal) { GeometricFunc func; Vec3f n=func.computeNormal(point, face); if(n*normal<0) { int temp=face[1]; face[1]=face[2]; face[2]=temp; } }
void ReTriangulation::delaunayTriangulation(std::vector<Vec3f>* point, Vec3i face, std::vector<int>& idx, std::vector<int>& pointOnEdge, std::vector<int>& pointOnFace, std::vector<Vec3i>& triangles, int preNbPoint) { GeometricFunc func; std::vector<std::vector<int>> trianglesAroundEdge; std::vector<std::vector<int>> edgesInTriangle; std::vector<Vec2i> edges; Vec3f normal=func.computeNormal(point, face); triangles.push_back(face); for(int i=0;i<pointOnEdge.size();i++) { for(int j=0;j<triangles.size();j++) { int edgeIdx=-1; for(int k=0;k<3;k++) { Vec3f l1=(*point)[triangles[j][k]]; Vec3f l2=(*point)[triangles[j][(k+1)%3]]; Vec3f p=(*point)[pointOnEdge[i]]; if(func.isPointInLine(l1, l2, p)) { edgeIdx=(k+2)%3; break; } } if(edgeIdx>-1) { //add triangles and edges triangles.push_back(Vec3i(triangles[j][(edgeIdx+1)%3], pointOnEdge[i], triangles[j][edgeIdx])); triangles.push_back(Vec3i(pointOnEdge[i], triangles[j][(edgeIdx+2)%3], triangles[j][edgeIdx])); //remove triangle triangles[j]=triangles[triangles.size()-1]; triangles.pop_back(); break; } } } for(int i=0;i<pointOnFace.size();i++) { int count=0; for(int j=0;j<triangles.size();j++) { int edgeIdx=-1; for(int k=0;k<3;k++) { Vec3f l1=(*point)[triangles[j][k]]; Vec3f l2=(*point)[triangles[j][(k+1)%3]]; Vec3f p=(*point)[pointOnFace[i]]; if(func.isPointInLine(l1, l2, p)) { edgeIdx=(k+2)%3; break; } } if(edgeIdx>-1) { //add triangles and edges triangles.push_back(Vec3i(triangles[j][(edgeIdx+1)%3], pointOnFace[i], triangles[j][edgeIdx])); triangles.push_back(Vec3i(pointOnFace[i], triangles[j][(edgeIdx+2)%3], triangles[j][edgeIdx])); //remove triangle triangles[j]=triangles[triangles.size()-1]; triangles.pop_back(); count++; if(count>1) break; } else if(func.isPointInTri(point, triangles[j], pointOnFace[i])) { //add triangles triangles.push_back(Vec3i(pointOnFace[i], triangles[j][0], triangles[j][1])); triangles.push_back(Vec3i(pointOnFace[i], triangles[j][1], triangles[j][2])); triangles.push_back(Vec3i(pointOnFace[i], triangles[j][2], triangles[j][0])); //remove triangle triangles[j]=triangles[triangles.size()-1]; triangles.pop_back(); int triIdx=triangles.size()-2; legalizeEdge(point, pointOnFace[i], Vec2i(triangles[triIdx][1], triangles[triIdx][2]), triIdx, triangles); triIdx=triangles.size()-1; legalizeEdge(point, pointOnFace[i], Vec2i(triangles[triIdx][1], triangles[triIdx][2]), triIdx, triangles); triIdx=j; legalizeEdge(point, pointOnFace[i], Vec2i(triangles[triIdx][1], triangles[triIdx][2]), triIdx, triangles); break; } } } for(int i=0;i<idx.size();i++) { for(int j=0;j<triangles.size();j++) { for(int k=0;k<3;k++) { if(triangles[j][k]==idx[i]) { triangles[j]=triangles[triangles.size()-1]; triangles.pop_back(); j--; break; } } } } }
int ReTriangulation::legalizeEdge(std::vector<Vec3f>* point, int pointIdx, Vec2i edge, int triIdx, std::vector<Vec3i>& triangles) { GeometricFunc func; int _triIdx; int _pointIdx; bool flag=true; //1. find the triangle that contains the edge for(int i=0;i<triangles.size();i++) { if(func.isTriangleContainEdge(edge, triangles[i])) { if(i!=triIdx) { _triIdx=i; for(int j=0;j<3;j++) { if((triangles[i][j]!=edge[0])&&(triangles[i][j]!=edge[1])) { _pointIdx=triangles[i][j]; break; } } flag=false; break; } } } if(flag) { return 0; } else { Vec3f faceNormal=func.computeNormal(point, triangles[_triIdx]); Vec3f circumCenter=func.computeCircumcenter(point, triangles[_triIdx], faceNormal); float radius=((*point)[edge[0]]-circumCenter).norm(); if(((*point)[pointIdx]-circumCenter).norm()<radius) { Vec3i face1=Vec3i(pointIdx, _pointIdx, edge[0]); Vec3i face2=Vec3i(pointIdx, _pointIdx, edge[1]); Vec3f normal1=func.computeNormal(point, face1); if(normal1*faceNormal<0) { int temp=face1[2]; face1[2]=face1[1]; face1[1]=temp; } else { int temp=face2[2]; face2[2]=face2[1]; face2[1]=temp; } //replace triangles triangles[triIdx]=face1; triangles[_triIdx]=face2; legalizeEdge(point, pointIdx, Vec2i(_pointIdx, edge[0]), triIdx, triangles); legalizeEdge(point, pointIdx, Vec2i(_pointIdx, edge[1]), _triIdx, triangles); } } return 0; }