Open3D (C++ API)  0.18.0+c1b55ee
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 
16 namespace open3d {
17 
18 namespace camera {
19 class PinholeCameraIntrinsic;
20 } // namespace camera
21 
22 namespace geometry {
23 class AxisAlignedBoundingBox;
24 class Geometry3D;
25 } // namespace geometry
26 
27 namespace t {
28 namespace geometry {
29 class Geometry;
30 } // namespace geometry
31 } // namespace t
32 
33 namespace visualization {
34 namespace rendering {
35 class Camera;
36 class CameraManipulator;
37 class MatrixInteractorLogic;
38 class Open3DScene;
39 class View;
40 } // namespace rendering
41 } // namespace visualization
42 
43 namespace visualization {
44 namespace gui {
45 
46 class Label3D;
47 class Color;
48 
49 class SceneWidget : public Widget {
50  using Super = Widget;
51 
52 public:
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 
63 public:
64  explicit SceneWidget();
65  ~SceneWidget() override;
66 
67  void SetFrame(const Rect& f) override;
68 
69  enum Controls {
72  FLY,
77  };
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 
95  void SetOnCameraChanged(
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);
122  Quality GetRenderQuality() const;
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;
133  const geometry::Geometry3D* geometry = nullptr;
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);
155  void SetOnPointsPicked(
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 
171  Widget::DrawResult Draw(const DrawContext& context) override;
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 
177 private:
178  visualization::rendering::Camera* GetCamera() const;
179 
180 private:
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 rendering::MatrixInteractorLogic & GetMatrixInteractor()=0
virtual bool Tick(const TickEvent &e)
Definition: SceneWidget.h:60
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
~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
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
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
Definition: Widget.h:49
Widget()
Definition: Widget.cpp:34
EventResult
Definition: Widget.h:103
DrawResult
Definition: Widget.h:95
Definition: MatrixInteractorLogic.h:20
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t int32_t int32_t int32_t k4a_color_control_mode_t default_mode mode
Definition: K4aPlugin.cpp:678
Definition: PinholeCameraIntrinsic.cpp:16
Definition: Events.h:203
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