ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccDisplayTools.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 <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include <pybind11/stl_bind.h>
11 
12 #include <ecvBBox.h>
13 #include <ecvDisplayTools.h>
14 #include <ecvHObject.h>
15 
16 #include "../casters.h"
17 
18 namespace py = pybind11;
19 using namespace pybind11::literals;
20 
21 void define_ccDisplayTools(py::module &m)
22 {
23  py::class_<ecvDisplayTools, ecvGenericDisplayTools> PyccDisplayTools(m, "ccDisplayTools");
24  py::enum_<ecvDisplayTools::PICKING_MODE> PyPickingMode(PyccDisplayTools, "PICKING_MODE");
25  py::enum_<ecvDisplayTools::INTERACTION_FLAG> PyInteractionFlag(
26  PyccDisplayTools, "INTERACTION_FLAG", py::arithmetic());
27  py::enum_<ecvDisplayTools::MessagePosition> PyMessagePosition(PyccDisplayTools,
28  "MessagePosition");
29  py::enum_<ecvDisplayTools::MessageType> PyMessageType(PyccDisplayTools, "MessageType");
30  py::enum_<ecvDisplayTools::PivotVisibility> PyPivotVisibility(PyccDisplayTools,
31  "PivotVisibility");
32 
33  PyPickingMode.value("NO_PICKING", ecvDisplayTools::PICKING_MODE::NO_PICKING)
34  .value("ENTITY_PICKING", ecvDisplayTools::PICKING_MODE::ENTITY_PICKING)
35  .value("ENTITY_RECT_PICKING", ecvDisplayTools::PICKING_MODE::ENTITY_RECT_PICKING)
36  .value("FAST_PICKING", ecvDisplayTools::PICKING_MODE::FAST_PICKING)
37  .value("POINT_PICKING", ecvDisplayTools::PICKING_MODE::POINT_PICKING)
38  .value("TRIANGLE_PICKING", ecvDisplayTools::PICKING_MODE::TRIANGLE_PICKING)
39  .value("POINT_OR_TRIANGLE_PICKING",
40  ecvDisplayTools::PICKING_MODE::POINT_OR_TRIANGLE_PICKING)
41  .value("POINT_OR_TRIANGLE_OR_LABEL_PICKING",
42  ecvDisplayTools::PICKING_MODE::POINT_OR_TRIANGLE_OR_LABEL_PICKING)
43  .value("LABEL_PICKING", ecvDisplayTools::PICKING_MODE::LABEL_PICKING)
44  .value("DEFAULT_PICKING", ecvDisplayTools::PICKING_MODE::DEFAULT_PICKING)
45  .export_values();
46 
47  PyInteractionFlag
48  .value("INTERACT_NONE", ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_NONE)
49  .value("INTERACT_ROTATE", ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_ROTATE)
50  .value("INTERACT_PAN", ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_PAN)
51  .value("INTERACT_CTRL_PAN",
52  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_CTRL_PAN)
53  .value("INTERACT_ZOOM_CAMERA",
54  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_ZOOM_CAMERA)
55  .value("INTERACT_2D_ITEMS",
56  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_2D_ITEMS)
57  .value("INTERACT_CLICKABLE_ITEMS",
58  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_CLICKABLE_ITEMS)
59  .value("INTERACT_TRANSFORM_ENTITIES",
60  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_TRANSFORM_ENTITIES)
61  .value("INTERACT_SIG_RB_CLICKED",
62  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_SIG_RB_CLICKED)
63  .value("INTERACT_SIG_LB_CLICKED",
64  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_SIG_LB_CLICKED)
65  .value("INTERACT_SIG_MOUSE_MOVED",
66  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_SIG_MOUSE_MOVED)
67  .value("INTERACT_SIG_BUTTON_RELEASED",
68  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_SIG_BUTTON_RELEASED)
69  .value("INTERACT_SIG_MB_CLICKED",
70  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_SIG_MB_CLICKED)
71  .value("INTERACT_SEND_ALL_SIGNALS",
72  ecvDisplayTools::INTERACTION_FLAGS::enum_type::INTERACT_SEND_ALL_SIGNALS)
73  .value("MODE_PAN_ONLY", ecvDisplayTools::INTERACTION_FLAGS::enum_type::MODE_PAN_ONLY)
74  .value("MODE_TRANSFORM_CAMERA",
75  ecvDisplayTools::INTERACTION_FLAGS::enum_type::MODE_TRANSFORM_CAMERA)
76  .value("MODE_TRANSFORM_ENTITIES",
77  ecvDisplayTools::INTERACTION_FLAGS::enum_type::MODE_TRANSFORM_ENTITIES)
78  .export_values();
79 
80  PyMessagePosition
81  .value("LOWER_LEFT_MESSAGE", ecvDisplayTools::MessagePosition::LOWER_LEFT_MESSAGE)
82  .value("UPPER_CENTER_MESSAGE", ecvDisplayTools::MessagePosition::UPPER_CENTER_MESSAGE)
83  .value("SCREEN_CENTER_MESSAGE", ecvDisplayTools::MessagePosition::SCREEN_CENTER_MESSAGE)
84  .export_values();
85 
86  PyMessageType.value("CUSTOM_MESSAGE", ecvDisplayTools::MessageType::CUSTOM_MESSAGE)
87  .value("SCREEN_SIZE_MESSAGE", ecvDisplayTools::MessageType::SCREEN_SIZE_MESSAGE)
88  .value("PERSPECTIVE_STATE_MESSAGE", ecvDisplayTools::MessageType::PERSPECTIVE_STATE_MESSAGE)
89  .value("SUN_LIGHT_STATE_MESSAGE", ecvDisplayTools::MessageType::SUN_LIGHT_STATE_MESSAGE)
90  .value("CUSTOM_LIGHT_STATE_MESSAGE",
91  ecvDisplayTools::MessageType::CUSTOM_LIGHT_STATE_MESSAGE)
92  .value("MANUAL_TRANSFORMATION_MESSAGE",
93  ecvDisplayTools::MessageType::MANUAL_TRANSFORMATION_MESSAGE)
94  .value("MANUAL_SEGMENTATION_MESSAGE",
95  ecvDisplayTools::MessageType::MANUAL_SEGMENTATION_MESSAGE)
96  .value("ROTAION_LOCK_MESSAGE", ecvDisplayTools::MessageType::ROTAION_LOCK_MESSAGE)
97  .value("FULL_SCREEN_MESSAGE", ecvDisplayTools::MessageType::FULL_SCREEN_MESSAGE)
98  .export_values();
99 
100  PyPivotVisibility.value("PIVOT_HIDE", ecvDisplayTools::PivotVisibility::PIVOT_HIDE)
101  .value("PIVOT_SHOW_ON_MOVE", ecvDisplayTools::PivotVisibility::PIVOT_SHOW_ON_MOVE)
102  .value("PIVOT_ALWAYS_SHOW", ecvDisplayTools::PivotVisibility::PIVOT_ALWAYS_SHOW)
103  .export_values();
104 
105  PyccDisplayTools.def_static("getDevicePixelRatio", &ecvDisplayTools::GetDevicePixelRatio)
106  .def_static(
107  "doResize", static_cast<void (*)(int, int)>(&ecvDisplayTools::DoResize), "x"_a, "y"_a)
108  .def_static(
109  "doResize", static_cast<void (*)(const QSize &)>(&ecvDisplayTools::DoResize), "size"_a)
110  .def_static("setSceneDB", &ecvDisplayTools::SetSceneDB, "root"_a)
111  .def_static("getSceneDB", &ecvDisplayTools::GetSceneDB)
112  .def_static(
113  "renderText",
114  [](int x,
115  int y,
116  const QString &str,
117  const QFont &font,
118  const ecvColor::Rgbub &color,
119  const QString &id) { ecvDisplayTools::RenderText(x, y, str, font, color, id); },
120  "x"_a,
121  "y"_a,
122  "str"_a,
123  "font"_a = QFont(),
124  "color"_a = ecvColor::defaultLabelBkgColor,
125  "id"_a = "")
126  .def_static(
127  "renderText",
128  [](double x,
129  double y,
130  double z,
131  const QString &str,
132  const QFont &font,
133  const ecvColor::Rgbub &color,
134  const QString &id) { ecvDisplayTools::RenderText(x, y, z, str, font, color, id); },
135  "x"_a,
136  "y"_a,
137  "z"_a,
138  "str"_a,
139  "font"_a = QFont(),
140  "color"_a = ecvColor::defaultLabelBkgColor,
141  "id"_a = "")
142  // TODO as widget
143  .def_static("getScreenSize", &ecvDisplayTools::GetScreenSize)
144  .def_static("getGLCameraParameters", &ecvDisplayTools::GetGLCameraParameters, "params"_a)
145  .def_static("displayNewMessage",
147  "message"_a,
148  "pos"_a,
149  "append"_a = false,
150  "displayMaxDelay_sec"_a = 2,
151  "type"_a = ecvDisplayTools::MessageType::CUSTOM_MESSAGE)
152  .def_static(
153  "setPivotVisibility",
155  "vis"_a)
156  .def_static("getPivotVisibility", &ecvDisplayTools::GetPivotVisibility)
157  .def_static("showPivotSymbol", &ecvDisplayTools::ShowPivotSymbol, "state"_a)
158  .def_static("setPivotPoint",
160  "P"_a,
161  "autoUpdateCameraPos"_a = false,
162  "verbose"_a = false)
163  .def_static("setCameraPos", &ecvDisplayTools::SetCameraPos, "P"_a)
164  .def_static(
165  "moveCamera", [](const CCVector3d &v) { ecvDisplayTools::MoveCamera(v); }, "v"_a)
166  .def_static("setPerspectiveState",
168  "state"_a,
169  "objectCenteredView"_a)
170  .def_static(
171  "getPerspectiveState", &ecvDisplayTools::GetPerspectiveState, "objectCentered"_a)
172  .def_static("objectPerspectiveEnabled", &ecvDisplayTools::ObjectPerspectiveEnabled)
173  .def_static("viewerPerspectiveEnabled", &ecvDisplayTools::ViewerPerspectiveEnabled)
174  .def_static("updateConstellationCenterAndZoom",
176  "boundingBox"_a = nullptr,
177  "redraw"_a = true)
178  .def_static("getVisibleObjectsBB", &ecvDisplayTools::GetVisibleObjectsBB, "box"_a)
179  .def_static(
180  "setView",
181  [](CC_VIEW_ORIENTATION orientation, bool redraw)
182  { ecvDisplayTools::SetView(orientation, redraw); },
183  "orientation"_a,
184  "redraw"_a = true)
185  .def_static("setInteractionMode", &ecvDisplayTools::SetInteractionMode, "flags"_a)
186  .def_static("getInteractionMode", &ecvDisplayTools::GetInteractionMode)
187  .def_static("setPickingMode",
189  "mode"_a = ecvDisplayTools::PICKING_MODE::DEFAULT_PICKING)
190  .def_static("getPickingMode", &ecvDisplayTools::GetPickingMode)
191  .def_static("lockPickingMode", &ecvDisplayTools::LockPickingMode, "state"_a)
192  .def_static("isPickingModeLocked", &ecvDisplayTools::IsPickingModeLocked)
193  .def_static("getContext", &ecvDisplayTools::GetContext, "context"_a)
194  // TODO static constexprs
195  .def_static("setPointSize",
197  "size"_a,
198  "silent"_a = false,
199  "viewport"_a = 0)
200  .def_static("setLineWidth",
202  "width"_a,
203  "silent"_a = false,
204  "viewport"_a = 0)
205  .def_static("getFontPointSize", &ecvDisplayTools::GetFontPointSize)
206  .def_static("getLabelFontPointSize", &ecvDisplayTools::GetLabelFontPointSize)
207  .def_static("getOwnDB", &ecvDisplayTools::GetOwnDB)
208  .def_static("addToOwnDB", &ecvDisplayTools::AddToOwnDB, "obj"_a, "noDependency"_a = false)
209  .def_static("removeFromOwnDB", &ecvDisplayTools::RemoveFromOwnDB, "obj"_a)
210  .def_static(
211  "setViewportParameters", &ecvDisplayTools::SetViewportParameters, "parameters"_a)
212  .def_static("setFov", &ecvDisplayTools::SetFov, "fov"_a)
213  .def_static("getFov", &ecvDisplayTools::GetFov)
214  .def_static("invalidateVisualization", &ecvDisplayTools::InvalidateVisualization)
215  // TODO renderToImage
216  .def_static("renderToFile",
218  "filename"_a,
219  "zoomFactor"_a = 1.0f,
220  "dontScaleFeatures"_a = false,
221  "renderOverlayItems"_a = false)
222  .def_static("computeActualPixelSize", &ecvDisplayTools::ComputeActualPixelSize)
223  .def_static("isRectangularPickingAllowed", &ecvDisplayTools::IsRectangularPickingAllowed)
224  .def_static("setRectangularPickingAllowed",
226  "state"_a)
227  // TODO: this would need a ccGui::ParamStruct binding
228  // .def_static("setShader", &ecvDisplayTools::getDisplayParameters)
229  // .def_static("setDisplayParameter", &ecvDisplayTools::getDisplayParameters,
230  // "params"_a, thisWindowOnly)
231  .def_static("setPickingRadius", &ecvDisplayTools::SetPickingRadius, "radius"_a)
232  .def_static("getPickingRadius", &ecvDisplayTools::GetPickingRadius)
233  .def_static(
234  "displayOverlayEntities", &ecvDisplayTools::DisplayOverlayEntities, "showScale"_a)
235  // display
236  .def_static(
237  "getMainWindow", &ecvDisplayTools::GetMainWindow, py::return_value_policy::reference)
238  .def_static("redrawDisplay",
240  "only2D"_a = false,
241  "forceRedraw"_a = true)
242  .def_static("refreshDisplay",
244  "only2D"_a = false,
245  "forceRedraw"_a = true)
246 
247  .def_static("getScreenSize", &ecvDisplayTools::GetScreenSize)
248  .def_static("toBeRefreshed", &ecvDisplayTools::ToBeRefreshed)
249  .def_static("invalidateViewport", &ecvDisplayTools::InvalidateViewport)
250  .def_static("deprecate3DLayer", &ecvDisplayTools::Deprecate3DLayer)
251  .def_static("getTextDisplayFont", &ecvDisplayTools::GetTextDisplayFont)
252  .def_static("getLabelDisplayFont", &ecvDisplayTools::GetLabelDisplayFont)
253 
254  .def_static(
255  "displayText",
256  [](const QString &text,
257  int x,
258  int y,
259  unsigned char align,
260  float bkgAlpha,
261  const unsigned char *color,
262  const QFont *font,
263  const QString &id)
264  { ecvDisplayTools::DisplayText(text, x, y, align, bkgAlpha, color, font, id); },
265  "text"_a,
266  "x"_a,
267  "y"_a,
268  "align"_a = ecvDisplayTools::ALIGN_DEFAULT,
269  "bkgAlpha"_a = 0.0f,
270  "color"_a = nullptr,
271  "font"_a = nullptr,
272  "id"_a = "")
273  .def_static("display3DLabel",
275  "str"_a,
276  "pos3D"_a,
277  "color"_a = nullptr,
278  "font"_a = QFont())
279  .def_static("remove3DLabel", &ecvDisplayTools::Remove3DLabel, "view_id"_a)
280  .def_static("removeAllWidgets", &ecvDisplayTools::RemoveAllWidgets, "update"_a = true)
281  .def_static("getGLCameraParameters", &ecvDisplayTools::GetGLCameraParameters, "params"_a)
282  .def_static(
283  "toCenteredGLCoordinates", &ecvDisplayTools::ToCenteredGLCoordinates, "x"_a, "y"_a)
284  .def_static("getViewportParameters", &ecvDisplayTools::GetViewportParameters)
285  .def_static("setupProjectiveViewport",
287  "cameraMatrix"_a,
288  "fov_deg"_a = 0.0f,
289  "ar"_a = 1.0f,
290  "viewerBasedPerspective"_a = true,
291  "bubbleViewMode"_a = false)
292  // TODO
293  ;
294 }
CC_VIEW_ORIENTATION
View orientation.
Definition: CVConst.h:102
math::float4 color
void define_ccDisplayTools(py::module &m)
RGB color structure.
Definition: ecvColorTypes.h:49
static void SetSceneDB(ccHObject *root)
static bool RenderToFile(QString filename, float zoomFactor=1.0f, bool dontScaleFeatures=false, bool renderOverlayItems=false)
Renders screen to a file.
static void ShowPivotSymbol(bool state)
Shows or hide the pivot symbol.
static void GetGLCameraParameters(ccGLCameraParameters &params)
Returns the current OpenGL camera parameters.
static void RenderText(int x, int y, const QString &str, const QFont &font=QFont(), const ecvColor::Rgbub &color=ecvColor::defaultLabelBkgColor, const QString &id="")
static int GetDevicePixelRatio()
static void RemoveFromOwnDB(ccHObject *obj)
Removes an entity from window own DB.
static INTERACTION_FLAGS GetInteractionMode()
Returns the current interaction flags.
static void Display3DLabel(const QString &str, const CCVector3 &pos3D, const ecvColor::Rgbub *color=nullptr, const QFont &font=QFont())
Displays a string at a given 3D position.
static bool ObjectPerspectiveEnabled()
Shortcut: returns whether object-based perspective mode is enabled.
static void AddToOwnDB(ccHObject *obj, bool noDependency=true)
Adds an entity to window own DB.
static QPointF ToCenteredGLCoordinates(int x, int y)
static PICKING_MODE GetPickingMode()
static QFont GetTextDisplayFont()
static void InvalidateViewport()
static const ecvViewportParameters & GetViewportParameters()
static bool ViewerPerspectiveEnabled()
Shortcut: returns whether viewer-based perspective mode is enabled.
static int GetPickingRadius()
Returns the current picking radius.
static void GetContext(CC_DRAW_CONTEXT &CONTEXT)
Returns context information.
static ccHObject * GetSceneDB()
static QMainWindow * GetMainWindow()
static void RemoveAllWidgets(bool update=true)
static void SetCameraPos(const CCVector3d &P)
Sets camera position.
static void ToBeRefreshed()
PivotVisibility
Pivot symbol visibility.
static void Deprecate3DLayer()
static int GetFontPointSize()
Returns current font size.
static void DisplayOverlayEntities(bool state)
static bool IsRectangularPickingAllowed()
Returns whether rectangular picking is allowed or not.
static void SetupProjectiveViewport(const ccGLMatrixd &cameraMatrix, float fov_deg=0.0f, float ar=1.0f, bool viewerBasedPerspective=true, bool bubbleViewMode=false)
static void SetViewportParameters(const ecvViewportParameters &params)
static void SetView(CC_VIEW_ORIENTATION orientation, ccBBox *bbox)
static void LockPickingMode(bool state)
Locks picking mode.
static QSize GetScreenSize()
static PivotVisibility GetPivotVisibility()
Returns pivot visibility.
static void SetInteractionMode(INTERACTION_FLAGS flags)
static double ComputeActualPixelSize()
static void SetRectangularPickingAllowed(bool state)
Sets whether rectangular picking is allowed or not.
static void MoveCamera(float dx, float dy, float dz)
Displaces camera.
static int GetLabelFontPointSize()
Returns current font size for labels.
static ccHObject * GetOwnDB()
Returns window own DB.
static void SetPickingRadius(int radius)
Sets picking radius.
static float GetFov()
Returns the current f.o.v. (field of view) in degrees.
static void SetPerspectiveState(bool state, bool objectCenteredView)
Set perspective state/mode.
static void Remove3DLabel(const QString &view_id)
static void SetFov(float fov)
Sets current camera f.o.v. (field of view) in degrees.
static void SetPickingMode(PICKING_MODE mode=DEFAULT_PICKING)
static void DisplayText(const QString &text, int x, int y, unsigned char align=ALIGN_DEFAULT, float bkgAlpha=0.0f, const unsigned char *rgbColor=nullptr, const QFont *font=nullptr, const QString &id="")
Displays a string at a given 2D position.
static void SetPivotPoint(const CCVector3d &P, bool autoUpdateCameraPos=false, bool verbose=false)
Sets pivot point.
static void SetPointSize(float size, bool silent=false, int viewport=0)
static void DoResize(int xw, int yw)
static void DisplayNewMessage(const QString &message, MessagePosition pos, bool append=false, int displayMaxDelay_sec=2, MessageType type=CUSTOM_MESSAGE)
Displays a status message in the bottom-left corner.
static void RefreshDisplay(bool only2D=false, bool forceRedraw=true)
static QFont GetLabelDisplayFont()
static void InvalidateVisualization()
static void UpdateConstellationCenterAndZoom(const ccBBox *aBox=nullptr, bool redraw=true)
Center and zoom on a given bounding box.
static void SetLineWidth(float width, bool silent=false, int viewport=0)
Sets line width.
static void RedrawDisplay(bool only2D=false, bool forceRedraw=true)
static bool IsPickingModeLocked()
Returns whether picking mode is locked or not.
static void GetVisibleObjectsBB(ccBBox &box)
Returns the visible objects bounding-box.
static void SetPivotVisibility(PivotVisibility vis)
Sets pivot visibility.
static bool GetPerspectiveState()
Returns perspective mode.
constexpr Rgbub defaultLabelBkgColor(MAX, MAX, MAX)