Open3D (C++ API)  0.17.0
O3DVisualizer.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 
15 
16 namespace open3d {
17 
18 namespace geometry {
19 class Geometry3D;
20 class Image;
21 } // namespace geometry
22 
23 namespace t {
24 namespace geometry {
25 class Geometry;
26 } // namespace geometry
27 } // namespace t
28 
29 namespace visualization {
30 
31 namespace rendering {
32 class Open3DScene;
33 struct TriangleMeshModel;
34 } // namespace rendering
35 
36 namespace visualizer {
37 
38 class O3DVisualizer : public gui::Window {
39  using Super = gui::Window;
40 
41 public:
42  enum class Shader { STANDARD, UNLIT, NORMALS, DEPTH };
43 
44  struct DrawObject {
45  std::string name;
46  std::shared_ptr<geometry::Geometry3D> geometry;
47  std::shared_ptr<t::geometry::Geometry> tgeometry;
48  std::shared_ptr<rendering::TriangleMeshModel> model;
50  std::string group;
51  double time = 0.0;
52  bool is_visible = true;
53 
54  // internal
55  bool is_color_default = true;
56  };
57 
58  struct UIState {
60  gui::SceneWidget::Controls::ROTATE_CAMERA;
62  bool show_settings = false;
63  bool show_skybox = true;
64  bool show_axes = false;
65  bool show_ground = false;
68  bool is_animating = false;
69  std::set<std::string> enabled_groups;
70 
71  Eigen::Vector4f bg_color = {1.0f, 1.0f, 1.0f, 1.0f};
72  int point_size = 3;
73  int line_width = 2;
74 
75  bool use_ibl = false;
76  bool use_sun = true;
77  bool sun_follows_camera = true;
78  std::string ibl_path = ""; // "" is default path
79  int ibl_intensity = 0;
80  int sun_intensity = 100000;
81  Eigen::Vector3f sun_dir = {0.577f, -0.577f, -0.577f};
82  Eigen::Vector3f sun_color = {1.0f, 1.0f, 1.0f};
83 
84  double current_time = 0.0; // seconds
85  double time_step = 1.0; // seconds
86  double frame_delay = 0.100; // seconds
87  };
88 
89  O3DVisualizer(const std::string& title, int width, int height);
90  virtual ~O3DVisualizer();
91 
92  void AddAction(const std::string& name,
93  std::function<void(O3DVisualizer&)> callback);
94 
95  void SetBackground(const Eigen::Vector4f& bg_color,
96  std::shared_ptr<geometry::Image> bg_image = nullptr);
97 
98  void SetShader(Shader shader);
99 
101  void AddGeometry(const std::string& name,
102  std::shared_ptr<geometry::Geometry3D> geom,
103  const rendering::MaterialRecord* material = nullptr,
104  const std::string& group = "",
105  double time = 0.0,
106  bool is_visible = true);
107 
110  void AddGeometry(const std::string& name,
111  std::shared_ptr<t::geometry::Geometry> tgeom,
112  const rendering::MaterialRecord* material = nullptr,
113  const std::string& group = "",
114  double time = 0.0,
115  bool is_visible = true);
116 
118  void AddGeometry(const std::string& name,
119  std::shared_ptr<rendering::TriangleMeshModel> tgeom,
120  const rendering::MaterialRecord* material = nullptr,
121  const std::string& group = "",
122  double time = 0.0,
123  bool is_visible = true);
124 
126  void RemoveGeometry(const std::string& name);
127 
130  void UpdateGeometry(const std::string& name,
131  std::shared_ptr<t::geometry::Geometry> tgeom,
132  uint32_t update_flags);
133 
135  void ShowGeometry(const std::string& name, bool show);
136 
138  DrawObject GetGeometry(const std::string& name) const;
140  const std::string& name) const;
141 
142  void ModifyGeometryMaterial(const std::string& name,
143  const rendering::MaterialRecord* material);
144 
146  void Add3DLabel(const Eigen::Vector3f& pos, const char* text);
147 
149  void Clear3DLabels();
150 
151  void SetupCamera(float fov,
152  const Eigen::Vector3f& center,
153  const Eigen::Vector3f& eye,
154  const Eigen::Vector3f& up);
155  void SetupCamera(const camera::PinholeCameraIntrinsic& intrinsic,
156  const Eigen::Matrix4d& extrinsic);
157  void SetupCamera(const Eigen::Matrix3d& intrinsic,
158  const Eigen::Matrix4d& extrinsic,
159  int intrinsic_width_px,
160  int intrinsic_height_px);
161 
162  void ResetCameraToDefault();
163 
164  void ShowSettings(bool show);
165  void ShowSkybox(bool show);
166  void SetIBL(const std::string& path);
167  void SetIBLIntensity(float intensity);
168  void ShowAxes(bool show);
169  void ShowGround(bool show);
171  void EnableSunFollowsCamera(bool enable);
172  void EnableBasicMode(bool enable);
173  void EnableWireframeMode(bool enable);
174  void SetPointSize(int point_size);
175  void SetLineWidth(int line_width);
176  void EnableGroup(const std::string& group, bool enable);
178 
179  std::vector<O3DVisualizerSelections::SelectionSet> GetSelectionSets() const;
180 
181  double GetAnimationFrameDelay() const;
182  void SetAnimationFrameDelay(double secs);
183 
184  double GetAnimationTimeStep() const;
185  void SetAnimationTimeStep(double time_step);
186 
187  double GetAnimationDuration() const;
188  void SetAnimationDuration(double sec);
189 
190  double GetCurrentTime() const;
191  void SetCurrentTime(double t);
192 
193  bool GetIsAnimating() const;
194  void SetAnimating(bool is_animating);
195 
196  void SetOnAnimationFrame(std::function<void(O3DVisualizer&, double)> cb);
197 
198  enum class TickResult { NO_CHANGE, REDRAW };
199  void SetOnAnimationTick(
200  std::function<TickResult(O3DVisualizer&, double, double)> cb);
201 
202  void ExportCurrentImage(const std::string& path);
203 
204  UIState GetUIState() const;
206 
208  void StartRPCInterface(const std::string& address, int timeout);
209 
210  void StopRPCInterface();
211 
212 protected:
213  void Layout(const gui::LayoutContext& context);
214 
215 private:
216  struct Impl;
217  std::unique_ptr<Impl> impl_;
218 };
219 
220 } // namespace visualizer
221 } // namespace visualization
222 } // namespace open3d
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:182
ImGuiContext * context
Definition: Window.cpp:76
Contains the pinhole camera intrinsic parameters.
Definition: PinholeCameraIntrinsic.h:32
Controls
Definition: SceneWidget.h:69
Definition: Window.h:30
bool GetIsAnimating() const
Definition: O3DVisualizer.cpp:2470
void SetGroundPlane(rendering::Scene::GroundPlane plane)
Definition: O3DVisualizer.cpp:2404
void ShowGeometry(const std::string &name, bool show)
Show/hide the named geometry.
Definition: O3DVisualizer.cpp:2371
void ModifyGeometryMaterial(const std::string &name, const rendering::MaterialRecord *material)
Definition: O3DVisualizer.cpp:2385
void SetShader(Shader shader)
Definition: O3DVisualizer.cpp:2320
std::vector< O3DVisualizerSelections::SelectionSet > GetSelectionSets() const
Definition: O3DVisualizer.cpp:2433
void SetMouseMode(gui::SceneWidget::Controls mode)
Definition: O3DVisualizer.cpp:2424
void SetupCamera(float fov, const Eigen::Vector3f &center, const Eigen::Vector3f &eye, const Eigen::Vector3f &up)
Definition: O3DVisualizer.cpp:2478
void SetAnimationTimeStep(double time_step)
Definition: O3DVisualizer.cpp:2449
TickResult
Definition: O3DVisualizer.h:198
O3DVisualizer(const std::string &title, int width, int height)
Definition: O3DVisualizer.cpp:2201
void ExportCurrentImage(const std::string &path)
Definition: O3DVisualizer.cpp:2520
void Add3DLabel(const Eigen::Vector3f &pos, const char *text)
Adds a label with text text at the 3D position pos.
Definition: O3DVisualizer.cpp:2355
void EnableBasicMode(bool enable)
Definition: O3DVisualizer.cpp:2408
void SetCurrentTime(double t)
Definition: O3DVisualizer.cpp:2468
double GetCurrentTime() const
Definition: O3DVisualizer.cpp:2464
void SetIBLIntensity(float intensity)
Definition: O3DVisualizer.cpp:2396
void SetBackground(const Eigen::Vector4f &bg_color, std::shared_ptr< geometry::Image > bg_image=nullptr)
Definition: O3DVisualizer.cpp:2314
void SetAnimationFrameDelay(double secs)
Definition: O3DVisualizer.cpp:2441
void EnableGroup(const std::string &group, bool enable)
Definition: O3DVisualizer.cpp:2428
double GetAnimationDuration() const
Definition: O3DVisualizer.cpp:2454
void ShowSkybox(bool show)
Definition: O3DVisualizer.cpp:2392
void Layout(const gui::LayoutContext &context)
Definition: O3DVisualizer.cpp:2524
void SetIBL(const std::string &path)
Definition: O3DVisualizer.cpp:2394
void StopRPCInterface()
Definition: O3DVisualizer.cpp:2281
rendering::Open3DScene * GetScene() const
Definition: O3DVisualizer.cpp:2265
void SetOnAnimationTick(std::function< TickResult(O3DVisualizer &, double, double)> cb)
Definition: O3DVisualizer.cpp:2515
void ShowGround(bool show)
Definition: O3DVisualizer.cpp:2402
DrawObject GetGeometry(const std::string &name) const
Returns Visualizer's internal DrawObject for the named geometry.
Definition: O3DVisualizer.cpp:2375
void ShowAxes(bool show)
Definition: O3DVisualizer.cpp:2400
virtual ~O3DVisualizer()
Definition: O3DVisualizer.cpp:2263
void EnableWireframeMode(bool enable)
Definition: O3DVisualizer.cpp:2412
void SetAnimationDuration(double sec)
Definition: O3DVisualizer.cpp:2458
void AddGeometry(const std::string &name, std::shared_ptr< geometry::Geometry3D > geom, const rendering::MaterialRecord *material=nullptr, const std::string &group="", double time=0.0, bool is_visible=true)
Adds a legacy geometry to the Visualizer.
Definition: O3DVisualizer.cpp:2322
void StartRPCInterface(const std::string &address, int timeout)
Starts the RPC interface. See io/rpc/ZMQReceiver for the parameters.
Definition: O3DVisualizer.cpp:2269
void SetLineWidth(int line_width)
Definition: O3DVisualizer.cpp:2420
void AddAction(const std::string &name, std::function< void(O3DVisualizer &)> callback)
Definition: O3DVisualizer.cpp:2288
UIState GetUIState() const
Definition: O3DVisualizer.cpp:2502
rendering::MaterialRecord GetGeometryMaterial(const std::string &name) const
Definition: O3DVisualizer.cpp:2380
void AddGeometry(const std::string &name, std::shared_ptr< rendering::TriangleMeshModel > tgeom, const rendering::MaterialRecord *material=nullptr, const std::string &group="", double time=0.0, bool is_visible=true)
Adds a triangle mesh model to the Visualizer.
void UpdateGeometry(const std::string &name, std::shared_ptr< t::geometry::Geometry > tgeom, uint32_t update_flags)
Definition: O3DVisualizer.cpp:2361
void SetPointSize(int point_size)
Definition: O3DVisualizer.cpp:2416
void ShowSettings(bool show)
Definition: O3DVisualizer.cpp:2390
double GetAnimationFrameDelay() const
Definition: O3DVisualizer.cpp:2437
void SetAnimating(bool is_animating)
Definition: O3DVisualizer.cpp:2474
void SetOnAnimationFrame(std::function< void(O3DVisualizer &, double)> cb)
Definition: O3DVisualizer.cpp:2506
void Clear3DLabels()
Clears all 3D labels created with Add3DLabel
Definition: O3DVisualizer.cpp:2359
double GetAnimationTimeStep() const
Definition: O3DVisualizer.cpp:2445
void ResetCameraToDefault()
Definition: O3DVisualizer.cpp:2498
void RemoveGeometry(const std::string &name)
Removes the named geometry from the Visualizer.
Definition: O3DVisualizer.cpp:2367
int width
Definition: FilePCD.cpp:52
std::string name
Definition: FilePCD.cpp:39
int height
Definition: FilePCD.cpp:53
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:548
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
std::string name
Definition: O3DVisualizer.h:45
std::shared_ptr< t::geometry::Geometry > tgeometry
Definition: O3DVisualizer.h:47
rendering::MaterialRecord material
Definition: O3DVisualizer.h:49
std::shared_ptr< geometry::Geometry3D > geometry
Definition: O3DVisualizer.h:46
std::shared_ptr< rendering::TriangleMeshModel > model
Definition: O3DVisualizer.h:48
std::string group
Definition: O3DVisualizer.h:50
double frame_delay
Definition: O3DVisualizer.h:86
bool show_settings
Definition: O3DVisualizer.h:62
Eigen::Vector3f sun_color
Definition: O3DVisualizer.h:82
gui::SceneWidget::Controls mouse_mode
Definition: O3DVisualizer.h:59
std::set< std::string > enabled_groups
Definition: O3DVisualizer.h:69
Eigen::Vector3f sun_dir
Definition: O3DVisualizer.h:81
double time_step
Definition: O3DVisualizer.h:85
Eigen::Vector4f bg_color
Definition: O3DVisualizer.h:71
Shader scene_shader
Definition: O3DVisualizer.h:61
rendering::Scene::GroundPlane ground_plane
Definition: O3DVisualizer.h:66
bool sun_follows_camera
Definition: O3DVisualizer.h:77
double current_time
Definition: O3DVisualizer.h:84
std::string ibl_path
Definition: O3DVisualizer.h:78