void TriMesh::buildConnectivity() { // skip // Use the algorithm from the lecture to categorize the edges into inner, boundary or non-manifold // Set the twin edge appropriately to the category of the current edge // For each node take its leading halfedge and rewind (using getVtxRingPrev) until: // - We get the one that we started with (no need to do anything) // - We get NULL - then the previous choice should be used as the nodes leading halfedge // unskip std::vector<SortElement> helper = std::vector<SortElement>(); for(int i = 0; i < m_halfedges.size(); i++){ helper.push_back(m_halfedges[i]); } std::sort(helper.begin(), helper.end()); int i,j; //Loop through all edges for(j=0; j<helper.size(); j++){ //Find i so that i and i+1 are different edges for(i=j; i<helper.size()-1; i++){ if(helper[i].m_a != helper[i+1].m_a || helper[i].m_b != helper[i+1].m_b){ break; } } if(i==j){ helper[j].m_he->m_twin_ = NULL; // helper[j] points to a boundary edge } else if (i==j+1){ helper[i].m_he->m_twin_ = helper[j].m_he; helper[j].m_he->m_twin_ = helper[i].m_he; // connect the triangles of helper[i] and helper[j] } else{ std::cout << "Non-manifold mesh!" << std::endl; } j = i; } for (int i = 0; i < m_nodes.size(); i++){ HalfEdge* beginLead = m_nodes[i].getLeadingHalfEdge(); HalfEdge* tempLead = m_nodes[i].getLeadingHalfEdge(); while(true){ HalfEdge* rewindHe = tempLead->getVtxRingPrev(); if (rewindHe == NULL){ m_nodes[i].m_he_ = tempLead; break; } else if (rewindHe == beginLead) break; tempLead = rewindHe; } } }