ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
geometry.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 "t/geometry/Geometry.h"
9 
10 #include <pybind11/stl.h>
11 #include <pybind11/stl_bind.h>
12 
13 #include <deque>
14 #include <vector>
15 
17 #include "pybind/docstring.h"
19 
20 namespace cloudViewer {
21 namespace t {
22 namespace geometry {
23 
24 void pybind_geometry_class(py::module& m) {
25  // cloudViewer.t.geometry.Geometry
26  py::class_<Geometry, PyGeometry<Geometry>, std::shared_ptr<Geometry>>
27  geometry(m, "Geometry", "The base geometry class.");
28 
29  geometry.def("clear", &Geometry::Clear,
30  "Clear all elements in the geometry.")
31  .def("is_empty", &Geometry::IsEmpty,
32  "Returns ``True`` iff the geometry is empty.");
33  geometry.def_property_readonly("device", &Geometry::GetDevice,
34  "Returns the device of the geometry.");
35  geometry.def_property_readonly("is_cpu", &Geometry::IsCPU,
36  "Returns true if the geometry is on CPU.");
37  geometry.def_property_readonly("is_cuda", &Geometry::IsCUDA,
38  "Returns true if the geometry is on CUDA.");
39  docstring::ClassMethodDocInject(m, "Geometry", "clear");
40  docstring::ClassMethodDocInject(m, "Geometry", "is_empty");
41 }
42 
43 void pybind_geometry(py::module& m) {
44  py::module m_submodule = m.def_submodule(
45  "geometry", "Tensor-based geometry defining module.");
46  py::bind_vector<std::vector<Metric>>(m_submodule, "VectorMetric");
47 
48  py::native_enum<Metric>(
49  m_submodule, "Metric", "enum.Enum",
50  "Enum for metrics for comparing point clouds and triangle meshes.")
51  .value("ChamferDistance", Metric::ChamferDistance,
52  "Chamfer Distance")
53  .value("HausdorffDistance", Metric::HausdorffDistance,
54  "Hausdorff Distance")
55  .value("FScore", Metric::FScore, "F-Score")
56  .export_values()
57  .finalize();
58  py::class_<MetricParameters> metric_parameters(
59  m_submodule, "MetricParameters",
60  "Holder for various parameters required by metrics.");
61 
62  py::native_enum<MethodOBBCreate>(
63  m_submodule, "MethodOBBCreate", "enum.Enum",
64  "Methods for creating oriented bounding boxes.")
65  .value("PCA", MethodOBBCreate::PCA)
66  .value("MINIMAL_APPROX", MethodOBBCreate::MINIMAL_APPROX)
67  .value("MINIMAL_JYLANKI", MethodOBBCreate::MINIMAL_JYLANKI)
68  .export_values()
69  .finalize();
70 
71  // Use std::deque instead of std::vector to enable automatic Python list /
72  // tuple conversion. FIXME: Ideally this should work for std::vector.
73  metric_parameters
74  .def(py::init([](const std::deque<float>& fsr, size_t nsp) {
75  std::vector<float> fsrvec{fsr.begin(), fsr.end()};
76  return MetricParameters{fsrvec, nsp};
77  }),
78  "fscore_radius"_a = std::deque<float>{0.01f},
79  "n_sampled_points"_a = 1000)
80  .def_property(
81  "fscore_radius",
82  [](const MetricParameters& self) { // getter
83  return std::deque<float>(self.fscore_radius.begin(),
84  self.fscore_radius.end());
85  },
86  [](MetricParameters& self,
87  const std::deque<float>& fsr) { // setter
88  self.fscore_radius =
89  std::vector<float>(fsr.begin(), fsr.end());
90  },
91  "Radius for computing the F-Score. A match between "
92  "a point and its nearest neighbor is sucessful if "
93  "it is within this radius.")
94  .def_readwrite("n_sampled_points",
96  "Points are sampled uniformly from the surface of "
97  "triangle meshes before distance computation. This "
98  "specifies the number of points sampled. No "
99  "sampling is done for point clouds.")
100  .def("__repr__", &MetricParameters::ToString);
101 
102  pybind_geometry_class(m_submodule);
103  pybind_drawable_geometry(m_submodule);
104  pybind_tensormap(m_submodule);
105  pybind_pointcloud(m_submodule);
106  pybind_lineset(m_submodule);
107  pybind_trianglemesh(m_submodule);
108  pybind_image(m_submodule);
109  pybind_boundingvolume(m_submodule);
110  pybind_voxel_block_grid(m_submodule);
111  pybind_raycasting_scene(m_submodule);
112 }
113 
114 } // namespace geometry
115 } // namespace t
116 } // namespace cloudViewer
bool IsCUDA() const
Definition: Device.h:99
bool IsCPU() const
Definition: Device.h:95
virtual core::Device GetDevice() const =0
Returns the device of the geometry.
virtual Geometry & Clear()=0
Clear all elements in the geometry.
virtual bool IsEmpty() const =0
Returns true iff the geometry is empty.
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_trianglemesh(py::module &m)
void pybind_voxel_block_grid(py::module &m)
void pybind_lineset(py::module &m)
Definition: lineset.cpp:20
void pybind_geometry(py::module &m)
Definition: geometry.cpp:43
void pybind_boundingvolume(py::module &m)
void pybind_image(py::module &m)
Definition: image.cpp:56
void pybind_raycasting_scene(py::module &m)
void pybind_geometry_class(py::module &m)
Definition: geometry.cpp:24
@ ChamferDistance
Chamfer Distance.
@ HausdorffDistance
Hausdorff Distance.
void pybind_tensormap(py::module &m)
Definition: tensormap.cpp:119
void pybind_pointcloud(py::module &m)
Definition: pointcloud.cpp:49
@ MINIMAL_APPROX
Minimal OBB approximation.
@ PCA
Principal Component Analysis.
@ MINIMAL_JYLANKI
Minimal OBB by Jylanki.
void pybind_drawable_geometry(py::module &m)
Generic file read and write utility for python interface.
Holder for various parameters required by metrics.
Definition: Geometry.h:103