Open3D (C++ API)  0.13.0
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) 2020 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 = false;
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 
118  void AddGeometry(const std::string& name,
119  std::shared_ptr<geometry::Geometry3D> geom,
120  const rendering::Material* material = nullptr,
121  const std::string& group = "",
122  double time = 0.0,
123  bool is_visible = true);
124 
125  void AddGeometry(const std::string& name,
126  std::shared_ptr<t::geometry::Geometry> tgeom,
127  const rendering::Material* material = nullptr,
128  const std::string& group = "",
129  double time = 0.0,
130  bool is_visible = true);
131 
132  void AddGeometry(const std::string& name,
133  std::shared_ptr<rendering::TriangleMeshModel> tgeom,
134  const rendering::Material* material = nullptr,
135  const std::string& group = "",
136  double time = 0.0,
137  bool is_visible = true);
138 
139  void RemoveGeometry(const std::string& name);
140 
141  void ShowGeometry(const std::string& name, bool show);
142 
143  DrawObject GetGeometry(const std::string& name) const;
144 
145  void Add3DLabel(const Eigen::Vector3f& pos, const char* text);
146  void Clear3DLabels();
147 
148  void SetupCamera(float fov,
149  const Eigen::Vector3f& center,
150  const Eigen::Vector3f& eye,
151  const Eigen::Vector3f& up);
152  void SetupCamera(const camera::PinholeCameraIntrinsic& intrinsic,
153  const Eigen::Matrix4d& extrinsic);
154  void SetupCamera(const Eigen::Matrix3d& intrinsic,
155  const Eigen::Matrix4d& extrinsic,
156  int intrinsic_width_px,
157  int intrinsic_height_px);
158 
159  void ResetCameraToDefault();
160 
161  void ShowSettings(bool show);
162  void ShowSkybox(bool show);
163  void ShowAxes(bool show);
164  void ShowGround(bool show);
165  void SetGroundPlane(rendering::Scene::GroundPlane plane);
166  void SetPointSize(int point_size);
167  void SetLineWidth(int line_width);
168  void EnableGroup(const std::string& group, bool enable);
169  void SetMouseMode(gui::SceneWidget::Controls mode);
170 
171  std::vector<O3DVisualizerSelections::SelectionSet> GetSelectionSets() const;
172 
173  double GetAnimationFrameDelay() const;
174  void SetAnimationFrameDelay(double secs);
175 
176  double GetAnimationTimeStep() const;
177  void SetAnimationTimeStep(double time_step);
178 
179  double GetAnimationDuration() const;
180  void SetAnimationDuration(double sec);
181 
182  double GetCurrentTime() const;
183  void SetCurrentTime(double t);
184 
185  bool GetIsAnimating() const;
186  void SetAnimating(bool is_animating);
187 
188  void SetOnAnimationFrame(std::function<void(O3DVisualizer&, double)> cb);
189 
190  enum class TickResult { NO_CHANGE, REDRAW };
191  void SetOnAnimationTick(
192  std::function<TickResult(O3DVisualizer&, double, double)> cb);
193 
194  void ExportCurrentImage(const std::string& path);
195 
196  UIState GetUIState() const;
197  rendering::Open3DScene* GetScene() const;
198 
200  void StartRPCInterface(const std::string& address, int timeout);
201 
202  void StopRPCInterface();
203 
204 protected:
205  void Layout(const gui::LayoutContext& context);
206 
207 private:
208  struct Impl;
209  std::unique_ptr<Impl> impl_;
210 };
211 
212 } // namespace visualizer
213 } // namespace visualization
214 } // 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
Definition: Window.h:49
std::shared_ptr< rendering::TriangleMeshModel > model
Definition: O3DVisualizer.h:67
Controls
Definition: SceneWidget.h:88
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
rendering::Material material
Definition: O3DVisualizer.h:68
std::string group
Definition: O3DVisualizer.h:69
std::set< std::string > enabled_groups
Definition: O3DVisualizer.h:88
Definition: PinholeCameraIntrinsic.cpp:35
TickResult
Definition: O3DVisualizer.h:190
std::string name
Definition: FilePCD.cpp:58
int height
Definition: FilePCD.cpp:72
std::shared_ptr< geometry::Geometry3D > geometry
Definition: O3DVisualizer.h:65
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:227
int width
Definition: FilePCD.cpp:71