Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SceneWidget.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <map>
30 
34 
35 namespace open3d {
36 
37 namespace camera {
38 class PinholeCameraIntrinsic;
39 } // namespace camera
40 
41 namespace geometry {
42 class AxisAlignedBoundingBox;
43 class Geometry3D;
44 } // namespace geometry
45 
46 namespace t {
47 namespace geometry {
48 class Geometry;
49 } // namespace geometry
50 } // namespace t
51 
52 namespace visualization {
53 namespace rendering {
54 class Camera;
55 class CameraManipulator;
56 class MatrixInteractorLogic;
57 class Open3DScene;
58 class View;
59 } // namespace rendering
60 } // namespace visualization
61 
62 namespace visualization {
63 namespace gui {
64 
65 class Label3D;
66 class Color;
67 
68 class SceneWidget : public Widget {
69  using Super = Widget;
70 
71 public:
73  public:
74  virtual ~MouseInteractor() = default;
75 
76  virtual rendering::MatrixInteractorLogic& GetMatrixInteractor() = 0;
77  virtual void Mouse(const MouseEvent& e) = 0;
78  virtual void Key(const KeyEvent& e) = 0;
79  virtual bool Tick(const TickEvent& e) { return false; }
80  };
81 
82 public:
83  explicit SceneWidget();
84  ~SceneWidget() override;
85 
86  void SetFrame(const Rect& f) override;
87 
88  enum Controls {
91  FLY,
95  PICK_POINTS
96  };
97  void SetViewControls(Controls mode);
98 
99  void SetupCamera(float verticalFoV,
100  const geometry::AxisAlignedBoundingBox& scene_bounds,
101  const Eigen::Vector3f& center_of_rotation);
102  void SetupCamera(const camera::PinholeCameraIntrinsic& intrinsic,
103  const Eigen::Matrix4d& extrinsic,
104  const geometry::AxisAlignedBoundingBox& scene_bounds);
105  void SetupCamera(const Eigen::Matrix3d& intrinsic,
106  const Eigen::Matrix4d& extrinsic,
107  int intrinsic_width_px,
108  int intrinsic_height_px,
109  const geometry::AxisAlignedBoundingBox& scene_bounds);
110  void LookAt(const Eigen::Vector3f& center,
111  const Eigen::Vector3f& eye,
112  const Eigen::Vector3f& up);
113 
114  void SetOnCameraChanged(
115  std::function<void(visualization::rendering::Camera*)>
116  on_cam_changed);
117 
118  Eigen::Vector3f GetCenterOfRotation() const;
119  void SetCenterOfRotation(const Eigen::Vector3f& center);
120 
124  void SetOnSunDirectionChanged(
125  std::function<void(const Eigen::Vector3f&)> on_dir_changed);
126 
127  void SetScene(std::shared_ptr<rendering::Open3DScene> scene);
128  std::shared_ptr<rendering::Open3DScene> GetScene() const;
129 
130  rendering::View* GetRenderView() const; // is nullptr if no scene
131 
134  void EnableSceneCaching(bool enable);
135 
138  void ForceRedraw();
139  enum class Quality { FAST, BEST };
140  void SetRenderQuality(Quality level);
141  Quality GetRenderQuality() const;
142 
143  enum class CameraPreset {
144  PLUS_X, // at (X, 0, 0), looking (-1, 0, 0)
145  PLUS_Y, // at (0, Y, 0), looking (0, -1, 0)
146  PLUS_Z // at (0, 0, Z), looking (0, 0, 1) [default OpenGL camera]
147  };
148  void GoToCameraPreset(CameraPreset preset);
149 
151  std::string name;
152  const geometry::Geometry3D* geometry = nullptr;
153  const t::geometry::Geometry* tgeometry = nullptr;
154 
155  PickableGeometry(const std::string& n, const geometry::Geometry3D* g)
156  : name(n), geometry(g) {}
157 
158  PickableGeometry(const std::string& n, const t::geometry::Geometry* t)
159  : name(n), tgeometry(t) {}
160 
164  PickableGeometry(const std::string& n,
165  const geometry::Geometry3D* g,
166  const t::geometry::Geometry* t)
167  : name(n), geometry(g), tgeometry(t) {}
168  };
169 
170  void SetSunInteractorEnabled(bool enable);
171 
172  void SetPickableGeometry(const std::vector<PickableGeometry>& geometry);
173  void SetPickablePointSize(int px);
174  void SetOnPointsPicked(
175  std::function<void(
176  const std::map<
177  std::string,
178  std::vector<std::pair<size_t, Eigen::Vector3d>>>&,
179  int)> on_picked);
180  void SetOnStartedPolygonPicking(std::function<void()> on_poly_pick);
181  enum class PolygonPickAction { CANCEL = 0, SELECT };
182  void DoPolygonPick(PolygonPickAction action);
183 
184  // 3D Labels
185  std::shared_ptr<Label3D> AddLabel(const Eigen::Vector3f& pos,
186  const char* text);
187  void RemoveLabel(std::shared_ptr<Label3D> label);
188  void ClearLabels();
189 
190  Widget::DrawResult Draw(const DrawContext& context) override;
191 
192  Widget::EventResult Mouse(const MouseEvent& e) override;
193  Widget::EventResult Key(const KeyEvent& e) override;
194  Widget::DrawResult Tick(const TickEvent& e) override;
195 
196 private:
197  visualization::rendering::Camera* GetCamera() const;
198 
199 private:
200  struct Impl;
201  std::unique_ptr<Impl> impl_;
202 };
203 
204 } // namespace gui
205 } // namespace visualization
206 } // namespace open3d
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:680
void Draw(const std::vector< std::shared_ptr< geometry::Geometry3D >> &geometries, const std::string &window_name, int width, int height, const std::vector< DrawAction > &actions)
Definition: Draw.cpp:63
Controls
Definition: SceneWidget.h:88
PolygonPickAction
Definition: SceneWidget.h:181
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:150
CameraPreset
Definition: SceneWidget.h:143
Definition: Widget.h:68
Contains the pinhole camera intrinsic parameters.
Definition: PinholeCameraIntrinsic.h:51
virtual bool Tick(const TickEvent &e)
Definition: SceneWidget.h:79
Definition: SceneWidget.cpp:764
PickableGeometry(const std::string &n, const geometry::Geometry3D *g, const t::geometry::Geometry *t)
Definition: SceneWidget.h:164
ImGuiContext * context
Definition: Window.cpp:95
GLMatrix4f LookAt(const Eigen::Vector3d &eye, const Eigen::Vector3d &lookat, const Eigen::Vector3d &up)
Definition: GLHelper.cpp:36
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
PickableGeometry(const std::string &n, const t::geometry::Geometry *t)
Definition: SceneWidget.h:158
Definition: MatrixInteractorLogic.h:39
The base geometry class.
Definition: Geometry.h:38
EventResult
Definition: Widget.h:122
Definition: PinholeCameraIntrinsic.cpp:35
PickableGeometry(const std::string &n, const geometry::Geometry3D *g)
Definition: SceneWidget.h:155
std::string name
Definition: SceneWidget.h:151
Definition: Events.h:210
DrawResult
Definition: Widget.h:114
Definition: SceneWidget.h:68
Quality
Definition: SceneWidget.h:139