// get half edges,and save into vector voidgetHalfEdge(PolygonMesh &mesh1, std::vector<myedge> &halfedges_out) { // get halfedge; std::vector<myedge> halfedges; for (int i = 0; i < mesh1.polygons.size(); i++) { int p1 = mesh1.polygons.at(i).vertices[0]; int p2 = mesh1.polygons.at(i).vertices[1]; int p3 = mesh1.polygons.at(i).vertices[2]; myedge e1(p1, p2); myedge e2(p2, p3); myedge e3(p3, p1); if (e1.edge_valid == 0) halfedges.push_back(e1); if (e2.edge_valid == 0) halfedges.push_back(e2); if (e3.edge_valid == 0) halfedges.push_back(e3); } std::vector<myedge>::iterator begin_pos = halfedges.begin(); std::vector<myedge>::iterator end_pos = halfedges.end(); std::sort(halfedges.begin(), halfedges.end(), isInfront); // above process is to get all edges(includeing halfedges and whole edges) and take them in order // if the edgd showed twice, it is not the halfedges
int recursion_times = 0; voidDeleteEndPoint(Lgraph gp, int searchsize) { cout << "Recursion times is: " << recursion_times << endl; std::vector<int> deleteID; // 由于find的得到的是第几个节点,因此得到n还需+1,因此链表下标从0开始 for (int i1 = 0; i1 < searchsize; i1++) { int len = getlen(gp->G[i1]); if (len==1) { deleteID.push_back(i1); } } if (deleteID.size() != 0) { for (int i = 0; i < deleteID.size(); i++) { for (int j = 5485; j < searchsize; j++) { int len = getlen(gp->G[j]);//当邻接表表长为0的时候说明是空表, if(len==0) continue; auto temp = delete_Vertex(deleteID.at(i), gp->G[j].FirstEdge); gp->G[j].FirstEdge = temp; gp->G[deleteID.at(i)].FirstEdge = NULL; /*if (gp->G[j].FirstEdge->Next == NULL) gp->G[j].FirstEdge = NULL;*/ } } recursion_times++; DeleteEndPoint(gp, searchsize); } else return;
}
voidgetHolesmap(std::vector<myedge> &halfedges, Lgraph &ph, std::vector<std::vector<int>> &holemap2) { // save sa adjacent list std::vector<int>pts; for (int i = 0; i < halfedges.size(); i++) { pts.push_back(halfedges.at(i).p1id); pts.push_back(halfedges.at(i).p2id); } sort(pts.begin(), pts.end()); pts.erase(unique(pts.begin(), pts.end()), pts.end()); int searchSize = FindMaxValue(pts);
Lgraph graph; graph = CreatGraph(pts.size()); graph->Ne = halfedges.size(); if (graph->Ne != 0) { for (int i = 0; i < graph->Ne; i++) { InsertEdge(graph, halfedges.at(i)); } }
// delete end point using recursion DeleteEndPoint(graph, searchSize); ph = graph;
std::vector<int> lens; int len4 = 0; int len6 = 0; for (int i = 0; i < searchSize; i++) { int lentep = getlen(ph->G[i]); if (lentep != 0) { lens.push_back(lentep); } else continue;; if (lentep == 4) { len4++; } if (lentep == 6) { len6++; } } cout << "Number of points have 4 adjacent points: " << len4 << endl; cout << "Number of points have 6 adjacent points: " << len6 << endl; }