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 285 286 287 288 289 290 291 292
|
// ----------------------------------------------------------------------------
// - 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/visualization/visualizer/Visualizer.h"
#include "open3d/geometry/Image.h"
#include "open3d/visualization/visualizer/VisualizerWithEditing.h"
#include "open3d/visualization/visualizer/VisualizerWithKeyCallback.h"
#include "open3d/visualization/visualizer/VisualizerWithVertexSelection.h"
#include "pybind/docstring.h"
#include "pybind/visualization/visualization.h"
#include "pybind/visualization/visualization_trampoline.h"
namespace open3d {
namespace visualization {
// Functions have similar arguments, thus the arg docstrings may be shared
static const std::unordered_map<std::string, std::string>
map_visualizer_docstrings = {
{"callback_func", "The call back function."},
{"depth_scale",
"Scale depth value when capturing the depth image."},
{"do_render", "Set to ``True`` to do render."},
{"filename", "Path to file."},
{"geometry", "The ``Geometry`` object."},
{"height", "Height of window."},
{"left", "Left margin of the window to the screen."},
{"top", "Top margin of the window to the screen."},
{"visible", "Whether the window is visible."},
{"width", "Width of the window."},
{"window_name", "Window title name."},
{"convert_to_world_coordinate",
"Set to ``True`` to convert to world coordinates"},
{"reset_bounding_box",
"Set to ``False`` to keep current viewpoint"}};
void pybind_visualizer(py::module &m) {
py::class_<Visualizer, PyVisualizer<>, std::shared_ptr<Visualizer>>
visualizer(m, "Visualizer", "The main Visualizer class.");
py::detail::bind_default_constructor<Visualizer>(visualizer);
visualizer
.def("__repr__",
[](const Visualizer &vis) {
return std::string("Visualizer with name ") +
vis.GetWindowName();
})
.def("create_window", &Visualizer::CreateVisualizerWindow,
"Function to create a window and initialize GLFW",
"window_name"_a = "Open3D", "width"_a = 1920,
"height"_a = 1080, "left"_a = 50, "top"_a = 50,
"visible"_a = true)
.def("destroy_window", &Visualizer::DestroyVisualizerWindow,
"Function to destroy a window. This function MUST be called "
"from the main thread.")
.def("register_animation_callback",
&Visualizer::RegisterAnimationCallback,
"Function to register a callback function for animation. The "
"callback function returns if UpdateGeometry() needs to be "
"run.",
"callback_func"_a)
.def("run", &Visualizer::Run,
"Function to activate the window. This function will block "
"the current thread until the window is closed.")
.def("close", &Visualizer::Close,
"Function to notify the window to be closed")
.def("reset_view_point", &Visualizer::ResetViewPoint,
"Function to reset view point")
.def("update_geometry", &Visualizer::UpdateGeometry,
"Function to update geometry. This function must be called "
"when geometry has been changed. Otherwise the behavior of "
"Visualizer is undefined.",
"geometry"_a)
.def("update_renderer", &Visualizer::UpdateRender,
"Function to inform render needed to be updated")
.def("set_full_screen", &Visualizer::SetFullScreen,
"Function to change between fullscreen and windowed")
.def("toggle_full_screen", &Visualizer::ToggleFullScreen,
"Function to toggle between fullscreen and windowed")
.def("is_full_screen", &Visualizer::IsFullScreen,
"Function to query whether in fullscreen mode")
.def("poll_events", &Visualizer::PollEvents,
"Function to poll events")
.def("add_geometry", &Visualizer::AddGeometry,
"Function to add geometry to the scene and create "
"corresponding shaders",
"geometry"_a, "reset_bounding_box"_a = true)
.def("remove_geometry", &Visualizer::RemoveGeometry,
"Function to remove geometry", "geometry"_a,
"reset_bounding_box"_a = true)
.def("clear_geometries", &Visualizer::ClearGeometries,
"Function to clear geometries from the visualizer")
.def("get_view_control", &Visualizer::GetViewControl,
"Function to retrieve the associated ``ViewControl``",
py::return_value_policy::reference_internal)
.def("get_render_option", &Visualizer::GetRenderOption,
"Function to retrieve the associated ``RenderOption``",
py::return_value_policy::reference_internal)
.def("capture_screen_float_buffer",
&Visualizer::CaptureScreenFloatBuffer,
"Function to capture screen and store RGB in a float buffer",
"do_render"_a = false)
.def("capture_screen_image", &Visualizer::CaptureScreenImage,
"Function to capture and save a screen image", "filename"_a,
"do_render"_a = false)
.def("capture_depth_float_buffer",
&Visualizer::CaptureDepthFloatBuffer,
"Function to capture depth in a float buffer",
"do_render"_a = false)
.def("capture_depth_image", &Visualizer::CaptureDepthImage,
"Function to capture and save a depth image", "filename"_a,
"do_render"_a = false, "depth_scale"_a = 1000.0)
.def("capture_depth_point_cloud",
&Visualizer::CaptureDepthPointCloud,
"Function to capture and save local point cloud", "filename"_a,
"do_render"_a = false, "convert_to_world_coordinate"_a = false)
.def("get_window_name", &Visualizer::GetWindowName);
py::class_<VisualizerWithKeyCallback,
PyVisualizer<VisualizerWithKeyCallback>,
std::shared_ptr<VisualizerWithKeyCallback>>
visualizer_key(m, "VisualizerWithKeyCallback", visualizer,
"Visualizer with custom key callback capabilities.");
py::detail::bind_default_constructor<VisualizerWithKeyCallback>(
visualizer_key);
visualizer_key
.def("__repr__",
[](const VisualizerWithKeyCallback &vis) {
return std::string(
"VisualizerWithKeyCallback with name ") +
vis.GetWindowName();
})
.def("register_key_callback",
&VisualizerWithKeyCallback::RegisterKeyCallback,
"Function to register a callback function for a key press "
"event",
"key"_a, "callback_func"_a)
.def("register_key_action_callback",
&VisualizerWithKeyCallback::RegisterKeyActionCallback,
"Function to register a callback function for a key action "
"event. The callback function takes Visualizer, action and "
"mods as input and returns a boolean indicating if "
"UpdateGeometry() needs to be run.",
"key"_a, "callback_func"_a);
py::class_<VisualizerWithEditing, PyVisualizer<VisualizerWithEditing>,
std::shared_ptr<VisualizerWithEditing>>
visualizer_edit(m, "VisualizerWithEditing", visualizer,
"Visualizer with editing capabilities.");
py::detail::bind_default_constructor<VisualizerWithEditing>(
visualizer_edit);
visualizer_edit.def(py::init<double, bool, const std::string &>())
.def("__repr__",
[](const VisualizerWithEditing &vis) {
return std::string("VisualizerWithEditing with name ") +
vis.GetWindowName();
})
.def("get_picked_points", &VisualizerWithEditing::GetPickedPoints,
"Function to get picked points")
.def("get_cropped_geometry",
&VisualizerWithEditing::GetCroppedGeometry,
"Function to get cropped geometry");
py::class_<VisualizerWithVertexSelection,
PyVisualizer<VisualizerWithVertexSelection>,
std::shared_ptr<VisualizerWithVertexSelection>>
visualizer_vselect(
m, "VisualizerWithVertexSelection", visualizer,
"Visualizer with vertex selection capabilities.");
py::detail::bind_default_constructor<VisualizerWithVertexSelection>(
visualizer_vselect);
visualizer_vselect.def(py::init<>())
.def("__repr__",
[](const VisualizerWithVertexSelection &vis) {
return std::string(
"VisualizerWithVertexSelection with "
"name ") +
vis.GetWindowName();
})
.def("pick_points", &VisualizerWithVertexSelection::PickPoints,
"Function to pick points")
.def("get_picked_points",
&VisualizerWithVertexSelection::GetPickedPoints,
"Function to get picked points")
.def("clear_picked_points",
&VisualizerWithVertexSelection::ClearPickedPoints,
"Function to clear picked points")
.def("add_picked_points",
&VisualizerWithVertexSelection::AddPickedPoints,
"Function to add picked points")
.def("remove_picked_points",
&VisualizerWithVertexSelection::RemovePickedPoints,
"Function to remove picked points")
.def("register_selection_changed_callback",
&VisualizerWithVertexSelection::
RegisterSelectionChangedCallback,
"Registers a function to be called when selection changes")
.def("register_selection_moving_callback",
&VisualizerWithVertexSelection::
RegisterSelectionMovingCallback,
"Registers a function to be called while selection moves. "
"Geometry's vertex values can be changed, but do not change"
"the number of vertices.")
.def("register_selection_moved_callback",
&VisualizerWithVertexSelection::RegisterSelectionMovedCallback,
"Registers a function to be called after selection moves");
py::class_<VisualizerWithVertexSelection::PickedPoint>
visualizer_vselect_pickedpoint(m, "PickedPoint");
visualizer_vselect_pickedpoint.def(py::init<>())
.def_readwrite("index",
&VisualizerWithVertexSelection::PickedPoint::index)
.def_readwrite("coord",
&VisualizerWithVertexSelection::PickedPoint::coord);
docstring::ClassMethodDocInject(m, "Visualizer", "add_geometry",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "remove_geometry",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer",
"capture_depth_float_buffer",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "capture_depth_image",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer",
"capture_depth_point_cloud",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer",
"capture_screen_float_buffer",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "capture_screen_image",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "close",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "create_window",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "destroy_window",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "get_render_option",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "get_view_control",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "get_window_name",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "poll_events",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer",
"register_animation_callback",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "reset_view_point",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "run",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "update_geometry",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "update_renderer",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "set_full_screen",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "toggle_full_screen",
map_visualizer_docstrings);
docstring::ClassMethodDocInject(m, "Visualizer", "is_full_screen",
map_visualizer_docstrings);
}
void pybind_visualizer_method(py::module &m) {}
} // namespace visualization
} // namespace open3d
|