From ffa865e56edcbd02c76e17393b0b437ed2af6e06 Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Thu, 7 Apr 2022 16:12:08 +0200 Subject: [PATCH 1/8] Simple delaunay --- vespa/PolygonMeshProcessing/CMakeLists.txt | 1 + .../Testing/CMakeLists.txt | 1 + .../Testing/TestDelaunayExecution.cxx | 32 +++++++ .../PolygonMeshProcessing/vtkCGALDelaunay.cxx | 88 +++++++++++++++++++ vespa/PolygonMeshProcessing/vtkCGALDelaunay.h | 34 +++++++ .../vtkCGALPolyDataAlgorithm.cxx | 20 ++--- 6 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx create mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay.cxx create mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay.h diff --git a/vespa/PolygonMeshProcessing/CMakeLists.txt b/vespa/PolygonMeshProcessing/CMakeLists.txt index b25c02e..3971991 100644 --- a/vespa/PolygonMeshProcessing/CMakeLists.txt +++ b/vespa/PolygonMeshProcessing/CMakeLists.txt @@ -2,6 +2,7 @@ set(vtkcgalpmp_files vtkCGALPolyDataAlgorithm vtkCGALBooleanOperation + vtkCGALDelaunay vtkCGALIsotropicRemesher vtkCGALMeshDeformation vtkCGALMeshSubdivision diff --git a/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt b/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt index 1666c15..4677b05 100644 --- a/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt +++ b/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt @@ -35,6 +35,7 @@ endif () vtk_add_test_cxx(vtkCGALCxxTests no_data_tests NO_DATA NO_VALID NO_OUTPUT TestPMPInstance.cxx + TestDelaunayExecution.cxx TestPMPBooleanExecution.cxx TestPMPDeformExecution.cxx TestPMPFairExecution.cxx diff --git a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx new file mode 100644 index 0000000..3c9f7d7 --- /dev/null +++ b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx @@ -0,0 +1,32 @@ +#include + +#include +#include +#include +#include + +#include "vtkCGALDelaunay.h" + +int TestDelaunayExecution(int, char* argv[]) +{ + // Open data + + vtkNew reader; + std::string cfname(argv[1]); + cfname += "/dragon.vtp"; + reader->SetFileName(cfname.c_str()); + + // Remesh + + vtkNew rm; + rm->SetInputConnection(reader->GetOutputPort()); + + // Save result + + vtkNew writer; + writer->SetInputConnection(rm->GetOutputPort()); + writer->SetFileName("delaunay_remesh.vtp"); + writer->Write(); + + return 0; +} diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay.cxx new file mode 100644 index 0000000..d856c8e --- /dev/null +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay.cxx @@ -0,0 +1,88 @@ +#include "vtkCGALDelaunay.h" + +// VTK related includes +#include "vtkDataSet.h" +#include "vtkInformationVector.h" +#include "vtkObjectFactory.h" + +// CGAL related includes +#include +#include + +vtkStandardNewMacro(vtkCGALDelaunay); + +typedef CGAL::Delaunay_triangulation_3 DT3; + +//------------------------------------------------------------------------------ +void vtkCGALDelaunay::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); +} + +//------------------------------------------------------------------------------ +int vtkCGALDelaunay::RequestData( + vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) +{ + // Get the input and output data objects. + vtkPolyData* input = vtkPolyData::GetData(inputVector[0]); + vtkPolyData* output = vtkPolyData::GetData(outputVector); + + // Create the surface mesh for CGAL + // -------------------------------- + + // std::unique_ptr cgalMesh = this->toCGAL(input); + vtkPoints* vtkPts = input->GetPoints(); + vtkIdType nbPts = input->GetNumberOfPoints(); + const auto pointRange = vtk::DataArrayTupleRange<3>(vtkPts->GetData()); + std::vector pts; + pts.reserve(nbPts); + for (const auto pt : pointRange) + { + pts.emplace_back(pt[0], pt[1], pt[2]); + } + + // CGAL Processing + // --------------- + + DT3 dt3(pts.begin(), pts.end()); + + // VTK Output + // ---------- + vtkNew outPts; + const vtkIdType outNPts = dt3.number_of_vertices(); + outPts->Allocate(outNPts); + std::map>, vtkIdType> vmap; + + for (auto vertex : dt3.finite_vertex_handles()) + { + vtkIdType id = + outPts->InsertNextPoint(vertex->point()[0], vertex->point()[1], vertex->point()[2]); + vmap[vertex->point()] = id; + } + outPts->Squeeze(); + + // cells + vtkNew cells; + cells->AllocateEstimate(dt3.number_of_cells(), 3); + + for (auto face : dt3.finite_cell_handles()) + { + vtkNew ids; + // for (auto edge : halfedges_around_face(halfedge(face, cgalMesh->surface), cgalMesh->surface)) + // { + // ids->InsertNextId(vmap[source(edge, cgalMesh->surface)]); + // } + ids->InsertNextId(vmap[face->vertex(0)->point()]); + ids->InsertNextId(vmap[face->vertex(1)->point()]); + ids->InsertNextId(vmap[face->vertex(2)->point()]); + + cells->InsertNextCell(ids); + } + cells->Squeeze(); + + // VTK dataset + output->SetPoints(outPts); + output->SetPolys(cells); + + return 1; +} diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay.h b/vespa/PolygonMeshProcessing/vtkCGALDelaunay.h new file mode 100644 index 0000000..654e5b0 --- /dev/null +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay.h @@ -0,0 +1,34 @@ +/** + * @class vtkCGALDelaunay + * @brief remesh using the CGAL delaunay + * + * vtkCGALDelaunay is a filter allowing to remesh + * ... + */ + +#ifndef vtkCGALDelaunay_h +#define vtkCGALDelaunay_h + +#include "vtkCGALPolyDataAlgorithm.h" + +#include "vtkCGALPMPModule.h" // For export macro + +class VTKCGALPMP_EXPORT vtkCGALDelaunay : public vtkCGALPolyDataAlgorithm +{ +public: + static vtkCGALDelaunay* New(); + vtkTypeMacro(vtkCGALDelaunay, vtkCGALPolyDataAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent) override; + +protected: + vtkCGALDelaunay() = default; + ~vtkCGALDelaunay() override = default; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + +private: + vtkCGALDelaunay(const vtkCGALDelaunay&) = delete; + void operator=(const vtkCGALDelaunay&) = delete; +}; + +#endif diff --git a/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.cxx b/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.cxx index c115936..caf1f8e 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.cxx +++ b/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.cxx @@ -38,26 +38,18 @@ std::unique_ptr vtkCGALPolyDataAlgorithm::toCGAL(vtkPolyData* vtkMesh } // Cells - std::array tri; - auto cit = vtk::TakeSmartPointer(vtkMesh->NewCellIterator()); for (cit->InitTraversal(); !cit->IsDoneWithTraversal(); cit->GoToNextCell()) { - // Sanity check - if (cit->GetCellType() != VTK_TRIANGLE) - { - vtkIdType id = cit->GetCellId(); - vtkErrorMacro("Cell " << id << " is not a triangle. Abort."); - return 0; - } - - // Add the triangle + // Add the cell vtkIdList* ids = cit->GetPointIds(); - for (vtkIdType i = 0; i < 3; i++) + vtkIdType nbIds = cit->GetNumberOfPoints(); + std::vector cell(nbIds); + for (vtkIdType i = 0; i < nbIds; i++) { - tri[i] = surfaceVertices[ids->GetId(i)]; + cell[i] = surfaceVertices[ids->GetId(i)]; } - CGAL::Euler::add_face(tri, cgalMesh->surface); + CGAL::Euler::add_face(cell, cgalMesh->surface); } return cgalMesh; -- GitLab From 757139a70d5f81cc003bc736da19361eaf952a8f Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Fri, 8 Apr 2022 11:26:10 +0200 Subject: [PATCH 2/8] 2D / 3D --- vespa/PolygonMeshProcessing/CMakeLists.txt | 3 +- .../Testing/TestDelaunayExecution.cxx | 33 ++++-- vespa/PolygonMeshProcessing/vtkCGALDelaunay.h | 34 ------ .../vtkCGALDelaunay2.cxx | 108 ++++++++++++++++++ .../PolygonMeshProcessing/vtkCGALDelaunay2.h | 34 ++++++ ...kCGALDelaunay.cxx => vtkCGALDelaunay3.cxx} | 14 +-- .../PolygonMeshProcessing/vtkCGALDelaunay3.h | 34 ++++++ 7 files changed, 206 insertions(+), 54 deletions(-) delete mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay.h create mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx create mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h rename vespa/PolygonMeshProcessing/{vtkCGALDelaunay.cxx => vtkCGALDelaunay3.cxx} (82%) create mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h diff --git a/vespa/PolygonMeshProcessing/CMakeLists.txt b/vespa/PolygonMeshProcessing/CMakeLists.txt index 3971991..837b227 100644 --- a/vespa/PolygonMeshProcessing/CMakeLists.txt +++ b/vespa/PolygonMeshProcessing/CMakeLists.txt @@ -2,7 +2,8 @@ set(vtkcgalpmp_files vtkCGALPolyDataAlgorithm vtkCGALBooleanOperation - vtkCGALDelaunay + vtkCGALDelaunay2 + vtkCGALDelaunay3 vtkCGALIsotropicRemesher vtkCGALMeshDeformation vtkCGALMeshSubdivision diff --git a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx index 3c9f7d7..34d5c1f 100644 --- a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx +++ b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx @@ -5,27 +5,42 @@ #include #include -#include "vtkCGALDelaunay.h" +#include "vtkCGALDelaunay2.h" +#include "vtkCGALDelaunay3.h" int TestDelaunayExecution(int, char* argv[]) { // Open data - vtkNew reader; - std::string cfname(argv[1]); - cfname += "/dragon.vtp"; - reader->SetFileName(cfname.c_str()); + vtkNew reader3; + std::string cfname3(argv[1]); + cfname3 += "/dragon.vtp"; + reader3->SetFileName(cfname3.c_str()); + + + vtkNew reader2; + std::string cfname2(argv[1]); + cfname2 += "/pts.vtp"; + reader2->SetFileName(cfname2.c_str()); // Remesh - vtkNew rm; - rm->SetInputConnection(reader->GetOutputPort()); + vtkNew rm2; + rm2->SetInputConnection(reader2->GetOutputPort()); + + vtkNew rm3; + rm3->SetInputConnection(reader3->GetOutputPort()); // Save result vtkNew writer; - writer->SetInputConnection(rm->GetOutputPort()); - writer->SetFileName("delaunay_remesh.vtp"); + + writer->SetInputConnection(rm2->GetOutputPort()); + writer->SetFileName("delaunay2_remesh.vtp"); + writer->Write(); + + writer->SetInputConnection(rm3->GetOutputPort()); + writer->SetFileName("delaunay3_remesh.vtp"); writer->Write(); return 0; diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay.h b/vespa/PolygonMeshProcessing/vtkCGALDelaunay.h deleted file mode 100644 index 654e5b0..0000000 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @class vtkCGALDelaunay - * @brief remesh using the CGAL delaunay - * - * vtkCGALDelaunay is a filter allowing to remesh - * ... - */ - -#ifndef vtkCGALDelaunay_h -#define vtkCGALDelaunay_h - -#include "vtkCGALPolyDataAlgorithm.h" - -#include "vtkCGALPMPModule.h" // For export macro - -class VTKCGALPMP_EXPORT vtkCGALDelaunay : public vtkCGALPolyDataAlgorithm -{ -public: - static vtkCGALDelaunay* New(); - vtkTypeMacro(vtkCGALDelaunay, vtkCGALPolyDataAlgorithm); - void PrintSelf(ostream& os, vtkIndent indent) override; - -protected: - vtkCGALDelaunay() = default; - ~vtkCGALDelaunay() override = default; - - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; - -private: - vtkCGALDelaunay(const vtkCGALDelaunay&) = delete; - void operator=(const vtkCGALDelaunay&) = delete; -}; - -#endif diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx new file mode 100644 index 0000000..0be002d --- /dev/null +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx @@ -0,0 +1,108 @@ +#include "vtkCGALDelaunay2.h" + +// VTK related includes +#include "vtkDataSet.h" +#include "vtkInformationVector.h" +#include "vtkObjectFactory.h" + +// CGAL related includes +#include + +vtkStandardNewMacro(vtkCGALDelaunay2); + +typedef CGAL::Delaunay_triangulation_2 DT2; + +//------------------------------------------------------------------------------ +void vtkCGALDelaunay2::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); +} + +//------------------------------------------------------------------------------ +int vtkCGALDelaunay2::RequestData( + vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) +{ + // Get the input and output data objects. + vtkPolyData* input = vtkPolyData::GetData(inputVector[0]); + vtkPolyData* output = vtkPolyData::GetData(outputVector); + + // Create the surface mesh for CGAL + // -------------------------------- + + vtkPoints* vtkPts = input->GetPoints(); + vtkIdType nbPts = input->GetNumberOfPoints(); + vtkDataArray* ptsArr = vtkPts->GetData(); + const auto pointRange = vtk::DataArrayTupleRange<3>(ptsArr); + + double rangeVal[3]; + for (int i = 0; i < 3; i++) + { + double range[2]; + ptsArr->GetRange(range, i); + rangeVal[i] = range[1] - range[0]; + } + + if (rangeVal[0] && rangeVal[1] && rangeVal[2]) + { + vtkErrorMacro("This dataset is 3D"); + } + int d1 = 0, d2 = 1; // z null + if (!rangeVal[0]) + { + d1 = 1; + d2 = 2; + } + if (!rangeVal[1]) + { + d1 = 0; + d2 = 2; + } + + std::vector pts; + pts.reserve(nbPts); + for (const auto pt : pointRange) + { + pts.emplace_back(pt[d1], pt[d2]); + } + + // CGAL Processing + // --------------- + + DT2 dt2(pts.begin(), pts.end()); + + // VTK Output + // ---------- + vtkNew outPts; + const vtkIdType outNPts = dt2.number_of_vertices(); + outPts->Allocate(outNPts); + std::map>, vtkIdType> vmap; + + for (auto vertex : dt2.finite_vertex_handles()) + { + vtkIdType id = + outPts->InsertNextPoint(vertex->point()[0], vertex->point()[1], vertex->point()[2]); + vmap[vertex->point()] = id; + } + outPts->Squeeze(); + + // cells + vtkNew cells; + cells->AllocateEstimate(dt2.number_of_faces(), 3); + + for (auto face : dt2.finite_face_handles()) + { + vtkNew ids; + ids->InsertNextId(vmap[face->vertex(0)->point()]); + ids->InsertNextId(vmap[face->vertex(1)->point()]); + ids->InsertNextId(vmap[face->vertex(2)->point()]); + + cells->InsertNextCell(ids); + } + cells->Squeeze(); + + // VTK dataset + output->SetPoints(outPts); + output->SetPolys(cells); + + return 1; +} diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h new file mode 100644 index 0000000..556d157 --- /dev/null +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h @@ -0,0 +1,34 @@ +/** + * @class vtkCGALDelaunay2 + * @brief remesh using the CGAL delaunay + * + * vtkCGALDelaunay2 is a filter allowing to remesh + * ... + */ + +#ifndef vtkCGALDelaunay2_h +#define vtkCGALDelaunay2_h + +#include "vtkCGALPolyDataAlgorithm.h" + +#include "vtkCGALPMPModule.h" // For export macro + +class VTKCGALPMP_EXPORT vtkCGALDelaunay2 : public vtkCGALPolyDataAlgorithm +{ +public: + static vtkCGALDelaunay2* New(); + vtkTypeMacro(vtkCGALDelaunay2, vtkCGALPolyDataAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent) override; + +protected: + vtkCGALDelaunay2() = default; + ~vtkCGALDelaunay2() override = default; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + +private: + vtkCGALDelaunay2(const vtkCGALDelaunay2&) = delete; + void operator=(const vtkCGALDelaunay2&) = delete; +}; + +#endif diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.cxx similarity index 82% rename from vespa/PolygonMeshProcessing/vtkCGALDelaunay.cxx rename to vespa/PolygonMeshProcessing/vtkCGALDelaunay3.cxx index d856c8e..1929e35 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay.cxx +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.cxx @@ -1,4 +1,4 @@ -#include "vtkCGALDelaunay.h" +#include "vtkCGALDelaunay3.h" // VTK related includes #include "vtkDataSet.h" @@ -7,20 +7,19 @@ // CGAL related includes #include -#include -vtkStandardNewMacro(vtkCGALDelaunay); +vtkStandardNewMacro(vtkCGALDelaunay3); typedef CGAL::Delaunay_triangulation_3 DT3; //------------------------------------------------------------------------------ -void vtkCGALDelaunay::PrintSelf(ostream& os, vtkIndent indent) +void vtkCGALDelaunay3::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); } //------------------------------------------------------------------------------ -int vtkCGALDelaunay::RequestData( +int vtkCGALDelaunay3::RequestData( vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) { // Get the input and output data objects. @@ -30,7 +29,6 @@ int vtkCGALDelaunay::RequestData( // Create the surface mesh for CGAL // -------------------------------- - // std::unique_ptr cgalMesh = this->toCGAL(input); vtkPoints* vtkPts = input->GetPoints(); vtkIdType nbPts = input->GetNumberOfPoints(); const auto pointRange = vtk::DataArrayTupleRange<3>(vtkPts->GetData()); @@ -68,10 +66,6 @@ int vtkCGALDelaunay::RequestData( for (auto face : dt3.finite_cell_handles()) { vtkNew ids; - // for (auto edge : halfedges_around_face(halfedge(face, cgalMesh->surface), cgalMesh->surface)) - // { - // ids->InsertNextId(vmap[source(edge, cgalMesh->surface)]); - // } ids->InsertNextId(vmap[face->vertex(0)->point()]); ids->InsertNextId(vmap[face->vertex(1)->point()]); ids->InsertNextId(vmap[face->vertex(2)->point()]); diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h b/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h new file mode 100644 index 0000000..287c0ad --- /dev/null +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h @@ -0,0 +1,34 @@ +/** + * @class vtkCGALDelaunay3 + * @brief remesh using the CGAL delaunay + * + * vtkCGALDelaunay3 is a filter allowing to remesh + * ... + */ + +#ifndef vtkCGALDelaunay3_h +#define vtkCGALDelaunay3_h + +#include "vtkCGALPolyDataAlgorithm.h" + +#include "vtkCGALPMPModule.h" // For export macro + +class VTKCGALPMP_EXPORT vtkCGALDelaunay3 : public vtkCGALPolyDataAlgorithm +{ +public: + static vtkCGALDelaunay3* New(); + vtkTypeMacro(vtkCGALDelaunay3, vtkCGALPolyDataAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent) override; + +protected: + vtkCGALDelaunay3() = default; + ~vtkCGALDelaunay3() override = default; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + +private: + vtkCGALDelaunay3(const vtkCGALDelaunay3&) = delete; + void operator=(const vtkCGALDelaunay3&) = delete; +}; + +#endif -- GitLab From 65a86a8416bf25f8ff816547aae667bfa3774fd1 Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Thu, 28 Apr 2022 17:32:30 +0200 Subject: [PATCH 3/8] 2D delaunay support 3D surfaces --- .../Testing/TestDelaunayExecution.cxx | 19 ++-- .../vtkCGALDelaunay2.cxx | 104 ++++++++++++++---- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx index 34d5c1f..3d22819 100644 --- a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx +++ b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx @@ -12,11 +12,10 @@ int TestDelaunayExecution(int, char* argv[]) { // Open data - vtkNew reader3; - std::string cfname3(argv[1]); - cfname3 += "/dragon.vtp"; - reader3->SetFileName(cfname3.c_str()); - + // vtkNew reader3; + // std::string cfname3(argv[1]); + // cfname3 += "/dragon.vtp"; + // reader3->SetFileName(cfname3.c_str()); vtkNew reader2; std::string cfname2(argv[1]); @@ -28,8 +27,8 @@ int TestDelaunayExecution(int, char* argv[]) vtkNew rm2; rm2->SetInputConnection(reader2->GetOutputPort()); - vtkNew rm3; - rm3->SetInputConnection(reader3->GetOutputPort()); + // vtkNew rm3; + // rm3->SetInputConnection(reader3->GetOutputPort()); // Save result @@ -39,9 +38,9 @@ int TestDelaunayExecution(int, char* argv[]) writer->SetFileName("delaunay2_remesh.vtp"); writer->Write(); - writer->SetInputConnection(rm3->GetOutputPort()); - writer->SetFileName("delaunay3_remesh.vtp"); - writer->Write(); + // writer->SetInputConnection(rm3->GetOutputPort()); + // writer->SetFileName("delaunay3_remesh.vtp"); + // writer->Write(); return 0; } diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx index 0be002d..448c09c 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx @@ -1,16 +1,22 @@ #include "vtkCGALDelaunay2.h" // VTK related includes +#include "vtkCellArrayIterator.h" #include "vtkDataSet.h" +#include "vtkIdList.h" #include "vtkInformationVector.h" #include "vtkObjectFactory.h" // CGAL related includes -#include +#include +#include +#include vtkStandardNewMacro(vtkCGALDelaunay2); -typedef CGAL::Delaunay_triangulation_2 DT2; +using CGAL_Proj_Kernel = CGAL::Projection_traits_3; +using CDT2 = CGAL::Constrained_Delaunay_triangulation_2; //------------------------------------------------------------------------------ void vtkCGALDelaunay2::PrintSelf(ostream& os, vtkIndent indent) @@ -42,54 +48,106 @@ int vtkCGALDelaunay2::RequestData( rangeVal[i] = range[1] - range[0]; } + std::cout << "range: " << rangeVal[0] << " " << rangeVal[1] << " " << rangeVal[2] << " " + << std::endl; + if (rangeVal[0] && rangeVal[1] && rangeVal[2]) { vtkErrorMacro("This dataset is 3D"); } - int d1 = 0, d2 = 1; // z null - if (!rangeVal[0]) - { - d1 = 1; - d2 = 2; - } - if (!rangeVal[1]) - { - d1 = 0; - d2 = 2; - } - std::vector pts; + std::vector> pts; pts.reserve(nbPts); for (const auto pt : pointRange) { - pts.emplace_back(pt[d1], pt[d2]); + pts.emplace_back(CDT2::Point(pt[0], pt[1], pt[2]), true); } // CGAL Processing // --------------- - DT2 dt2(pts.begin(), pts.end()); + CGAL_Proj_Kernel proj{ { 0, 1, 1 } }; + CDT2 delaunay(proj); + try + { + // Add constraints (lines and polys) + vtkCellArray* polys = input->GetPolys(); + auto polysIt = vtk::TakeSmartPointer(polys->NewIterator()); + // each poly + for (polysIt->GoToFirstCell(); !polysIt->IsDoneWithTraversal(); polysIt->GoToNextCell()) + { + vtkIdList* p = polysIt->GetCurrentCell(); + std::list poly; + // each segment of poly + for (vtkIdType i = 0; i < p->GetNumberOfIds(); i++) + { + auto point = std::get<0>(pts[p->GetId(i)]); + poly.emplace_back(point); + std::get<1>(pts[p->GetId(i)]) = false; + } + delaunay.insert_constraint(poly.begin(), poly.end(), true); + } + + vtkCellArray* lines = input->GetLines(); + auto linesIt = vtk::TakeSmartPointer(lines->NewIterator()); + // each line + for (linesIt->GoToFirstCell(); !linesIt->IsDoneWithTraversal(); linesIt->GoToNextCell()) + { + // each segment of line + vtkIdList* l = linesIt->GetCurrentCell(); + std::list line; + for (vtkIdType i = 1; i < l->GetNumberOfIds(); i++) + { + if (!std::get<1>(pts[l->GetId(i)])) + { + std::cerr << "invalid line: " << l->GetId(i) << std::endl; + continue; + } + auto point = std::get<0>(pts[l->GetId(i)]); + line.emplace_back(point); + std::get<1>(pts[l->GetId(i)]) = false; + } + delaunay.insert_constraint(line.begin(), line.end()); + } + + // Add points + for (auto point : pts) + { + if (std::get<1>(point)) + { + delaunay.push_back(CDT2::Point(std::get<0>(point))); + } + } + } + catch (std::exception& e) + { + vtkErrorMacro("CGAL Exception: " << e.what()); + return 0; + } // VTK Output // ---------- vtkNew outPts; - const vtkIdType outNPts = dt2.number_of_vertices(); + const vtkIdType outNPts = delaunay.number_of_vertices(); outPts->Allocate(outNPts); - std::map>, vtkIdType> vmap; + std::map vmap; - for (auto vertex : dt2.finite_vertex_handles()) + for (auto vertex : delaunay.finite_vertex_handles()) { - vtkIdType id = - outPts->InsertNextPoint(vertex->point()[0], vertex->point()[1], vertex->point()[2]); + double coords[3]; + coords[0] = vertex->point()[0]; + coords[1] = vertex->point()[1]; + coords[2] = vertex->point()[2]; + vtkIdType id = outPts->InsertNextPoint(coords); vmap[vertex->point()] = id; } outPts->Squeeze(); // cells vtkNew cells; - cells->AllocateEstimate(dt2.number_of_faces(), 3); + cells->AllocateEstimate(delaunay.number_of_faces(), 3); - for (auto face : dt2.finite_face_handles()) + for (auto face : delaunay.finite_face_handles()) { vtkNew ids; ids->InsertNextId(vmap[face->vertex(0)->point()]); -- GitLab From b8f3121addc7aa8e524dfc3d9ef3c928886433f5 Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Thu, 28 Apr 2022 18:41:18 +0200 Subject: [PATCH 4/8] Keep the manual projection that works --- .../Testing/TestDelaunayExecution.cxx | 2 +- .../vtkCGALDelaunay2.cxx | 46 +++++++++++-------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx index 3d22819..a50af98 100644 --- a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx +++ b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx @@ -19,7 +19,7 @@ int TestDelaunayExecution(int, char* argv[]) vtkNew reader2; std::string cfname2(argv[1]); - cfname2 += "/pts.vtp"; + cfname2 += "/shrink_sphere.vtp"; reader2->SetFileName(cfname2.c_str()); // Remesh diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx index 448c09c..fb94d34 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx @@ -8,14 +8,15 @@ #include "vtkObjectFactory.h" // CGAL related includes -#include #include #include vtkStandardNewMacro(vtkCGALDelaunay2); -using CGAL_Proj_Kernel = CGAL::Projection_traits_3; -using CDT2 = CGAL::Constrained_Delaunay_triangulation_2; //------------------------------------------------------------------------------ @@ -48,26 +49,35 @@ int vtkCGALDelaunay2::RequestData( rangeVal[i] = range[1] - range[0]; } - std::cout << "range: " << rangeVal[0] << " " << rangeVal[1] << " " << rangeVal[2] << " " - << std::endl; - if (rangeVal[0] && rangeVal[1] && rangeVal[2]) { vtkErrorMacro("This dataset is 3D"); } + int d1 = 0, d2 = 1, d3 = 2; // z null + if (!rangeVal[0]) + { + d1 = 1; + d2 = 2; + d3 = 0; + } + if (!rangeVal[1]) + { + d1 = 0; + d2 = 2; + d3 = 1; + } - std::vector> pts; + std::vector> pts; pts.reserve(nbPts); for (const auto pt : pointRange) { - pts.emplace_back(CDT2::Point(pt[0], pt[1], pt[2]), true); + pts.emplace_back(CGAL_Kernel::Point_2(pt[d1], pt[d2]), true); } // CGAL Processing // --------------- - CGAL_Proj_Kernel proj{ { 0, 1, 1 } }; - CDT2 delaunay(proj); + CDT2 delaunay; try { // Add constraints (lines and polys) @@ -77,7 +87,7 @@ int vtkCGALDelaunay2::RequestData( for (polysIt->GoToFirstCell(); !polysIt->IsDoneWithTraversal(); polysIt->GoToNextCell()) { vtkIdList* p = polysIt->GetCurrentCell(); - std::list poly; + std::list poly; // each segment of poly for (vtkIdType i = 0; i < p->GetNumberOfIds(); i++) { @@ -94,8 +104,8 @@ int vtkCGALDelaunay2::RequestData( for (linesIt->GoToFirstCell(); !linesIt->IsDoneWithTraversal(); linesIt->GoToNextCell()) { // each segment of line - vtkIdList* l = linesIt->GetCurrentCell(); - std::list line; + vtkIdList* l = linesIt->GetCurrentCell(); + std::list line; for (vtkIdType i = 1; i < l->GetNumberOfIds(); i++) { if (!std::get<1>(pts[l->GetId(i)])) @@ -115,7 +125,7 @@ int vtkCGALDelaunay2::RequestData( { if (std::get<1>(point)) { - delaunay.push_back(CDT2::Point(std::get<0>(point))); + delaunay.push_back(CGAL_Kernel::Point_2(std::get<0>(point))); } } } @@ -130,14 +140,14 @@ int vtkCGALDelaunay2::RequestData( vtkNew outPts; const vtkIdType outNPts = delaunay.number_of_vertices(); outPts->Allocate(outNPts); - std::map vmap; + std::map>, vtkIdType> vmap; for (auto vertex : delaunay.finite_vertex_handles()) { double coords[3]; - coords[0] = vertex->point()[0]; - coords[1] = vertex->point()[1]; - coords[2] = vertex->point()[2]; + coords[d1] = vertex->point()[0]; + coords[d2] = vertex->point()[1]; + coords[d3] = rangeVal[d3 * 2]; vtkIdType id = outPts->InsertNextPoint(coords); vmap[vertex->point()] = id; } -- GitLab From b1263a91bee9be7ab7f4c565bd57c43f336bc74b Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Fri, 29 Apr 2022 10:58:48 +0200 Subject: [PATCH 5/8] refacto for points type --- .../Testing/TestDelaunayExecution.cxx | 2 +- vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx index a50af98..3d22819 100644 --- a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx +++ b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx @@ -19,7 +19,7 @@ int TestDelaunayExecution(int, char* argv[]) vtkNew reader2; std::string cfname2(argv[1]); - cfname2 += "/shrink_sphere.vtp"; + cfname2 += "/pts.vtp"; reader2->SetFileName(cfname2.c_str()); // Remesh diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx index fb94d34..cbd528a 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx @@ -8,6 +8,7 @@ #include "vtkObjectFactory.h" // CGAL related includes +#include #include #include @@ -16,8 +17,7 @@ vtkStandardNewMacro(vtkCGALDelaunay2); // TODO May try to use ProjectionTraits_3 to handle arbitrary 3D surfaces // Look at perf then // caution, a sphere won't work: intersection -using CDT2 = CGAL::Constrained_Delaunay_triangulation_2; +using CDT2 = CGAL::Constrained_Delaunay_triangulation_2; //------------------------------------------------------------------------------ void vtkCGALDelaunay2::PrintSelf(ostream& os, vtkIndent indent) @@ -67,11 +67,11 @@ int vtkCGALDelaunay2::RequestData( d3 = 1; } - std::vector> pts; + std::vector> pts; pts.reserve(nbPts); for (const auto pt : pointRange) { - pts.emplace_back(CGAL_Kernel::Point_2(pt[d1], pt[d2]), true); + pts.emplace_back(CDT2::Point(pt[d1], pt[d2]), true); } // CGAL Processing @@ -87,7 +87,7 @@ int vtkCGALDelaunay2::RequestData( for (polysIt->GoToFirstCell(); !polysIt->IsDoneWithTraversal(); polysIt->GoToNextCell()) { vtkIdList* p = polysIt->GetCurrentCell(); - std::list poly; + std::list poly; // each segment of poly for (vtkIdType i = 0; i < p->GetNumberOfIds(); i++) { @@ -105,7 +105,7 @@ int vtkCGALDelaunay2::RequestData( { // each segment of line vtkIdList* l = linesIt->GetCurrentCell(); - std::list line; + std::list line; for (vtkIdType i = 1; i < l->GetNumberOfIds(); i++) { if (!std::get<1>(pts[l->GetId(i)])) @@ -125,7 +125,7 @@ int vtkCGALDelaunay2::RequestData( { if (std::get<1>(point)) { - delaunay.push_back(CGAL_Kernel::Point_2(std::get<0>(point))); + delaunay.push_back(CDT2::Point(std::get<0>(point))); } } } @@ -140,7 +140,7 @@ int vtkCGALDelaunay2::RequestData( vtkNew outPts; const vtkIdType outNPts = delaunay.number_of_vertices(); outPts->Allocate(outNPts); - std::map>, vtkIdType> vmap; + std::map vmap; for (auto vertex : delaunay.finite_vertex_handles()) { -- GitLab From fc9c3c01f9dee3cbafe5ba9cba2d961506c9cb7e Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Fri, 29 Apr 2022 14:33:55 +0200 Subject: [PATCH 6/8] Remove delaunay 3D as it output tetra --- vespa/PolygonMeshProcessing/CMakeLists.txt | 1 - .../Testing/TestDelaunayExecution.cxx | 15 +--- .../vtkCGALDelaunay2.cxx | 6 +- .../vtkCGALDelaunay3.cxx | 82 ------------------- .../PolygonMeshProcessing/vtkCGALDelaunay3.h | 34 -------- 5 files changed, 5 insertions(+), 133 deletions(-) delete mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay3.cxx delete mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h diff --git a/vespa/PolygonMeshProcessing/CMakeLists.txt b/vespa/PolygonMeshProcessing/CMakeLists.txt index 837b227..e8e086c 100644 --- a/vespa/PolygonMeshProcessing/CMakeLists.txt +++ b/vespa/PolygonMeshProcessing/CMakeLists.txt @@ -3,7 +3,6 @@ set(vtkcgalpmp_files vtkCGALBooleanOperation vtkCGALDelaunay2 - vtkCGALDelaunay3 vtkCGALIsotropicRemesher vtkCGALMeshDeformation vtkCGALMeshSubdivision diff --git a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx index 3d22819..2750f7e 100644 --- a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx +++ b/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx @@ -6,20 +6,14 @@ #include #include "vtkCGALDelaunay2.h" -#include "vtkCGALDelaunay3.h" int TestDelaunayExecution(int, char* argv[]) { // Open data - // vtkNew reader3; - // std::string cfname3(argv[1]); - // cfname3 += "/dragon.vtp"; - // reader3->SetFileName(cfname3.c_str()); - vtkNew reader2; std::string cfname2(argv[1]); - cfname2 += "/pts.vtp"; + cfname2 += "shrink_plane.vtp"; reader2->SetFileName(cfname2.c_str()); // Remesh @@ -27,9 +21,6 @@ int TestDelaunayExecution(int, char* argv[]) vtkNew rm2; rm2->SetInputConnection(reader2->GetOutputPort()); - // vtkNew rm3; - // rm3->SetInputConnection(reader3->GetOutputPort()); - // Save result vtkNew writer; @@ -38,9 +29,5 @@ int TestDelaunayExecution(int, char* argv[]) writer->SetFileName("delaunay2_remesh.vtp"); writer->Write(); - // writer->SetInputConnection(rm3->GetOutputPort()); - // writer->SetFileName("delaunay3_remesh.vtp"); - // writer->Write(); - return 0; } diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx index cbd528a..7de4e39 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx +++ b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx @@ -10,13 +10,13 @@ // CGAL related includes #include #include -#include vtkStandardNewMacro(vtkCGALDelaunay2); -// TODO May try to use ProjectionTraits_3 to handle arbitrary 3D surfaces +// TODO May try to use ProjectionTraits_3 to handle open 3D surfaces // Look at perf then // caution, a sphere won't work: intersection +// caution, infinit loop on some tests using CDT2 = CGAL::Constrained_Delaunay_triangulation_2; //------------------------------------------------------------------------------ @@ -41,6 +41,8 @@ int vtkCGALDelaunay2::RequestData( vtkDataArray* ptsArr = vtkPts->GetData(); const auto pointRange = vtk::DataArrayTupleRange<3>(ptsArr); + // manually handle the plannar coordinate + // should be along an axix double rangeVal[3]; for (int i = 0; i < 3; i++) { diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.cxx b/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.cxx deleted file mode 100644 index 1929e35..0000000 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.cxx +++ /dev/null @@ -1,82 +0,0 @@ -#include "vtkCGALDelaunay3.h" - -// VTK related includes -#include "vtkDataSet.h" -#include "vtkInformationVector.h" -#include "vtkObjectFactory.h" - -// CGAL related includes -#include - -vtkStandardNewMacro(vtkCGALDelaunay3); - -typedef CGAL::Delaunay_triangulation_3 DT3; - -//------------------------------------------------------------------------------ -void vtkCGALDelaunay3::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); -} - -//------------------------------------------------------------------------------ -int vtkCGALDelaunay3::RequestData( - vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) -{ - // Get the input and output data objects. - vtkPolyData* input = vtkPolyData::GetData(inputVector[0]); - vtkPolyData* output = vtkPolyData::GetData(outputVector); - - // Create the surface mesh for CGAL - // -------------------------------- - - vtkPoints* vtkPts = input->GetPoints(); - vtkIdType nbPts = input->GetNumberOfPoints(); - const auto pointRange = vtk::DataArrayTupleRange<3>(vtkPts->GetData()); - std::vector pts; - pts.reserve(nbPts); - for (const auto pt : pointRange) - { - pts.emplace_back(pt[0], pt[1], pt[2]); - } - - // CGAL Processing - // --------------- - - DT3 dt3(pts.begin(), pts.end()); - - // VTK Output - // ---------- - vtkNew outPts; - const vtkIdType outNPts = dt3.number_of_vertices(); - outPts->Allocate(outNPts); - std::map>, vtkIdType> vmap; - - for (auto vertex : dt3.finite_vertex_handles()) - { - vtkIdType id = - outPts->InsertNextPoint(vertex->point()[0], vertex->point()[1], vertex->point()[2]); - vmap[vertex->point()] = id; - } - outPts->Squeeze(); - - // cells - vtkNew cells; - cells->AllocateEstimate(dt3.number_of_cells(), 3); - - for (auto face : dt3.finite_cell_handles()) - { - vtkNew ids; - ids->InsertNextId(vmap[face->vertex(0)->point()]); - ids->InsertNextId(vmap[face->vertex(1)->point()]); - ids->InsertNextId(vmap[face->vertex(2)->point()]); - - cells->InsertNextCell(ids); - } - cells->Squeeze(); - - // VTK dataset - output->SetPoints(outPts); - output->SetPolys(cells); - - return 1; -} diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h b/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h deleted file mode 100644 index 287c0ad..0000000 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay3.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @class vtkCGALDelaunay3 - * @brief remesh using the CGAL delaunay - * - * vtkCGALDelaunay3 is a filter allowing to remesh - * ... - */ - -#ifndef vtkCGALDelaunay3_h -#define vtkCGALDelaunay3_h - -#include "vtkCGALPolyDataAlgorithm.h" - -#include "vtkCGALPMPModule.h" // For export macro - -class VTKCGALPMP_EXPORT vtkCGALDelaunay3 : public vtkCGALPolyDataAlgorithm -{ -public: - static vtkCGALDelaunay3* New(); - vtkTypeMacro(vtkCGALDelaunay3, vtkCGALPolyDataAlgorithm); - void PrintSelf(ostream& os, vtkIndent indent) override; - -protected: - vtkCGALDelaunay3() = default; - ~vtkCGALDelaunay3() override = default; - - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; - -private: - vtkCGALDelaunay3(const vtkCGALDelaunay3&) = delete; - void operator=(const vtkCGALDelaunay3&) = delete; -}; - -#endif -- GitLab From 5a66486922aeecade9993697e49ddc93ed0f2433 Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Fri, 29 Apr 2022 14:34:33 +0200 Subject: [PATCH 7/8] Add delaunay 2D testing data --- Data/Testing/shrink_plane.vtp | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Data/Testing/shrink_plane.vtp diff --git a/Data/Testing/shrink_plane.vtp b/Data/Testing/shrink_plane.vtp new file mode 100644 index 0000000..ae39dc5 --- /dev/null +++ b/Data/Testing/shrink_plane.vtp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dab096e6f0f3fcc8fd02fcec8195d9194d3e5c162bb5d5a401e33b2d0e2ece6c +size 16766 -- GitLab From 26ab5581d9b1409127a0124c30a105e2446ea99b Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Fri, 29 Apr 2022 15:14:04 +0200 Subject: [PATCH 8/8] New architecture with new module --- vespa/Delaunay/CMakeLists.txt | 6 +++ vespa/Delaunay/Testing/CMakeLists.txt | 41 ++++++++++++++++++ .../Testing/TestDelaunayExecution.cxx | 0 vespa/Delaunay/Testing/execute_Delaunay.py | 11 +++++ vespa/Delaunay/Testing/import_Delaunay.py | 4 ++ vespa/Delaunay/vtk.module | 20 +++++++++ .../vtkCGALDelaunay2.cxx | 11 ++--- vespa/Delaunay/vtkCGALDelaunay2.h | 42 +++++++++++++++++++ vespa/PolygonMeshProcessing/CMakeLists.txt | 1 - .../Testing/CMakeLists.txt | 5 +-- .../PolygonMeshProcessing/vtkCGALDelaunay2.h | 34 --------------- .../vtkCGALPolyDataAlgorithm.h | 4 +- 12 files changed, 134 insertions(+), 45 deletions(-) create mode 100644 vespa/Delaunay/CMakeLists.txt create mode 100644 vespa/Delaunay/Testing/CMakeLists.txt rename vespa/{PolygonMeshProcessing => Delaunay}/Testing/TestDelaunayExecution.cxx (100%) create mode 100644 vespa/Delaunay/Testing/execute_Delaunay.py create mode 100644 vespa/Delaunay/Testing/import_Delaunay.py create mode 100644 vespa/Delaunay/vtk.module rename vespa/{PolygonMeshProcessing => Delaunay}/vtkCGALDelaunay2.cxx (97%) create mode 100644 vespa/Delaunay/vtkCGALDelaunay2.h delete mode 100644 vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h diff --git a/vespa/Delaunay/CMakeLists.txt b/vespa/Delaunay/CMakeLists.txt new file mode 100644 index 0000000..689690e --- /dev/null +++ b/vespa/Delaunay/CMakeLists.txt @@ -0,0 +1,6 @@ +set(vtkcgaldelaunay_files + vtkCGALDelaunay2 +) +vtk_module_add_module(vtkCGALDelaunay + CLASSES ${vtkcgaldelaunay_files} +) diff --git a/vespa/Delaunay/Testing/CMakeLists.txt b/vespa/Delaunay/Testing/CMakeLists.txt new file mode 100644 index 0000000..0669684 --- /dev/null +++ b/vespa/Delaunay/Testing/CMakeLists.txt @@ -0,0 +1,41 @@ +if (TARGET VTK::vtkpython) + # import + add_test(NAME "import_Delaunay" + COMMAND + "$" + "${CMAKE_CURRENT_LIST_DIR}/import_Delaunay.py") + set_property(TEST "import_Delaunay" APPEND + PROPERTY + ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/${python_destination}") + if (WIN32) + set(test_path "$ENV{PATH};${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") + string(REPLACE ";" "\;" test_path "${test_path}") + set_property(TEST "import_Delaunay" APPEND + PROPERTY + ENVIRONMENT "PATH=${test_path}") + endif () + + # execute + add_test(NAME "execute_Delaunay" + COMMAND + "$" + "${CMAKE_CURRENT_LIST_DIR}/execute_Delaunay.py") + set_property(TEST "execute_Delaunay" APPEND + PROPERTY + ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/${python_destination}") + if (WIN32) + set(test_path "$ENV{PATH};${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") + string(REPLACE ";" "\;" test_path "${test_path}") + set_property(TEST "execute_Delaunay" APPEND + PROPERTY + ENVIRONMENT "PATH=${test_path}") + endif () +endif () + +vtk_add_test_cxx(vtkCGALDelaunayCxxTests no_data_tests + NO_DATA NO_VALID NO_OUTPUT + TestDelaunayExecution.cxx + + ${PROJECT_SOURCE_DIR}/Data/Testing/ +) +vtk_test_cxx_executable(vtkCGALDelaunayCxxTests no_data_tests) diff --git a/vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx b/vespa/Delaunay/Testing/TestDelaunayExecution.cxx similarity index 100% rename from vespa/PolygonMeshProcessing/Testing/TestDelaunayExecution.cxx rename to vespa/Delaunay/Testing/TestDelaunayExecution.cxx diff --git a/vespa/Delaunay/Testing/execute_Delaunay.py b/vespa/Delaunay/Testing/execute_Delaunay.py new file mode 100644 index 0000000..950f1ae --- /dev/null +++ b/vespa/Delaunay/Testing/execute_Delaunay.py @@ -0,0 +1,11 @@ +from vtk import vtkSphereSource, vtkShrinkPolyData +from vespa import vtkCGALDelaunay + +sp = vtkSphereSource() + +pd = vtkShrinkPolyData() +pd.SetInputConnection(sp.GetOutputPort()) + +d2 = vtkCGALDelaunay.vtkCGALDelaunay2() +d2.SetInputConnection(pd.GetOutputPort()) +d2.Update() diff --git a/vespa/Delaunay/Testing/import_Delaunay.py b/vespa/Delaunay/Testing/import_Delaunay.py new file mode 100644 index 0000000..30a0795 --- /dev/null +++ b/vespa/Delaunay/Testing/import_Delaunay.py @@ -0,0 +1,4 @@ +from vespa import vtkCGALDelaunay + +d2 = vtkCGALDelaunay.vtkCGALDelaunay2() +help(d2) diff --git a/vespa/Delaunay/vtk.module b/vespa/Delaunay/vtk.module new file mode 100644 index 0000000..3ad2b5e --- /dev/null +++ b/vespa/Delaunay/vtk.module @@ -0,0 +1,20 @@ +NAME + vtkCGALDelaunay +DESCRIPTION + "This module contains filters related to the Delaunay module of CGAL." +GROUPS + Meshing +DEPENDS + VTK::CommonCore + VTK::CommonDataModel + VTK::CommonExecutionModel + VTK::FiltersCore + VTK::FiltersExtraction + VTK::FiltersGeometry + CGAL::CGAL +TEST_DEPENDS + VTK::CommonSystem + VTK::FiltersSources + VTK::IOInfovis + VTK::IOXML + VTK::TestingCore diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx b/vespa/Delaunay/vtkCGALDelaunay2.cxx similarity index 97% rename from vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx rename to vespa/Delaunay/vtkCGALDelaunay2.cxx index 7de4e39..b2eca9f 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.cxx +++ b/vespa/Delaunay/vtkCGALDelaunay2.cxx @@ -42,7 +42,7 @@ int vtkCGALDelaunay2::RequestData( const auto pointRange = vtk::DataArrayTupleRange<3>(ptsArr); // manually handle the plannar coordinate - // should be along an axix + // should be along the x, y or z axis double rangeVal[3]; for (int i = 0; i < 3; i++) { @@ -58,9 +58,9 @@ int vtkCGALDelaunay2::RequestData( int d1 = 0, d2 = 1, d3 = 2; // z null if (!rangeVal[0]) { - d1 = 1; - d2 = 2; - d3 = 0; + d1 = 2; + d2 = 0; + d3 = 1; } if (!rangeVal[1]) { @@ -139,6 +139,7 @@ int vtkCGALDelaunay2::RequestData( // VTK Output // ---------- + vtkNew outPts; const vtkIdType outNPts = delaunay.number_of_vertices(); outPts->Allocate(outNPts); @@ -149,7 +150,7 @@ int vtkCGALDelaunay2::RequestData( double coords[3]; coords[d1] = vertex->point()[0]; coords[d2] = vertex->point()[1]; - coords[d3] = rangeVal[d3 * 2]; + coords[d3] = rangeVal[d3]; vtkIdType id = outPts->InsertNextPoint(coords); vmap[vertex->point()] = id; } diff --git a/vespa/Delaunay/vtkCGALDelaunay2.h b/vespa/Delaunay/vtkCGALDelaunay2.h new file mode 100644 index 0000000..55f74d6 --- /dev/null +++ b/vespa/Delaunay/vtkCGALDelaunay2.h @@ -0,0 +1,42 @@ +/** + * @class vtkCGALDelaunay2 + * @brief remesh using the CGAL delaunay + * + * vtkCGALDelaunay2 allows to create plannar delaunay meshes + * from a set of planar points, edges and polygons. + * From now on, the input mesh needs to be planar along x, y or z. + * Constraints should not overlap each others. + */ + +#ifndef vtkCGALDelaunay2_h +#define vtkCGALDelaunay2_h + +#include "vtkPolyDataAlgorithm.h" + +// CGAL includes +#include +#include + +using CGAL_Kernel = CGAL::Simple_cartesian; + +#include "vtkCGALDelaunayModule.h" // For export macro + +class VTKCGALDELAUNAY_EXPORT vtkCGALDelaunay2 : public vtkPolyDataAlgorithm +{ +public: + static vtkCGALDelaunay2* New(); + vtkTypeMacro(vtkCGALDelaunay2, vtkPolyDataAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent) override; + +protected: + vtkCGALDelaunay2() = default; + ~vtkCGALDelaunay2() override = default; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + +private: + vtkCGALDelaunay2(const vtkCGALDelaunay2&) = delete; + void operator=(const vtkCGALDelaunay2&) = delete; +}; + +#endif diff --git a/vespa/PolygonMeshProcessing/CMakeLists.txt b/vespa/PolygonMeshProcessing/CMakeLists.txt index e8e086c..b25c02e 100644 --- a/vespa/PolygonMeshProcessing/CMakeLists.txt +++ b/vespa/PolygonMeshProcessing/CMakeLists.txt @@ -2,7 +2,6 @@ set(vtkcgalpmp_files vtkCGALPolyDataAlgorithm vtkCGALBooleanOperation - vtkCGALDelaunay2 vtkCGALIsotropicRemesher vtkCGALMeshDeformation vtkCGALMeshSubdivision diff --git a/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt b/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt index 4677b05..8bf63c8 100644 --- a/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt +++ b/vespa/PolygonMeshProcessing/Testing/CMakeLists.txt @@ -32,10 +32,9 @@ if (TARGET VTK::vtkpython) endif () endif () -vtk_add_test_cxx(vtkCGALCxxTests no_data_tests +vtk_add_test_cxx(vtkCGALPMPCxxTests no_data_tests NO_DATA NO_VALID NO_OUTPUT TestPMPInstance.cxx - TestDelaunayExecution.cxx TestPMPBooleanExecution.cxx TestPMPDeformExecution.cxx TestPMPFairExecution.cxx @@ -45,4 +44,4 @@ vtk_add_test_cxx(vtkCGALCxxTests no_data_tests ${PROJECT_SOURCE_DIR}/Data/Testing/ ) -vtk_test_cxx_executable(vtkCGALCxxTests no_data_tests) +vtk_test_cxx_executable(vtkCGALPMPCxxTests no_data_tests) diff --git a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h b/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h deleted file mode 100644 index 556d157..0000000 --- a/vespa/PolygonMeshProcessing/vtkCGALDelaunay2.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @class vtkCGALDelaunay2 - * @brief remesh using the CGAL delaunay - * - * vtkCGALDelaunay2 is a filter allowing to remesh - * ... - */ - -#ifndef vtkCGALDelaunay2_h -#define vtkCGALDelaunay2_h - -#include "vtkCGALPolyDataAlgorithm.h" - -#include "vtkCGALPMPModule.h" // For export macro - -class VTKCGALPMP_EXPORT vtkCGALDelaunay2 : public vtkCGALPolyDataAlgorithm -{ -public: - static vtkCGALDelaunay2* New(); - vtkTypeMacro(vtkCGALDelaunay2, vtkCGALPolyDataAlgorithm); - void PrintSelf(ostream& os, vtkIndent indent) override; - -protected: - vtkCGALDelaunay2() = default; - ~vtkCGALDelaunay2() override = default; - - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; - -private: - vtkCGALDelaunay2(const vtkCGALDelaunay2&) = delete; - void operator=(const vtkCGALDelaunay2&) = delete; -}; - -#endif diff --git a/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.h b/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.h index e30b180..abb0a4b 100644 --- a/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.h +++ b/vespa/PolygonMeshProcessing/vtkCGALPolyDataAlgorithm.h @@ -17,14 +17,14 @@ #include #include -#include "vtkCGALPMPModule.h" // For export macro - using CGAL_Kernel = CGAL::Simple_cartesian; using CGAL_Surface = CGAL::Surface_mesh; using Graph_Verts = boost::graph_traits::vertex_descriptor; using Graph_Faces = boost::graph_traits::face_descriptor; using Graph_Coord = boost::property_map::type; +#include "vtkCGALPMPModule.h" // For export macro + // Container for CGAL related info struct CGAL_Mesh { -- GitLab