Skip to content

Commit 855a6ea

Browse files
committed
feat(mesh-filters): start meshtoGeogramMesh
1 parent 04c33be commit 855a6ea

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

packages/mesh-filters/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ FetchContent_Declare(
6868

6969
FetchContent_MakeAvailable(pmp geogram)
7070
include_directories(${pmp_SOURCE_DIR}/src)
71+
include_directories(${geogram_SOURCE_DIR}/src/lib)
7172

7273
foreach(pipeline geogram-conversion)
7374
# foreach(pipeline mesh-filters mesh-filters-sigma gaussian-kernel-radius mesh-filters-bin-shrink mesh-filters-label-image)
7475
add_executable(${pipeline} ${pipeline}.cxx)
75-
target_link_libraries(${pipeline} PUBLIC ${ITK_LIBRARIES} pmp)
76+
target_link_libraries(${pipeline} PUBLIC ${ITK_LIBRARIES} geogram)
7677
target_include_directories(${pipeline} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7778
endforeach()
7879

packages/mesh-filters/geogram-conversion.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "itkOutputMesh.h"
2222
#include "itkPipeline.h"
2323

24+
#include "itkmeshToGeogramMesh.h"
25+
2426
int main( int argc, char * argv[] )
2527
{
2628
itk::wasm::Pipeline pipeline("mesh-read-write-test", "A test for reading and writing meshes", argc, argv);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
#ifndef itkmeshToGeogramMesh_h
19+
#define itkmeshToGeogramMesh_h
20+
21+
#include <memory>
22+
23+
#include "geogram/mesh/mesh.h"
24+
25+
namespace itk
26+
{
27+
28+
template <typename TMesh>
29+
auto
30+
meshToGeogramMesh(const TMesh * itkMesh) -> std::unique_ptr<GEO::Mesh>
31+
{
32+
using MeshType = TMesh;
33+
static constexpr unsigned int Dimension = MeshType::PointDimension;
34+
static constexpr bool SinglePrecision = std::is_same<typename MeshType::CoordRepType, float>::value;
35+
std::unique_ptr<GEO::Mesh> geoMesh = std::make_unique<GEO::Mesh>(Dimension, SinglePrecision);
36+
37+
// Copy vertices
38+
auto points = itkMesh->GetPoints();
39+
geoMesh->vertices.create_vertices(points->Size());
40+
41+
for(auto it = points->Begin(); it != points->End(); ++it)
42+
{
43+
const auto& point = it.Value();
44+
GEO::index_t v = it.Index();
45+
for (unsigned int d = 0; d < Dimension; ++d)
46+
{
47+
geoMesh->vertices.point(v)[d] = point[d];
48+
}
49+
}
50+
51+
// Copy faces/cells
52+
auto cells = itkMesh->GetCells();
53+
for(auto it = cells->Begin(); it != cells->End(); ++it)
54+
{
55+
const auto& cell = it.Value();
56+
GEO::vector<GEO::index_t> vertices;
57+
for(auto* pit = cell->PointIdsBegin(); pit != cell->PointIdsEnd(); ++pit) {
58+
vertices.push_back(*pit);
59+
}
60+
geoMesh->facets.create_polygon(vertices);
61+
}
62+
63+
return geoMesh;
64+
}
65+
66+
} // namespace itk
67+
68+
#endif // itkmeshToGeogramMesh_h

0 commit comments

Comments
 (0)