Open3D (C++ API)  0.12.0
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) 2018 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 geometry {
38 class AxisAlignedBoundingBox;
39 class Geometry3D;
40 } // namespace geometry
41 
42 namespace t {
43 namespace geometry {
44 class Geometry;
45 } // namespace geometry
46 } // namespace t
47 
48 namespace visualization {
49 namespace rendering {
50 class Camera;
51 class CameraManipulator;
52 class MatrixInteractorLogic;
53 class Open3DScene;
54 class View;
55 } // namespace rendering
56 } // namespace visualization
57 
58 namespace visualization {
59 namespace gui {
60 
61 class Label3D;
62 class Color;
63 
64 class SceneWidget : public Widget {
65  using Super = Widget;
66 
67 public:
69  public:
70  virtual ~MouseInteractor() = default;
71 
72  virtual rendering::MatrixInteractorLogic& GetMatrixInteractor() = 0;
73  virtual void Mouse(const MouseEvent& e) = 0;
74  virtual void Key(const KeyEvent& e) = 0;
75  virtual bool Tick(const TickEvent& e) { return false; }
76  };
77 
78 public:
79  explicit SceneWidget();
80  ~SceneWidget() override;
81 
82  void SetFrame(const Rect& f) override;
83 
84  enum Controls {
86  FLY,
90  PICK_POINTS
91  };
92  void SetViewControls(Controls mode);
93 
94  void SetupCamera(float verticalFoV,
95  const geometry::AxisAlignedBoundingBox& geometry_bounds,
96  const Eigen::Vector3f& center_of_rotation);
97  void SetOnCameraChanged(
98  std::function<void(visualization::rendering::Camera*)>
99  on_cam_changed);
100 
104  void SetOnSunDirectionChanged(
105  std::function<void(const Eigen::Vector3f&)> on_dir_changed);
107  void ShowSkybox(bool is_on);
108 
109  void SetScene(std::shared_ptr<rendering::Open3DScene> scene);
110  std::shared_ptr<rendering::Open3DScene> GetScene() const;
111 
112  rendering::View* GetRenderView() const; // is nullptr if no scene
113 
116  void EnableSceneCaching(bool enable);
117 
120  void ForceRedraw();
121  enum class Quality { FAST, BEST };
122  void SetRenderQuality(Quality level);
123  Quality GetRenderQuality() const;
124 
125  enum class CameraPreset {
126  PLUS_X, // at (X, 0, 0), looking (-1, 0, 0)
127  PLUS_Y, // at (0, Y, 0), looking (0, -1, 0)
128  PLUS_Z // at (0, 0, Z), looking (0, 0, 1) [default OpenGL camera]
129  };
130  void GoToCameraPreset(CameraPreset preset);
131 
133  std::string name;
134  const geometry::Geometry3D* geometry = nullptr;
135  const t::geometry::Geometry* tgeometry = nullptr;
136 
137  PickableGeometry(const std::string& n, const geometry::Geometry3D* g)
138  : name(n), geometry(g) {}
139 
140  PickableGeometry(const std::string& n, const t::geometry::Geometry* t)
141  : name(n), tgeometry(t) {}
142 
146  PickableGeometry(const std::string& n,
147  const geometry::Geometry3D* g,
148  const t::geometry::Geometry* t)
149  : name(n), geometry(g), tgeometry(t) {}
150  };
151 
152  void SetPickableGeometry(const std::vector<PickableGeometry>& geometry);
153  void SetPickablePointSize(int px);
154  void SetOnPointsPicked(
155  std::function<void(
156  const std::map<
157  std::string,
158  std::vector<std::pair<size_t, Eigen::Vector3d>>>&,
159  int)> on_picked);
160 
161  // 3D Labels
162  std::shared_ptr<Label3D> AddLabel(const Eigen::Vector3f& pos,
163  const char* text);
164  void RemoveLabel(std::shared_ptr<Label3D> label);
165 
166  void Layout(const Theme& theme) override;
167  Widget::DrawResult Draw(const DrawContext& context) override;
168 
169  Widget::EventResult Mouse(const MouseEvent& e) override;
170  Widget::EventResult Key(const KeyEvent& e) override;
171  Widget::DrawResult Tick(const TickEvent& e) override;
172 
173 private:
174  visualization::rendering::Camera* GetCamera() const;
175 
176 private:
177  struct Impl;
178  std::unique_ptr<Impl> impl_;
179 };
180 
181 } // namespace gui
182 } // namespace visualization
183 } // 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:54
Definition: Theme.h:39
Controls
Definition: SceneWidget.h:84
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:149
CameraPreset
Definition: SceneWidget.h:125
Definition: Widget.h:62
virtual bool Tick(const TickEvent &e)
Definition: SceneWidget.h:75
Definition: SceneWidget.cpp:646
PickableGeometry(const std::string &n, const geometry::Geometry3D *g, const t::geometry::Geometry *t)
Definition: SceneWidget.h:146
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
PickableGeometry(const std::string &n, const t::geometry::Geometry *t)
Definition: SceneWidget.h:140
Definition: MatrixInteractorLogic.h:39
The base geometry class.
Definition: Geometry.h:38
EventResult
Definition: Widget.h:106
Definition: PinholeCameraIntrinsic.cpp:35
PickableGeometry(const std::string &n, const geometry::Geometry3D *g)
Definition: SceneWidget.h:137
std::string name
Definition: SceneWidget.h:133
Definition: Events.h:172
DrawResult
Definition: Widget.h:98
Definition: SceneWidget.h:64
Quality
Definition: SceneWidget.h:121