ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
viewcontrol.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 
9 
10 #include <IJsonConvertibleIO.h>
11 
12 #include "pybind/docstring.h"
15 
16 namespace cloudViewer {
17 namespace visualization {
18 
19 // Functions have similar arguments, thus the arg docstrings may be shared
20 static const std::unordered_map<std::string, std::string>
22  {"parameter", "The pinhole camera parameter to convert from."},
23  {"scale", "Scale ratio."},
24  {"x", "Distance the mouse cursor has moved in x-axis."},
25  {"y", "Distance the mouse cursor has moved in y-axis."},
26  {"xo", "Original point coordinate of the mouse in x-axis."},
27  {"yo", "Original point coordinate of the mouse in y-axis."},
28  {"step", "The step to change field of view."},
29  {"z_near", "The depth of the near z-plane of the visualizer."},
30  {"z_far", "The depth of the far z-plane of the visualizer."},
31 };
32 
33 void pybind_viewcontrol(py::module &m) {
34  py::class_<ViewControl, PyViewControl<>, std::shared_ptr<ViewControl>>
35  viewcontrol(m, "ViewControl", "View controller for visualizer.");
36  py::detail::bind_default_constructor<ViewControl>(viewcontrol);
37  viewcontrol
38  .def("__repr__",
39  [](const ViewControl &vc) {
40  return std::string("ViewControl");
41  })
42  .def(
43  "convert_to_pinhole_camera_parameters",
44  [](ViewControl &vc) {
47  return parameter;
48  },
49  "Function to convert ViewControl to "
50  "camera::PinholeCameraParameters")
51  .def("convert_from_pinhole_camera_parameters",
53  "parameter"_a, "allow_arbitrary"_a = false)
54  .def("scale", &ViewControl::Scale, "Function to process scaling",
55  "scale"_a)
56  .def("rotate", &ViewControl::Rotate, "Function to process rotation",
57  "x"_a, "y"_a, "xo"_a = 0.0, "yo"_a = 0.0)
58  .def("translate", &ViewControl::Translate,
59  "Function to process translation", "x"_a, "y"_a, "xo"_a = 0.0,
60  "yo"_a = 0.0)
61  .def("camera_local_translate", &ViewControl::CameraLocalTranslate,
62  "Function to process translation of camera", "forward"_a,
63  "right"_a, "up"_a)
64  .def("camera_local_rotate", &ViewControl::CameraLocalRotate,
65  "Function to process rotation of camera in a local"
66  "coordinate frame",
67  "x"_a, "y"_a, "xo"_a = 0.0, "yo"_a = 0.0)
68  .def("reset_camera_local_rotate",
70  "Resets the coordinate frame for local camera rotations")
71  .def("get_field_of_view", &ViewControl::GetFieldOfView,
72  "Function to get field of view")
73  .def("change_field_of_view", &ViewControl::ChangeFieldOfView,
74  "Function to change field of view", "step"_a = 0.45)
75  .def("set_constant_z_near", &ViewControl::SetConstantZNear,
76  "Function to change the near z-plane of the visualizer to a "
77  "constant value, i.e., independent of zoom and bounding box "
78  "size.",
79  "z_near"_a)
80  .def("set_constant_z_far", &ViewControl::SetConstantZFar,
81  "Function to change the far z-plane of the visualizer to a "
82  "constant value, i.e., independent of zoom and bounding box "
83  "size.",
84  "z_far"_a)
85  .def("unset_constant_z_near", &ViewControl::UnsetConstantZNear,
86  "Function to remove a previously set constant z near value, "
87  "i.e., near z-plane of the visualizer is dynamically set "
88  "dependent on zoom and bounding box size.")
89  .def("unset_constant_z_far", &ViewControl::UnsetConstantZFar,
90  "Function to remove a previously set constant z far value, "
91  "i.e., far z-plane of the visualizer is dynamically set "
92  "dependent on zoom and bounding box size.")
93  .def("set_lookat", &ViewControl::SetLookat,
94  "Set the lookat vector of the visualizer", "lookat"_a)
95  .def("set_up", &ViewControl::SetUp,
96  "Set the up vector of the visualizer", "up"_a)
97  .def("set_front", &ViewControl::SetFront,
98  "Set the front vector of the visualizer", "front"_a)
99  .def("set_zoom", &ViewControl::SetZoom,
100  "Set the zoom of the visualizer", "zoom"_a);
101  docstring::ClassMethodDocInject(m, "ViewControl", "change_field_of_view",
103  docstring::ClassMethodDocInject(m, "ViewControl",
104  "convert_from_pinhole_camera_parameters",
106  docstring::ClassMethodDocInject(m, "ViewControl",
107  "convert_to_pinhole_camera_parameters",
109  docstring::ClassMethodDocInject(m, "ViewControl", "get_field_of_view",
111  docstring::ClassMethodDocInject(m, "ViewControl", "rotate",
113  docstring::ClassMethodDocInject(m, "ViewControl", "scale",
115  docstring::ClassMethodDocInject(m, "ViewControl", "translate",
117  docstring::ClassMethodDocInject(m, "ViewControl", "set_constant_z_near",
119  docstring::ClassMethodDocInject(m, "ViewControl", "set_constant_z_far",
121  docstring::ClassMethodDocInject(m, "ViewControl", "unset_constant_z_near",
123  docstring::ClassMethodDocInject(m, "ViewControl", "unset_constant_z_far",
125 }
126 
127 void pybind_viewcontrol_method(py::module &m) {}
128 
129 } // namespace visualization
130 } // namespace cloudViewer
Contains both intrinsic and extrinsic pinhole camera parameters.
View controller for visualizer.
Definition: ViewControl.h:25
double GetFieldOfView() const
Function to get field of view.
Definition: ViewControl.h:155
void SetFront(const Eigen::Vector3d &front)
void SetUp(const Eigen::Vector3d &up)
virtual void Translate(double x, double y, double xo=0.0, double yo=0.0)
Function to process translation.
virtual void Rotate(double x, double y, double xo=0.0, double yo=0.0)
Function to process rotation.
virtual void CameraLocalTranslate(double forward, double right, double up)
virtual void CameraLocalRotate(double x, double y, double xo=0.0, double yo=0.0)
virtual void ChangeFieldOfView(double step)
bool ConvertFromPinholeCameraParameters(const camera::PinholeCameraParameters &parameters, bool allow_arbitrary=false)
void SetLookat(const Eigen::Vector3d &lookat)
virtual void Scale(double scale)
bool ConvertToPinholeCameraParameters(camera::PinholeCameraParameters &parameters)
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
static const std::unordered_map< std::string, std::string > map_view_control_docstrings
Definition: viewcontrol.cpp:21
void pybind_viewcontrol(py::module &m)
Definition: viewcontrol.cpp:33
void pybind_viewcontrol_method(py::module &m)
Generic file read and write utility for python interface.