ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
utility.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 // clang-format off
9 // must include first to fix glfw issues
11 // clang-format on
12 
13 #include <FileSystem.h>
14 #include <IJsonConvertibleIO.h>
15 #include <ecvMesh.h>
16 #include <ecvPointCloud.h>
17 
18 #include "pybind/docstring.h"
22 
23 namespace cloudViewer {
24 namespace visualization {
25 
26 void pybind_visualization_utility(py::module &m) {
27  py::class_<visualization::SelectionPolygonVolume> selection_volume(
28  m, "SelectionPolygonVolume",
29  "Select a polygon volume for cropping.");
30  py::detail::bind_default_constructor<visualization::SelectionPolygonVolume>(
31  selection_volume);
32  py::detail::bind_copy_functions<visualization::SelectionPolygonVolume>(
33  selection_volume);
34  selection_volume
35  .def(
36  "crop_point_cloud",
38  const ccPointCloud &input) {
39  return s.CropPointCloud(input);
40  },
41  "input"_a, "Function to crop point cloud.")
42  .def(
43  "crop_triangle_mesh",
45  const ccMesh &input) {
46  return s.CropTriangleMesh(input);
47  },
48  "input"_a, "Function to crop crop triangle mesh.")
49  .def(
50  "crop_in_polygon",
52  const ccPointCloud &input) {
53  return s.CropInPolygon(input);
54  },
55  "input"_a, "Function to crop 3d point clouds.")
56  .def("__repr__",
58  return std::string(
59  "visualization::SelectionPolygonVolume, access "
60  "its members:\n"
61  "orthogonal_axis, bounding_polygon, axis_min, "
62  "axis_max");
63  })
64  .def_readwrite(
65  "orthogonal_axis",
67  "string: one of ``{x, y, z}``.")
68  .def_readwrite(
69  "bounding_polygon",
71  "``(n, 3)`` float64 numpy array: Bounding polygon "
72  "boundary.")
73  .def_readwrite("axis_min",
75  "float: Minimum axis value.")
76  .def_readwrite("axis_max",
78  "float: Maximum axis value.");
79  docstring::ClassMethodDocInject(m, "SelectionPolygonVolume",
80  "crop_point_cloud",
81  {{"input", "The input point cloud."}});
82  docstring::ClassMethodDocInject(m, "SelectionPolygonVolume",
83  "crop_triangle_mesh",
84  {{"input", "The input triangle mesh."}});
85  docstring::ClassMethodDocInject(m, "SelectionPolygonVolume",
86  "crop_in_polygon",
87  {{"input", "The input point cloud xyz."}});
88 }
89 
90 // Visualization util functions have similar arguments, sharing arg
91 // docstrings
92 static const std::unordered_map<std::string, std::string>
94  {"callback_function",
95  "Call back function to be triggered at a key press "
96  "event."},
97  {"filename", "The file path."},
98  {"geometry_list", "List of geometries to be visualized."},
99  {"height", "The height of the visualization window."},
100  {"key_to_callback", "Map of key to call back functions."},
101  {"left", "The left margin of the visualization window."},
102  {"optional_view_trajectory_json_file",
103  "Camera trajectory json file path for custom animation."},
104  {"top", "The top margin of the visualization window."},
105  {"width", "The width of the visualization window."},
106  {"point_show_normal",
107  "Visualize point normals if set to true."},
108  {"mesh_show_wireframe",
109  "Visualize mesh wireframe if set to true."},
110  {"mesh_show_back_face",
111  "Visualize also the back face of the mesh triangles."},
112  {"window_name",
113  "The displayed title of the visualization window."},
114  {"lookat", "The lookat vector of the camera."},
115  {"up", "The up vector of the camera."},
116  {"front", "The front vector of the camera."},
117  {"zoom", "The zoom of the camera."}};
118 
120  m.def(
121  "draw_geometries",
122  [](const std::vector<std::shared_ptr<const ccHObject>>
123  &geometry_ptrs,
124  const std::string &window_name, int width, int height, int left,
125  int top, bool point_show_normal, bool mesh_show_wireframe,
126  bool mesh_show_back_face,
131  std::string current_dir =
133  DrawGeometries(geometry_ptrs, window_name, width, height, left,
134  top, point_show_normal, mesh_show_wireframe,
135  mesh_show_back_face,
136  lookat.has_value() ? &lookat.value() : nullptr,
137  up.has_value() ? &up.value() : nullptr,
138  front.has_value() ? &front.value() : nullptr,
139  zoom.has_value() ? &zoom.value() : nullptr);
141  },
142  "Function to draw a list of geometry::Geometry objects",
143  "geometry_list"_a, "window_name"_a = "CloudViewer",
144  "width"_a = 1920, "height"_a = 1080, "left"_a = 50, "top"_a = 50,
145  "point_show_normal"_a = false, "mesh_show_wireframe"_a = false,
146  "mesh_show_back_face"_a = false, "lookat"_a = py::none(),
147  "up"_a = py::none(), "front"_a = py::none(), "zoom"_a = py::none());
148  docstring::FunctionDocInject(m, "draw_geometries",
150 
151  m.def(
152  "draw_geometries_with_custom_animation",
153  [](const std::vector<std::shared_ptr<const ccHObject>>
154  &geometry_ptrs,
155  const std::string &window_name, int width, int height, int left,
156  int top, const fs::path &json_filename) {
157  std::string current_dir =
160  geometry_ptrs, window_name, width, height, left, top,
161  json_filename.string());
163  current_dir);
164  },
165  "Function to draw a list of ccHObject objects with a GUI "
166  "that "
167  "supports animation",
168  "geometry_list"_a, "window_name"_a = "cloudViewer",
169  "width"_a = 1920, "height"_a = 1080, "left"_a = 50, "top"_a = 50,
170  "optional_view_trajectory_json_file"_a = "");
171  docstring::FunctionDocInject(m, "draw_geometries_with_custom_animation",
173 
174  m.def(
175  "draw_geometries_with_animation_callback",
176  [](const std::vector<std::shared_ptr<const ccHObject>>
177  &geometry_ptrs,
178  std::function<bool(visualization::Visualizer *)> callback_func,
179  const std::string &window_name, int width, int height, int left,
180  int top) {
181  std::string current_dir =
184  geometry_ptrs, callback_func, window_name, width,
185  height, left, top);
187  current_dir);
188  },
189  "Function to draw a list of ccHObject objects with a "
190  "customized "
191  "animation callback function",
192  "geometry_list"_a, "callback_function"_a,
193  "window_name"_a = "cloudViewer", "width"_a = 1920,
194  "height"_a = 1080, "left"_a = 50, "top"_a = 50,
195  py::return_value_policy::reference);
196  docstring::FunctionDocInject(m, "draw_geometries_with_animation_callback",
198 
199  m.def(
200  "draw_geometries_with_key_callbacks",
201  [](const std::vector<std::shared_ptr<const ccHObject>>
202  &geometry_ptrs,
203  const std::map<int,
204  std::function<bool(visualization::Visualizer *)>>
205  &key_to_callback,
206  const std::string &window_name, int width, int height, int left,
207  int top) {
208  std::string current_dir =
211  geometry_ptrs, key_to_callback, window_name, width,
212  height, left, top);
214  current_dir);
215  },
216  "Function to draw a list of ccHObject objects with a "
217  "customized "
218  "key-callback mapping",
219  "geometry_list"_a, "key_to_callback"_a,
220  "window_name"_a = "cloudViewer", "width"_a = 1920,
221  "height"_a = 1080, "left"_a = 50, "top"_a = 50);
222  docstring::FunctionDocInject(m, "draw_geometries_with_key_callbacks",
224 
225  m.def(
226  "draw_geometries_with_editing",
227  [](const std::vector<std::shared_ptr<const ccHObject>>
228  &geometry_ptrs,
229  const std::string &window_name, int width, int height, int left,
230  int top) {
232  geometry_ptrs, window_name, width, height, left, top);
233  },
234  "Function to draw a list of ccHObject providing user "
235  "interaction",
236  "geometry_list"_a, "window_name"_a = "cloudViewer",
237  "width"_a = 1920, "height"_a = 1080, "left"_a = 50, "top"_a = 50);
238  docstring::FunctionDocInject(m, "draw_geometries_with_editing",
240 
241  m.def(
242  "draw_geometries_with_vertex_selection",
243  [](const std::vector<std::shared_ptr<const ccHObject>>
244  &geometry_ptrs,
245  const std::string &window_name, int width, int height, int left,
246  int top) {
248  geometry_ptrs, window_name, width, height, left, top);
249  },
250  "Function to draw a list of ccHObject providing ability "
251  "for user to select points",
252  "geometry_list"_a, "window_name"_a = "cloudViewer",
253  "width"_a = 1920, "height"_a = 1080, "left"_a = 50, "top"_a = 50);
254  docstring::FunctionDocInject(m, "draw_geometries_with_vertex_selection",
256 
257  m.def(
258  "read_selection_polygon_volume",
259  [](const fs::path &filename) {
261  io::ReadIJsonConvertible(filename.string(), vol);
262  return vol;
263  },
264  "Function to read visualization::SelectionPolygonVolume from file",
265  "filename"_a);
266  docstring::FunctionDocInject(m, "read_selection_polygon_volume",
268 }
269 
270 } // namespace visualization
271 } // namespace cloudViewer
std::string filename
int width
int height
Triangular mesh.
Definition: ecvMesh.h:35
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
constexpr bool has_value() const noexcept
Definition: Optional.h:440
constexpr T const & value() const &
Definition: Optional.h:465
std::vector< Eigen::Vector3d > bounding_polygon_
Bounding polygon boundary.
std::vector< size_t > CropInPolygon(const ccPointCloud &input) const
std::shared_ptr< ccPointCloud > CropPointCloud(const ccPointCloud &input) const
std::shared_ptr< ccMesh > CropTriangleMesh(const ccMesh &input) const
The main Visualizer class.
Definition: Visualizer.h:45
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 FunctionDocInject(py::module &pybind_module, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:76
bool ReadIJsonConvertible(const std::string &filename, cloudViewer::utility::IJsonConvertible &object)
static const std::string path
Definition: PointCloud.cpp:59
bool ChangeWorkingDirectory(const std::string &directory)
Definition: FileSystem.cpp:427
void pybind_visualization_utility(py::module &m)
Definition: utility.cpp:26
bool DrawGeometriesWithVertexSelection(const std::vector< std::shared_ptr< const ccHObject >> &geometry_ptrs, const std::string &window_name, int width, int height, int left, int top)
void pybind_visualization_utility_methods(py::module &m)
Definition: utility.cpp:119
static const std::unordered_map< std::string, std::string > map_shared_argument_docstrings
Definition: utility.cpp:93
bool DrawGeometriesWithKeyCallbacks(const std::vector< std::shared_ptr< const ccHObject >> &geometry_ptrs, const std::map< int, std::function< bool(Visualizer *)>> &key_to_callback, const std::string &window_name, int width, int height, int left, int top)
Function to draw a list of geometry.
bool DrawGeometriesWithCustomAnimation(const std::vector< std::shared_ptr< const ccHObject >> &geometry_ptrs, const std::string &window_name, int width, int height, int left, int top, const std::string &json_filename)
Function to draw a list of geometry objects with a GUI that supports animation.
bool DrawGeometriesWithEditing(const std::vector< std::shared_ptr< const ccHObject >> &geometry_ptrs, const std::string &window_name, int width, int height, int left, int top)
Function to draw a list of geometry.
bool DrawGeometries(const std::vector< std::shared_ptr< const ccHObject >> &geometry_ptrs, const std::string &window_name, int width, int height, int left, int top, bool point_show_normal, bool mesh_show_wireframe, bool mesh_show_back_face, Eigen::Vector3d *lookat, Eigen::Vector3d *up, Eigen::Vector3d *front, double *zoom)
Function to draw a list of geometry objects.
bool DrawGeometriesWithAnimationCallback(const std::vector< std::shared_ptr< const ccHObject >> &geometry_ptrs, std::function< bool(Visualizer *)> callback_func, const std::string &window_name, int width, int height, int left, int top)
Function to draw a list of geometry objects with a customized animation callback function.
Generic file read and write utility for python interface.