| 26 | } |
| 27 | |
| 28 | bool MeshChecker::is_vertex_manifold() const { |
| 29 | const size_t num_vertices = m_vertices.rows(); |
| 30 | const size_t num_faces = m_faces.rows(); |
| 31 | const size_t vertex_per_face = m_faces.cols(); |
| 32 | |
| 33 | std::vector<std::vector<VectorI> > opposite_edges(num_vertices); |
| 34 | if (vertex_per_face == 3) { |
| 35 | for (size_t i=0; i<num_faces; i++) { |
| 36 | const auto& f = m_faces.row(i); |
| 37 | opposite_edges[f[0]].push_back(Vector2I(f[1], f[2])); |
| 38 | opposite_edges[f[1]].push_back(Vector2I(f[2], f[0])); |
| 39 | opposite_edges[f[2]].push_back(Vector2I(f[0], f[1])); |
| 40 | } |
| 41 | } else if (vertex_per_face == 4) { |
| 42 | for (size_t i=0; i<num_faces; i++) { |
| 43 | const auto& f = m_faces.row(i); |
| 44 | opposite_edges[f[0]].push_back(Vector2I(f[1], f[2])); |
| 45 | opposite_edges[f[0]].push_back(Vector2I(f[2], f[3])); |
| 46 | opposite_edges[f[1]].push_back(Vector2I(f[2], f[3])); |
| 47 | opposite_edges[f[1]].push_back(Vector2I(f[3], f[0])); |
| 48 | opposite_edges[f[2]].push_back(Vector2I(f[3], f[0])); |
| 49 | opposite_edges[f[2]].push_back(Vector2I(f[0], f[1])); |
| 50 | opposite_edges[f[3]].push_back(Vector2I(f[0], f[1])); |
| 51 | opposite_edges[f[3]].push_back(Vector2I(f[1], f[2])); |
| 52 | } |
| 53 | } else { |
| 54 | std::stringstream err_msg; |
| 55 | err_msg << "Vertex manifold check does not support face with " |
| 56 | << vertex_per_face << " vertices."; |
| 57 | throw NotImplementedError(err_msg.str()); |
| 58 | } |
| 59 | |
| 60 | for (const auto& entries: opposite_edges) { |
| 61 | if (entries.empty()) continue; |
| 62 | try { |
| 63 | auto edge_loops = EdgeUtils::chain_edges( |
| 64 | MatrixUtils::rowstack(entries)); |
| 65 | if (edge_loops.size() != 1) return false; |
| 66 | } catch (...) { |
| 67 | return false; |
| 68 | } |
| 69 | } |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | bool MeshChecker::is_edge_manifold() const { |
| 74 | for (auto adj : m_edge_face_adjacency) { |