Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.15.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
O3DVisualizer.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-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 
34 
35 namespace open3d {
36 
37 namespace geometry {
38 class Geometry3D;
39 class Image;
40 } // namespace geometry
41 
42 namespace t {
43 namespace geometry {
44 class Geometry;
45 } // namespace geometry
46 } // namespace t
47 
48 namespace visualization {
49 
50 namespace rendering {
51 class Open3DScene;
52 struct TriangleMeshModel;
53 } // namespace rendering
54 
55 namespace visualizer {
56 
57 class O3DVisualizer : public gui::Window {
58  using Super = gui::Window;
59 
60 public:
61  enum class Shader { STANDARD, UNLIT, NORMALS, DEPTH };
62 
63  struct DrawObject {
64  std::string name;
65  std::shared_ptr<geometry::Geometry3D> geometry;
66  std::shared_ptr<t::geometry::Geometry> tgeometry;
67  std::shared_ptr<rendering::TriangleMeshModel> model;
69  std::string group;
70  double time = 0.0;
71  bool is_visible = true;
72 
73  // internal
74  bool is_color_default = true;
75  };
76 
77  struct UIState {
79  gui::SceneWidget::Controls::ROTATE_CAMERA;
80  Shader scene_shader = Shader::STANDARD;
81  bool show_settings = false;
82  bool show_skybox = true;
83  bool show_axes = false;
84  bool show_ground = false;
86  rendering::Scene::GroundPlane::XZ;
87  bool is_animating = false;
88  std::set<std::string> enabled_groups;
89 
90  Eigen::Vector4f bg_color = {1.0f, 1.0f, 1.0f, 1.0f};
91  int point_size = 3;
92  int line_width = 2;
93 
94  bool use_ibl = false;
95  bool use_sun = true;
96  bool sun_follows_camera = true;
97  std::string ibl_path = ""; // "" is default path
98  int ibl_intensity = 0;
99  int sun_intensity = 100000;
100  Eigen::Vector3f sun_dir = {0.577f, -0.577f, -0.577f};
101  Eigen::Vector3f sun_color = {1.0f, 1.0f, 1.0f};
102 
103  double current_time = 0.0; // seconds
104  double time_step = 1.0; // seconds
105  double frame_delay = 0.100; // seconds
106  };
107 
108  O3DVisualizer(const std::string& title, int width, int height);
109  virtual ~O3DVisualizer();
110 
111  void AddAction(const std::string& name,
112  std::function<void(O3DVisualizer&)> callback);
113 
114  void SetBackground(const Eigen::Vector4f& bg_color,
115  std::shared_ptr<geometry::Image> bg_image = nullptr);
116 
117  void SetShader(Shader shader);
118 
120  void AddGeometry(const std::string& name,
121  std::shared_ptr<geometry::Geometry3D> geom,
122  const rendering::MaterialRecord* material = nullptr,
123  const std::string& group = "",
124  double time = 0.0,
125  bool is_visible = true);
126 
129  void AddGeometry(const std::string& name,
130  std::shared_ptr<t::geometry::Geometry> tgeom,
131  const rendering::MaterialRecord* material = nullptr,
132  const std::string& group = "",
133  double time = 0.0,
134  bool is_visible = true);
135 
137  void AddGeometry(const std::string& name,
138  std::shared_ptr<rendering::TriangleMeshModel> tgeom,
139  const rendering::MaterialRecord* material = nullptr,
140  const std::string& group = "",
141  double time = 0.0,
142  bool is_visible = true);
143 
145  void RemoveGeometry(const std::string& name);
146 
149  void UpdateGeometry(const std::string& name,
150  std::shared_ptr<t::geometry::Geometry> tgeom,
151  uint32_t update_flags);
152 
154  void ShowGeometry(const std::string& name, bool show);
155 
157  DrawObject GetGeometry(const std::string& name) const;
158  rendering::MaterialRecord GetGeometryMaterial(
159  const std::string& name) const;
160 
161  void ModifyGeometryMaterial(const std::string& name,
162  const rendering::MaterialRecord* material);
163 
165  void Add3DLabel(const Eigen::Vector3f& pos, const char* text);
166 
168  void Clear3DLabels();
169 
170  void SetupCamera(float fov,
171  const Eigen::Vector3f& center,
172  const Eigen::Vector3f& eye,
173  const Eigen::Vector3f& up);
174  void SetupCamera(const camera::PinholeCameraIntrinsic& intrinsic,
175  const Eigen::Matrix4d& extrinsic);
176  void SetupCamera(const Eigen::Matrix3d& intrinsic,
177  const Eigen::Matrix4d& extrinsic,
178  int intrinsic_width_px,
179  int intrinsic_height_px);
180 
181  void ResetCameraToDefault();
182 
183  void ShowSettings(bool show);
184  void ShowSkybox(bool show);
185  void SetIBL(const std::string& path);
186  void SetIBLIntensity(float intensity);
187  void ShowAxes(bool show);
188  void ShowGround(bool show);
189  void SetGroundPlane(rendering::Scene::GroundPlane plane);
190  void EnableSunFollowsCamera(bool enable);
191  void EnableBasicMode(bool enable);
192  void SetPointSize(int point_size);
193  void SetLineWidth(int line_width);
194  void EnableGroup(const std::string& group, bool enable);
195  void SetMouseMode(gui::SceneWidget::Controls mode);
196 
197  std::vector<O3DVisualizerSelections::SelectionSet> GetSelectionSets() const;
198 
199  double GetAnimationFrameDelay() const;
200  void SetAnimationFrameDelay(double secs);
201 
202  double GetAnimationTimeStep() const;
203  void SetAnimationTimeStep(double time_step);
204 
205  double GetAnimationDuration() const;
206  void SetAnimationDuration(double sec);
207 
208  double GetCurrentTime() const;
209  void SetCurrentTime(double t);
210 
211  bool GetIsAnimating() const;
212  void SetAnimating(bool is_animating);
213 
214  void SetOnAnimationFrame(std::function<void(O3DVisualizer&, double)> cb);
215 
216  enum class TickResult { NO_CHANGE, REDRAW };
217  void SetOnAnimationTick(
218  std::function<TickResult(O3DVisualizer&, double, double)> cb);
219 
220  void ExportCurrentImage(const std::string& path);
221 
222  UIState GetUIState() const;
223  rendering::Open3DScene* GetScene() const;
224 
226  void StartRPCInterface(const std::string& address, int timeout);
227 
228  void StopRPCInterface();
229 
230 protected:
231  void Layout(const gui::LayoutContext& context);
232 
233 private:
234  struct Impl;
235  std::unique_ptr<Impl> impl_;
236 };
237 
238 } // namespace visualizer
239 } // namespace visualization
240 } // 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:690
int height
Definition: FilePCD.cpp:72
Definition: Window.h:49
std::shared_ptr< rendering::TriangleMeshModel > model
Definition: O3DVisualizer.h:67
Controls
Definition: SceneWidget.h:88
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 uint32_t
Definition: K4aPlugin.cpp:567
std::string name
Definition: O3DVisualizer.h:64
Contains the pinhole camera intrinsic parameters.
Definition: PinholeCameraIntrinsic.h:51
std::shared_ptr< t::geometry::Geometry > tgeometry
Definition: O3DVisualizer.h:66
ImGuiContext * context
Definition: Window.cpp:95
std::string group
Definition: O3DVisualizer.h:69
std::set< std::string > enabled_groups
Definition: O3DVisualizer.h:88
rendering::MaterialRecord material
Definition: O3DVisualizer.h:68
Definition: PinholeCameraIntrinsic.cpp:35
TickResult
Definition: O3DVisualizer.h:216
std::shared_ptr< geometry::Geometry3D > geometry
Definition: O3DVisualizer.h:65
int width
Definition: FilePCD.cpp:71
std::string name
Definition: FilePCD.cpp:58
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:227