1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2018-2021 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------
#include "open3d/geometry/PointCloud.h"
#include "open3d/geometry/TriangleMesh.h"
#include "open3d/io/IJsonConvertibleIO.h"
#include "open3d/utility/FileSystem.h"
#include "open3d/visualization/utility/DrawGeometry.h"
#include "open3d/visualization/utility/SelectionPolygonVolume.h"
#include "open3d/visualization/visualizer/Visualizer.h"
#include "pybind/docstring.h"
#include "pybind/visualization/visualization.h"
namespace open3d {
namespace visualization {
void pybind_visualization_utility(py::module &m) {
py::class_<SelectionPolygonVolume> selection_volume(
m, "SelectionPolygonVolume",
"Select a polygon volume for cropping.");
py::detail::bind_default_constructor<SelectionPolygonVolume>(
selection_volume);
py::detail::bind_copy_functions<SelectionPolygonVolume>(selection_volume);
selection_volume
.def(
"crop_point_cloud",
[](const SelectionPolygonVolume &s,
const geometry::PointCloud &input) {
return s.CropPointCloud(input);
},
"input"_a, "Function to crop point cloud.")
.def(
"crop_triangle_mesh",
[](const SelectionPolygonVolume &s,
const geometry::TriangleMesh &input) {
return s.CropTriangleMesh(input);
},
"input"_a, "Function to crop crop triangle mesh.")
.def(
"crop_in_polygon",
[](const SelectionPolygonVolume &s,
const geometry::PointCloud &input) {
return s.CropInPolygon(input);
},
"input"_a, "Function to crop 3d point clouds.")
.def("__repr__",
[](const SelectionPolygonVolume &s) {
return std::string(
"SelectionPolygonVolume, access "
"its members:\n"
"orthogonal_axis, bounding_polygon, axis_min, "
"axis_max");
})
.def_readwrite("orthogonal_axis",
&SelectionPolygonVolume::orthogonal_axis_,
"string: one of ``{x, y, z}``.")
.def_readwrite("bounding_polygon",
&SelectionPolygonVolume::bounding_polygon_,
"``(n, 3)`` float64 numpy array: Bounding polygon "
"boundary.")
.def_readwrite("axis_min", &SelectionPolygonVolume::axis_min_,
"float: Minimum axis value.")
.def_readwrite("axis_max", &SelectionPolygonVolume::axis_max_,
"float: Maximum axis value.");
docstring::ClassMethodDocInject(m, "SelectionPolygonVolume",
"crop_point_cloud",
{{"input", "The input point cloud."}});
docstring::ClassMethodDocInject(m, "SelectionPolygonVolume",
"crop_triangle_mesh",
{{"input", "The input triangle mesh."}});
docstring::ClassMethodDocInject(m, "SelectionPolygonVolume",
"crop_in_polygon",
{{"input", "The input point cloud xyz."}});
}
// Visualization util functions have similar arguments, sharing arg docstrings
static const std::unordered_map<std::string, std::string>
map_shared_argument_docstrings = {
{"callback_function",
"Call back function to be triggered at a key press event."},
{"filename", "The file path."},
{"geometry_list", "List of geometries to be visualized."},
{"height", "The height of the visualization window."},
{"key_to_callback", "Map of key to call back functions."},
{"left", "The left margin of the visualization window."},
{"optional_view_trajectory_json_file",
"Camera trajectory json file path for custom animation."},
{"top", "The top margin of the visualization window."},
{"width", "The width of the visualization window."},
{"point_show_normal",
"Visualize point normals if set to true."},
{"mesh_show_wireframe",
"Visualize mesh wireframe if set to true."},
{"mesh_show_back_face",
"Visualize also the back face of the mesh triangles."},
{"window_name",
"The displayed title of the visualization window."},
{"lookat", "The lookat vector of the camera."},
{"up", "The up vector of the camera."},
{"front", "The front vector of the camera."},
{"zoom", "The zoom of the camera."}};
void pybind_visualization_utility_methods(py::module &m) {
m.def(
"draw_geometries",
[](const std::vector<std::shared_ptr<const geometry::Geometry>>
&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) {
std::string current_dir =
utility::filesystem::GetWorkingDirectory();
DrawGeometries(geometry_ptrs, window_name, width, height, left,
top, point_show_normal, mesh_show_wireframe,
mesh_show_back_face);
utility::filesystem::ChangeWorkingDirectory(current_dir);
},
"Function to draw a list of geometry::Geometry objects",
"geometry_list"_a, "window_name"_a = "Open3D", "width"_a = 1920,
"height"_a = 1080, "left"_a = 50, "top"_a = 50,
"point_show_normal"_a = false, "mesh_show_wireframe"_a = false,
"mesh_show_back_face"_a = false);
m.def(
"draw_geometries",
[](const std::vector<std::shared_ptr<const geometry::Geometry>>
&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) {
std::string current_dir =
utility::filesystem::GetWorkingDirectory();
DrawGeometries(geometry_ptrs, window_name, width, height, left,
top, point_show_normal, mesh_show_wireframe,
mesh_show_back_face, &lookat, &up, &front,
&zoom);
utility::filesystem::ChangeWorkingDirectory(current_dir);
},
"Function to draw a list of geometry::Geometry objects",
"geometry_list"_a, "window_name"_a = "Open3D", "width"_a = 1920,
"height"_a = 1080, "left"_a = 50, "top"_a = 50,
"point_show_normal"_a = false, "mesh_show_wireframe"_a = false,
"mesh_show_back_face"_a = false, "lookat"_a, "up"_a, "front"_a,
"zoom"_a);
docstring::FunctionDocInject(m, "draw_geometries",
map_shared_argument_docstrings);
m.def(
"draw_geometries_with_custom_animation",
[](const std::vector<std::shared_ptr<const geometry::Geometry>>
&geometry_ptrs,
const std::string &window_name, int width, int height, int left,
int top, const std::string &json_filename) {
std::string current_dir =
utility::filesystem::GetWorkingDirectory();
DrawGeometriesWithCustomAnimation(geometry_ptrs, window_name,
width, height, left, top,
json_filename);
utility::filesystem::ChangeWorkingDirectory(current_dir);
},
"Function to draw a list of geometry::Geometry objects with a GUI "
"that "
"supports animation",
"geometry_list"_a, "window_name"_a = "Open3D", "width"_a = 1920,
"height"_a = 1080, "left"_a = 50, "top"_a = 50,
"optional_view_trajectory_json_file"_a = "");
docstring::FunctionDocInject(m, "draw_geometries_with_custom_animation",
map_shared_argument_docstrings);
m.def(
"draw_geometries_with_animation_callback",
[](const std::vector<std::shared_ptr<const geometry::Geometry>>
&geometry_ptrs,
std::function<bool(Visualizer *)> callback_func,
const std::string &window_name, int width, int height, int left,
int top) {
std::string current_dir =
utility::filesystem::GetWorkingDirectory();
DrawGeometriesWithAnimationCallback(geometry_ptrs,
callback_func, window_name,
width, height, left, top);
utility::filesystem::ChangeWorkingDirectory(current_dir);
},
"Function to draw a list of geometry::Geometry objects with a "
"customized "
"animation callback function",
"geometry_list"_a, "callback_function"_a,
"window_name"_a = "Open3D", "width"_a = 1920, "height"_a = 1080,
"left"_a = 50, "top"_a = 50, py::return_value_policy::reference);
docstring::FunctionDocInject(m, "draw_geometries_with_animation_callback",
map_shared_argument_docstrings);
m.def(
"draw_geometries_with_key_callbacks",
[](const std::vector<std::shared_ptr<const geometry::Geometry>>
&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) {
std::string current_dir =
utility::filesystem::GetWorkingDirectory();
DrawGeometriesWithKeyCallbacks(geometry_ptrs, key_to_callback,
window_name, width, height, left,
top);
utility::filesystem::ChangeWorkingDirectory(current_dir);
},
"Function to draw a list of geometry::Geometry objects with a "
"customized "
"key-callback mapping",
"geometry_list"_a, "key_to_callback"_a, "window_name"_a = "Open3D",
"width"_a = 1920, "height"_a = 1080, "left"_a = 50, "top"_a = 50);
docstring::FunctionDocInject(m, "draw_geometries_with_key_callbacks",
map_shared_argument_docstrings);
m.def(
"draw_geometries_with_editing",
[](const std::vector<std::shared_ptr<const geometry::Geometry>>
&geometry_ptrs,
const std::string &window_name, int width, int height, int left,
int top) {
DrawGeometriesWithEditing(geometry_ptrs, window_name, width,
height, left, top);
},
"Function to draw a list of geometry::Geometry providing user "
"interaction",
"geometry_list"_a, "window_name"_a = "Open3D", "width"_a = 1920,
"height"_a = 1080, "left"_a = 50, "top"_a = 50);
docstring::FunctionDocInject(m, "draw_geometries_with_editing",
map_shared_argument_docstrings);
m.def(
"draw_geometries_with_vertex_selection",
[](const std::vector<std::shared_ptr<const geometry::Geometry>>
&geometry_ptrs,
const std::string &window_name, int width, int height, int left,
int top) {
DrawGeometriesWithVertexSelection(geometry_ptrs, window_name,
width, height, left, top);
},
"Function to draw a list of geometry::Geometry providing ability "
"for user to select points",
"geometry_list"_a, "window_name"_a = "Open3D", "width"_a = 1920,
"height"_a = 1080, "left"_a = 50, "top"_a = 50);
docstring::FunctionDocInject(m, "draw_geometries_with_vertex_selection",
map_shared_argument_docstrings);
m.def(
"read_selection_polygon_volume",
[](const std::string &filename) {
SelectionPolygonVolume vol;
io::ReadIJsonConvertible(filename, vol);
return vol;
},
"Function to read SelectionPolygonVolume from file", "filename"_a);
docstring::FunctionDocInject(m, "read_selection_polygon_volume",
map_shared_argument_docstrings);
}
} // namespace visualization
} // namespace open3d
|