Open3D (C++ API)  0.18.0
Loading...
Searching...
No Matches
SceneWidget.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2023 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include <map>
11
15
16namespace open3d {
17
18namespace camera {
19class PinholeCameraIntrinsic;
20} // namespace camera
21
22namespace geometry {
23class AxisAlignedBoundingBox;
24class Geometry3D;
25} // namespace geometry
26
27namespace t {
28namespace geometry {
29class Geometry;
30} // namespace geometry
31} // namespace t
32
33namespace visualization {
34namespace rendering {
35class Camera;
36class CameraManipulator;
37class MatrixInteractorLogic;
38class Open3DScene;
39class View;
40} // namespace rendering
41} // namespace visualization
42
43namespace visualization {
44namespace gui {
45
46class Label3D;
47class Color;
48
49class SceneWidget : public Widget {
50 using Super = Widget;
51
52public:
54 public:
55 virtual ~MouseInteractor() = default;
56
58 virtual void Mouse(const MouseEvent& e) = 0;
59 virtual void Key(const KeyEvent& e) = 0;
60 virtual bool Tick(const TickEvent& e) { return false; }
61 };
62
63public:
64 explicit SceneWidget();
65 ~SceneWidget() override;
66
67 void SetFrame(const Rect& f) override;
68
78 void SetViewControls(Controls mode);
79
80 void SetupCamera(float verticalFoV,
81 const geometry::AxisAlignedBoundingBox& scene_bounds,
82 const Eigen::Vector3f& center_of_rotation);
83 void SetupCamera(const camera::PinholeCameraIntrinsic& intrinsic,
84 const Eigen::Matrix4d& extrinsic,
85 const geometry::AxisAlignedBoundingBox& scene_bounds);
86 void SetupCamera(const Eigen::Matrix3d& intrinsic,
87 const Eigen::Matrix4d& extrinsic,
88 int intrinsic_width_px,
89 int intrinsic_height_px,
90 const geometry::AxisAlignedBoundingBox& scene_bounds);
91 void LookAt(const Eigen::Vector3f& center,
92 const Eigen::Vector3f& eye,
93 const Eigen::Vector3f& up);
94
96 std::function<void(visualization::rendering::Camera*)>
97 on_cam_changed);
98
99 Eigen::Vector3f GetCenterOfRotation() const;
100 void SetCenterOfRotation(const Eigen::Vector3f& center);
101
106 std::function<void(const Eigen::Vector3f&)> on_dir_changed);
107
108 void SetScene(std::shared_ptr<rendering::Open3DScene> scene);
109 std::shared_ptr<rendering::Open3DScene> GetScene() const;
110
111 rendering::View* GetRenderView() const; // is nullptr if no scene
112
115 void EnableSceneCaching(bool enable);
116
119 void ForceRedraw();
120 enum class Quality { FAST, BEST };
121 void SetRenderQuality(Quality level);
123
124 enum class CameraPreset {
125 PLUS_X, // at (X, 0, 0), looking (-1, 0, 0)
126 PLUS_Y, // at (0, Y, 0), looking (0, -1, 0)
127 PLUS_Z // at (0, 0, Z), looking (0, 0, 1) [default OpenGL camera]
128 };
129 void GoToCameraPreset(CameraPreset preset);
130
132 std::string name;
135
136 PickableGeometry(const std::string& n, const geometry::Geometry3D* g)
137 : name(n), geometry(g) {}
138
139 PickableGeometry(const std::string& n, const t::geometry::Geometry* t)
140 : name(n), tgeometry(t) {}
141
145 PickableGeometry(const std::string& n,
146 const geometry::Geometry3D* g,
147 const t::geometry::Geometry* t)
148 : name(n), geometry(g), tgeometry(t) {}
149 };
150
151 void SetSunInteractorEnabled(bool enable);
152
153 void SetPickableGeometry(const std::vector<PickableGeometry>& geometry);
154 void SetPickablePointSize(int px);
156 std::function<void(
157 const std::map<
158 std::string,
159 std::vector<std::pair<size_t, Eigen::Vector3d>>>&,
160 int)> on_picked);
161 void SetOnStartedPolygonPicking(std::function<void()> on_poly_pick);
162 enum class PolygonPickAction { CANCEL = 0, SELECT };
163 void DoPolygonPick(PolygonPickAction action);
164
165 // 3D Labels
166 std::shared_ptr<Label3D> AddLabel(const Eigen::Vector3f& pos,
167 const char* text);
168 void RemoveLabel(std::shared_ptr<Label3D> label);
169 void ClearLabels();
170
172
173 Widget::EventResult Mouse(const MouseEvent& e) override;
174 Widget::EventResult Key(const KeyEvent& e) override;
175 Widget::DrawResult Tick(const TickEvent& e) override;
176
177private:
178 visualization::rendering::Camera* GetCamera() const;
179
180private:
181 struct Impl;
182 std::unique_ptr<Impl> impl_;
183};
184
185} // namespace gui
186} // namespace visualization
187} // namespace open3d
ImGuiContext * context
Definition Window.cpp:76
Contains the pinhole camera intrinsic parameters.
Definition PinholeCameraIntrinsic.h:32
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition BoundingVolume.h:160
The base geometry class for 3D geometries.
Definition Geometry3D.h:28
The base geometry class.
Definition Geometry.h:21
virtual bool Tick(const TickEvent &e)
Definition SceneWidget.h:60
virtual rendering::MatrixInteractorLogic & GetMatrixInteractor()=0
Definition SceneWidget.h:49
void GoToCameraPreset(CameraPreset preset)
Definition SceneWidget.cpp:1030
void LookAt(const Eigen::Vector3f &center, const Eigen::Vector3f &eye, const Eigen::Vector3f &up)
Definition SceneWidget.cpp:872
void SetOnPointsPicked(std::function< void(const std::map< std::string, std::vector< std::pair< size_t, Eigen::Vector3d > > > &, int)> on_picked)
Definition SceneWidget.cpp:917
~SceneWidget() override
Definition SceneWidget.cpp:801
void RemoveLabel(std::shared_ptr< Label3D > label)
Definition SceneWidget.cpp:1073
PolygonPickAction
Definition SceneWidget.h:162
void SetOnCameraChanged(std::function< void(visualization::rendering::Camera *)> on_cam_changed)
Definition SceneWidget.cpp:888
void SetScene(std::shared_ptr< rendering::Open3DScene > scene)
Definition SceneWidget.cpp:926
void SetFrame(const Rect &f) override
Definition SceneWidget.cpp:805
void SetupCamera(float verticalFoV, const geometry::AxisAlignedBoundingBox &scene_bounds, const Eigen::Vector3f &center_of_rotation)
Definition SceneWidget.cpp:821
void SetSunInteractorEnabled(bool enable)
Definition SceneWidget.cpp:904
void ForceRedraw()
Definition SceneWidget.cpp:998
void SetOnStartedPolygonPicking(std::function< void()> on_poly_pick)
Definition SceneWidget.cpp:940
Widget::EventResult Key(const KeyEvent &e) override
Definition SceneWidget.cpp:1201
void SetViewControls(Controls mode)
Definition SceneWidget.cpp:968
void SetOnSunDirectionChanged(std::function< void(const Eigen::Vector3f &)> on_dir_changed)
Definition SceneWidget.cpp:893
void SetRenderQuality(Quality level)
Definition SceneWidget.cpp:1006
void DoPolygonPick(PolygonPickAction action)
Definition SceneWidget.cpp:945
rendering::View * GetRenderView() const
Definition SceneWidget.cpp:960
Quality
Definition SceneWidget.h:120
Quality GetRenderQuality() const
Definition SceneWidget.cpp:1026
void SetCenterOfRotation(const Eigen::Vector3f &center)
Definition SceneWidget.cpp:884
void SetPickablePointSize(int px)
Definition SceneWidget.cpp:913
void SetPickableGeometry(const std::vector< PickableGeometry > &geometry)
Definition SceneWidget.cpp:908
CameraPreset
Definition SceneWidget.h:124
Eigen::Vector3f GetCenterOfRotation() const
Definition SceneWidget.cpp:880
Widget::DrawResult Tick(const TickEvent &e) override
Definition SceneWidget.cpp:1210
Widget::DrawResult Draw(const DrawContext &context) override
Definition SceneWidget.cpp:1082
Controls
Definition SceneWidget.h:69
@ ROTATE_CAMERA_SPHERE
Definition SceneWidget.h:71
@ ROTATE_IBL
Definition SceneWidget.h:74
@ ROTATE_CAMERA
Definition SceneWidget.h:70
@ FLY
Definition SceneWidget.h:72
@ ROTATE_SUN
Definition SceneWidget.h:73
@ ROTATE_MODEL
Definition SceneWidget.h:75
@ PICK_POINTS
Definition SceneWidget.h:76
std::shared_ptr< rendering::Open3DScene > GetScene() const
Definition SceneWidget.cpp:956
SceneWidget()
Definition SceneWidget.cpp:796
Widget::EventResult Mouse(const MouseEvent &e) override
Definition SceneWidget.cpp:1169
void EnableSceneCaching(bool enable)
Definition SceneWidget.cpp:990
void ClearLabels()
Definition SceneWidget.cpp:1080
std::shared_ptr< Label3D > AddLabel(const Eigen::Vector3f &pos, const char *text)
Definition SceneWidget.cpp:1066
Widget()
Definition Widget.cpp:34
EventResult
Definition Widget.h:103
DrawResult
Definition Widget.h:95
Definition MatrixInteractorLogic.h:20
Definition PinholeCameraIntrinsic.cpp:16
PickableGeometry(const std::string &n, const t::geometry::Geometry *t)
Definition SceneWidget.h:139
PickableGeometry(const std::string &n, const geometry::Geometry3D *g, const t::geometry::Geometry *t)
Definition SceneWidget.h:145
const t::geometry::Geometry * tgeometry
Definition SceneWidget.h:134
PickableGeometry(const std::string &n, const geometry::Geometry3D *g)
Definition SceneWidget.h:136
std::string name
Definition SceneWidget.h:132
const geometry::Geometry3D * geometry
Definition SceneWidget.h:133