Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.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  std::string ibl_path = ""; // "" is default path
97  int ibl_intensity = 0;
98  int sun_intensity = 100000;
99  Eigen::Vector3f sun_dir = {0.577f, -0.577f, -0.577f};
100  Eigen::Vector3f sun_color = {1.0f, 1.0f, 1.0f};
101 
102  double current_time = 0.0; // seconds
103  double time_step = 1.0; // seconds
104  double frame_delay = 0.100; // seconds
105  };
106 
107  O3DVisualizer(const std::string& title, int width, int height);
108  virtual ~O3DVisualizer();
109 
110  void AddAction(const std::string& name,
111  std::function<void(O3DVisualizer&)> callback);
112 
113  void SetBackground(const Eigen::Vector4f& bg_color,
114  std::shared_ptr<geometry::Image> bg_image = nullptr);
115 
116  void SetShader(Shader shader);
117 
119  void AddGeometry(const std::string& name,
120  std::shared_ptr<geometry::Geometry3D> geom,
121  const rendering::MaterialRecord* material = nullptr,
122  const std::string& group = "",
123  double time = 0.0,
124  bool is_visible = true);
125 
128  void AddGeometry(const std::string& name,
129  std::shared_ptr<t::geometry::Geometry> tgeom,
130  const rendering::MaterialRecord* material = nullptr,
131  const std::string& group = "",
132  double time = 0.0,
133  bool is_visible = true);
134 
136  void AddGeometry(const std::string& name,
137  std::shared_ptr<rendering::TriangleMeshModel> tgeom,
138  const rendering::MaterialRecord* material = nullptr,
139  const std::string& group = "",
140  double time = 0.0,
141  bool is_visible = true);
142 
144  void RemoveGeometry(const std::string& name);
145 
148  void UpdateGeometry(const std::string& name,
149  std::shared_ptr<t::geometry::Geometry> tgeom,
150  uint32_t update_flags);
151 
153  void ShowGeometry(const std::string& name, bool show);
154 
156  DrawObject GetGeometry(const std::string& name) const;
157  rendering::MaterialRecord GetGeometryMaterial(
158  const std::string& name) const;
159 
160  void ModifyGeometryMaterial(const std::string& name,
161  const rendering::MaterialRecord* material);
162 
164  void Add3DLabel(const Eigen::Vector3f& pos, const char* text);
165 
167  void Clear3DLabels();
168 
169  void SetupCamera(float fov,
170  const Eigen::Vector3f& center,
171  const Eigen::Vector3f& eye,
172  const Eigen::Vector3f& up);
173  void SetupCamera(const camera::PinholeCameraIntrinsic& intrinsic,
174  const Eigen::Matrix4d& extrinsic);
175  void SetupCamera(const Eigen::Matrix3d& intrinsic,
176  const Eigen::Matrix4d& extrinsic,
177  int intrinsic_width_px,
178  int intrinsic_height_px);
179 
180  void ResetCameraToDefault();
181 
182  void ShowSettings(bool show);
183  void ShowSkybox(bool show);
184  void SetIBL(const std::string& path);
185  void SetIBLIntensity(float intensity);
186  void ShowAxes(bool show);
187  void ShowGround(bool show);
188  void SetGroundPlane(rendering::Scene::GroundPlane plane);
189  void SetPointSize(int point_size);
190  void SetLineWidth(int line_width);
191  void EnableGroup(const std::string& group, bool enable);
192  void SetMouseMode(gui::SceneWidget::Controls mode);
193 
194  std::vector<O3DVisualizerSelections::SelectionSet> GetSelectionSets() const;
195 
196  double GetAnimationFrameDelay() const;
197  void SetAnimationFrameDelay(double secs);
198 
199  double GetAnimationTimeStep() const;
200  void SetAnimationTimeStep(double time_step);
201 
202  double GetAnimationDuration() const;
203  void SetAnimationDuration(double sec);
204 
205  double GetCurrentTime() const;
206  void SetCurrentTime(double t);
207 
208  bool GetIsAnimating() const;
209  void SetAnimating(bool is_animating);
210 
211  void SetOnAnimationFrame(std::function<void(O3DVisualizer&, double)> cb);
212 
213  enum class TickResult { NO_CHANGE, REDRAW };
214  void SetOnAnimationTick(
215  std::function<TickResult(O3DVisualizer&, double, double)> cb);
216 
217  void ExportCurrentImage(const std::string& path);
218 
219  UIState GetUIState() const;
220  rendering::Open3DScene* GetScene() const;
221 
223  void StartRPCInterface(const std::string& address, int timeout);
224 
225  void StopRPCInterface();
226 
227 protected:
228  void Layout(const gui::LayoutContext& context);
229 
230 private:
231  struct Impl;
232  std::unique_ptr<Impl> impl_;
233 };
234 
235 } // namespace visualizer
236 } // namespace visualization
237 } // 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
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:557
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:213
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