From ef240c89c6292ae046bd00843ed05a872ee5d833 Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Fri, 10 Jan 2025 15:07:04 +0100 Subject: [PATCH] Update alpha wrapping to work on point clouds --- vespa/Algorithm/vtkCGALPolyDataAlgorithm.cxx | 4 +--- .../Testing/TestPMPAlphaWrapping.cxx | 20 +++++++++++++------ vespa/PolygonMeshProcessing/vtk.module | 1 + .../vtkCGALAlphaWrapping.cxx | 20 +++++++++++++++++-- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/vespa/Algorithm/vtkCGALPolyDataAlgorithm.cxx b/vespa/Algorithm/vtkCGALPolyDataAlgorithm.cxx index dec3f9b..72da294 100644 --- a/vespa/Algorithm/vtkCGALPolyDataAlgorithm.cxx +++ b/vespa/Algorithm/vtkCGALPolyDataAlgorithm.cxx @@ -49,9 +49,7 @@ bool vtkCGALPolyDataAlgorithm::toCGAL(vtkPolyData* vtkMesh, Vespa_soup* cgalMesh vtkIdList* ids = cit->GetPointIds(); vtkIdType nbIds = cit->GetNumberOfPoints(); - cgalMesh->faces[cid].reserve(3); // mostly triangles - - std::vector cell(nbIds); + cgalMesh->faces[cid].reserve(ids->GetNumberOfIds()); for (vtkIdType i = 0; i < nbIds; i++) { cgalMesh->faces[cid].emplace_back(ids->GetId(i)); diff --git a/vespa/PolygonMeshProcessing/Testing/TestPMPAlphaWrapping.cxx b/vespa/PolygonMeshProcessing/Testing/TestPMPAlphaWrapping.cxx index 40a816b..a89c224 100644 --- a/vespa/PolygonMeshProcessing/Testing/TestPMPAlphaWrapping.cxx +++ b/vespa/PolygonMeshProcessing/Testing/TestPMPAlphaWrapping.cxx @@ -1,5 +1,4 @@ -#include - +#include #include #include #include @@ -16,15 +15,24 @@ int TestPMPAlphaWrapping(int, char* argv[]) cfname += "/dragon.vtp"; reader->SetFileName(cfname.c_str()); - // Remesh + // Remesh surface + vtkNew aw1; + aw1->SetInputConnection(reader->GetOutputPort()); + + // Remesh point cloud + vtkNew toPC; + toPC->SetInputConnection(aw1->GetOutputPort()); + toPC->SetCellGenerationMode(vtkConvertToPointCloud::VERTEX_CELLS); - vtkNew aw; - aw->SetInputConnection(reader->GetOutputPort()); + // Remesh point cloud + vtkNew aw2; + aw2->SetInputConnection(toPC->GetOutputPort()); + aw2->SetAlpha(2); // Save result vtkNew writer; - writer->SetInputConnection(aw->GetOutputPort()); + writer->SetInputConnection(aw2->GetOutputPort()); writer->SetFileName("alpha_wrapping.vtp"); writer->Write(); diff --git a/vespa/PolygonMeshProcessing/vtk.module b/vespa/PolygonMeshProcessing/vtk.module index 84ab514..b66b032 100644 --- a/vespa/PolygonMeshProcessing/vtk.module +++ b/vespa/PolygonMeshProcessing/vtk.module @@ -9,6 +9,7 @@ DEPENDS TEST_DEPENDS VTK::CommonSystem VTK::FiltersSources + VTK::FiltersPoints VTK::IOInfovis VTK::IOXML VTK::TestingCore diff --git a/vespa/PolygonMeshProcessing/vtkCGALAlphaWrapping.cxx b/vespa/PolygonMeshProcessing/vtkCGALAlphaWrapping.cxx index 54048ef..4fcb341 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALAlphaWrapping.cxx +++ b/vespa/PolygonMeshProcessing/vtkCGALAlphaWrapping.cxx @@ -57,7 +57,6 @@ int vtkCGALAlphaWrapping::RequestData( // Create the surface mesh for CGAL // -------------------------------- - // TODO switch to soup ? (or shrink 1) std::unique_ptr cgalMesh = std::make_unique(); this->toCGAL(input, cgalMesh.get()); @@ -68,7 +67,24 @@ int vtkCGALAlphaWrapping::RequestData( try { - CGAL::alpha_wrap_3(cgalMesh->points, cgalMesh->faces, alpha, offset, cgalOutput->surface); + bool isPointCloud = true; + for (auto& cell : cgalMesh->faces) + { + if (cell.size() > 1) + { + isPointCloud = false; + } + } + + if (isPointCloud) + { + // Specific version when we have only points + CGAL::alpha_wrap_3(cgalMesh->points, alpha, offset, cgalOutput->surface); + } + else + { + CGAL::alpha_wrap_3(cgalMesh->points, cgalMesh->faces, alpha, offset, cgalOutput->surface); + } } catch (std::exception& e) { -- GitLab