@@ -389,6 +389,12 @@ static std::tuple<Eigen::MatrixXd, Eigen::MatrixXi, Eigen::MatrixXd, Eigen::Matr
389389 Eigen::MatrixXi out_F;
390390 Eigen::MatrixXd rem_V;
391391 Eigen::MatrixXi rem_F;
392+
393+ // If either mesh is empty, there can be no shared surface
394+ if (is_empty (src_V, src_F) || is_empty (other_V, other_F)) {
395+ return std::make_tuple (out_V, out_F, src_V, src_F);
396+ }
397+
392398 igl::AABB<Eigen::MatrixXd, 3 > tree;
393399 tree.init (other_V, other_F);
394400
@@ -482,6 +488,10 @@ std::array<Mesh, 3> MeshUtils::shared_boundary_extractor(const Mesh& mesh_l, con
482488 V_r = mesh_r.points ();
483489 F_r = mesh_r.faces ();
484490
491+ if (is_empty (V_l, F_l) || is_empty (V_r, F_r)) {
492+ throw std::runtime_error (" Input mesh is empty. Cannot extract shared boundary from empty meshes" );
493+ }
494+
485495 Eigen::MatrixXd shared_V_l, shared_V_r, rem_V_l, rem_V_r;
486496 Eigen::MatrixXi shared_F_l, shared_F_r, rem_F_l, rem_F_r;
487497 std::tie (shared_V_l, shared_F_l, rem_V_l, rem_F_l) = find_shared_surface (V_l, F_l, V_r, F_r, tol);
@@ -1073,18 +1083,23 @@ vtkSmartPointer<vtkPolyData> MeshUtils::recreate_mesh(vtkSmartPointer<vtkPolyDat
10731083}
10741084
10751085// ---------------------------------------------------------------------------
1076- vtkSmartPointer<vtkPolyData> MeshUtils::repair_mesh (vtkSmartPointer<vtkPolyData> mesh) {
1086+ vtkSmartPointer<vtkPolyData> MeshUtils::repair_mesh (vtkSmartPointer<vtkPolyData> mesh, bool extract_largest ) {
10771087 auto triangle_filter = vtkSmartPointer<vtkTriangleFilter>::New ();
10781088 triangle_filter->SetInputData (mesh);
10791089 triangle_filter->PassLinesOff ();
10801090 triangle_filter->Update ();
10811091
1082- auto connectivity = vtkSmartPointer<vtkPolyDataConnectivityFilter>::New ();
1083- connectivity->SetInputConnection (triangle_filter->GetOutputPort ());
1084- connectivity->SetExtractionModeToLargestRegion ();
1085- connectivity->Update ();
1092+ vtkSmartPointer<vtkPolyData> triangulated = triangle_filter->GetOutput ();
1093+
1094+ if (extract_largest) {
1095+ auto connectivity = vtkSmartPointer<vtkPolyDataConnectivityFilter>::New ();
1096+ connectivity->SetInputData (triangulated);
1097+ connectivity->SetExtractionModeToLargestRegion ();
1098+ connectivity->Update ();
1099+ triangulated = connectivity->GetOutput ();
1100+ }
10861101
1087- auto cleaned = MeshUtils::clean_mesh (connectivity-> GetOutput () );
1102+ auto cleaned = MeshUtils::clean_mesh (triangulated );
10881103
10891104 auto fixed = Mesh (cleaned).fixNonManifold ();
10901105
0 commit comments