ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
tetramesh.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <ecvPointCloud.h>
9 #include <ecvTetraMesh.h>
10 
11 #include "pybind/docstring.h"
14 
15 namespace cloudViewer {
16 namespace geometry {
17 
18 void pybind_tetramesh(py::module &m) {
19  py::class_<TetraMesh, PyGeometry<TetraMesh>, std::shared_ptr<TetraMesh>,
21  trianglemesh(m, "TetraMesh",
22  "TetraMesh class. Tetra mesh contains vertices "
23  "and Tetrahedra represented by the indices to the "
24  "vertices.");
25  py::detail::bind_default_constructor<TetraMesh>(trianglemesh);
26  py::detail::bind_copy_functions<TetraMesh>(trianglemesh);
27  trianglemesh
28  .def(py::init<const std::vector<Eigen::Vector3d> &,
29  const std::vector<Eigen::Vector4i,
31  Vector4i_allocator> &>(),
32  "Create a tetrahedra mesh from vertices and tetra indices",
33  "vertices"_a, "tetras"_a)
34  .def("__repr__",
35  [](const TetraMesh &mesh) {
36  return std::string("TetraMesh with ") +
37  std::to_string(mesh.vertices_.size()) +
38  " points and " +
39  std::to_string(mesh.tetras_.size()) +
40  " tetrahedra.";
41  })
42  .def(py::self + py::self)
43  .def(py::self += py::self)
44  .def("remove_duplicated_vertices",
46  "Function that removes duplicated vertices, i.e., vertices "
47  "that have identical coordinates.")
48  .def("remove_duplicated_tetras", &TetraMesh::RemoveDuplicatedTetras,
49  "Function that removes duplicated tetras, i.e., removes "
50  "tetras that reference the same four vertices, "
51  "independent of their order.")
52  .def("remove_unreferenced_vertices",
54  "This function removes vertices from the tetra mesh that "
55  "are not referenced in any tetra of the mesh.")
56  .def("remove_degenerate_tetras", &TetraMesh::RemoveDegenerateTetras,
57  "Function that removes degenerate tetras, i.e., tetras "
58  "that references a single vertex multiple times in a single "
59  "tetra. They are usually the product of removing "
60  "duplicated vertices.")
61  .def("has_vertices", &TetraMesh::HasVertices,
62  "Returns ``True`` if the mesh contains vertices.")
63  .def("has_tetras", &TetraMesh::HasTetras,
64  "Returns ``True`` if the mesh contains tetras.")
65  .def("extract_triangle_mesh", &TetraMesh::ExtractTriangleMesh,
66  "Function that generates a triangle mesh of the specified "
67  "iso-surface.",
68  "values"_a, "level"_a)
69  .def_static(
70  "create_from_point_cloud", &TetraMesh::CreateFromPointCloud,
71  "Function to create a tetrahedral mesh from a point cloud.",
72  "point_cloud"_a)
73  .def_readwrite("vertices", &TetraMesh::vertices_,
74  "``float64`` array of shape ``(num_vertices, 3)``, "
75  "use ``numpy.asarray()`` to access data: Vertex "
76  "coordinates.")
77  .def_readwrite("tetras", &TetraMesh::tetras_,
78  "``int64`` array of shape ``(num_tetras, 4)``, use "
79  "``numpy.asarray()`` to access data: List of "
80  "tetras denoted by the index of points forming "
81  "the tetra.");
82  docstring::ClassMethodDocInject(m, "TetraMesh", "has_tetras");
83  docstring::ClassMethodDocInject(m, "TetraMesh", "has_vertices");
84  docstring::ClassMethodDocInject(m, "TetraMesh",
85  "remove_duplicated_vertices");
86  docstring::ClassMethodDocInject(m, "TetraMesh", "remove_duplicated_tetras");
87  docstring::ClassMethodDocInject(m, "TetraMesh",
88  "remove_unreferenced_vertices");
89  docstring::ClassMethodDocInject(m, "TetraMesh", "remove_degenerate_tetras");
91  m, "TetraMesh", "extract_triangle_mesh",
92  {{"values",
93  "Vector with a scalar value for each vertex in the tetra mesh"},
94  {"level", "A scalar which defines the level-set to extract"}});
95  docstring::ClassMethodDocInject(m, "TetraMesh", "create_from_point_cloud",
96  {{"point_cloud", "A PointCloud."}});
97 }
98 
99 void pybind_tetramesh_methods(py::module &m) {}
100 
101 } // namespace geometry
102 } // namespace cloudViewer
Tetra mesh contains vertices and tetrahedra represented by the indices to the vertices.
Definition: ecvTetraMesh.h:29
std::vector< Eigen::Vector4i, cloudViewer::utility::Vector4i_allocator > tetras_
List of tetras denoted by the index of points forming the tetra.
Definition: ecvTetraMesh.h:108
std::shared_ptr< ccMesh > ExtractTriangleMesh(const std::vector< double > &values, double level)
Function to extract a triangle mesh of the specified iso-surface at a level This method applies prima...
TetraMesh & RemoveDuplicatedTetras()
Function that removes duplicated tetrahedra, i.e., removes tetrahedra that reference the same four ve...
TetraMesh & RemoveUnreferencedVertices()
This function removes vertices from the tetra mesh that are not referenced in any tetrahedron of the ...
TetraMesh & RemoveDegenerateTetras()
Function that removes degenerate tetrahedra, i.e., tetrahedra that reference a single vertex multiple...
TetraMesh & RemoveDuplicatedVertices()
Function that removes duplicated verties, i.e., vertices that have identical coordinates.
bool HasTetras() const
Returns true if the mesh contains tetras.
Definition: ecvTetraMesh.h:84
static std::tuple< std::shared_ptr< TetraMesh >, std::vector< size_t > > CreateFromPointCloud(const ccPointCloud &point_cloud)
Function that creates a tetrahedral mesh (TetraMeshFactory.cpp). from a point cloud.
bool HasVertices() const
Returns True if the mesh contains vertices.
Definition: ecvMeshBase.h:87
std::vector< Eigen::Vector3d > vertices_
Vertex coordinates.
Definition: ecvMeshBase.h:132
void ClassMethodDocInject(py::module &pybind_module, const std::string &class_name, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:27
void pybind_tetramesh(py::module &m)
Definition: tetramesh.cpp:18
void pybind_tetramesh_methods(py::module &m)
Definition: tetramesh.cpp:99
Eigen::aligned_allocator< Eigen::Vector4i > Vector4i_allocator
Definition: Eigen.h:129
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 4, 1 > Vector4i
Definition: knncpp.h:31
std::string to_string(const T &n)
Definition: Common.h:20