Open3D (C++ API)  0.12.0
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 
32 
33 namespace open3d {
34 
35 namespace geometry {
36 class Geometry3D;
37 class Image;
38 } // namespace geometry
39 
40 namespace t {
41 namespace geometry {
42 class Geometry;
43 } // namespace geometry
44 } // namespace t
45 
46 namespace visualization {
47 
48 namespace rendering {
49 class Open3DScene;
50 } // namespace rendering
51 
52 namespace visualizer {
53 
54 class O3DVisualizer : public gui::Window {
55  using Super = gui::Window;
56 
57 public:
58  enum class Shader { STANDARD, UNLIT, NORMALS, DEPTH };
59 
60  struct DrawObject {
61  std::string name;
62  std::shared_ptr<geometry::Geometry3D> geometry;
63  std::shared_ptr<t::geometry::Geometry> tgeometry;
65  std::string group;
66  double time = 0.0;
67  bool is_visible = true;
68 
69  // internal
70  bool is_color_default = true;
71  };
72 
73  struct UIState {
74  Shader scene_shader = Shader::STANDARD;
75  bool show_settings = false;
76  bool show_skybox = false;
77  bool show_axes = false;
78  bool is_animating = false;
79  std::set<std::string> enabled_groups;
80 
81  Eigen::Vector4f bg_color = {1.0f, 1.0f, 1.0f, 1.0f};
82  int point_size = 3;
83  int line_width = 2;
84 
85  bool use_ibl = false;
86  bool use_sun = true;
87  std::string ibl_path = ""; // "" is default path
88  int ibl_intensity = 0;
89  int sun_intensity = 100000;
90  Eigen::Vector3f sun_dir = {0.577f, -0.577f, -0.577f};
91  Eigen::Vector3f sun_color = {1.0f, 1.0f, 1.0f};
92 
93  double current_time = 0.0; // seconds
94  double time_step = 1.0; // seconds
95  double frame_delay = 0.100; // seconds
96  };
97 
98  O3DVisualizer(const std::string& title, int width, int height);
99  virtual ~O3DVisualizer();
100 
101  void AddAction(const std::string& name,
102  std::function<void(O3DVisualizer&)> callback);
103 
104  void SetBackground(const Eigen::Vector4f& bg_color,
105  std::shared_ptr<geometry::Image> bg_image = nullptr);
106 
107  void SetShader(Shader shader);
108 
109  void AddGeometry(const std::string& name,
110  std::shared_ptr<geometry::Geometry3D> geom,
111  rendering::Material* material = nullptr,
112  const std::string& group = "",
113  double time = 0.0,
114  bool is_visible = true);
115 
116  void AddGeometry(const std::string& name,
117  std::shared_ptr<t::geometry::Geometry> tgeom,
118  rendering::Material* material = nullptr,
119  const std::string& group = "",
120  double time = 0.0,
121  bool is_visible = true);
122 
123  void RemoveGeometry(const std::string& name);
124 
125  void ShowGeometry(const std::string& name, bool show);
126 
127  DrawObject GetGeometry(const std::string& name) const;
128 
129  void SetupCamera(float fov,
130  const Eigen::Vector3f& center,
131  const Eigen::Vector3f& eye,
132  const Eigen::Vector3f& up);
133  void ResetCameraToDefault();
134 
135  void ShowSettings(bool show);
136  void ShowSkybox(bool show);
137  void ShowAxes(bool show);
138  void SetPointSize(int point_size);
139  void SetLineWidth(int line_width);
140  void EnableGroup(const std::string& group, bool enable);
141 
142  std::vector<O3DVisualizerSelections::SelectionSet> GetSelectionSets() const;
143 
144  double GetAnimationFrameDelay() const;
145  void SetAnimationFrameDelay(double secs);
146 
147  double GetAnimationTimeStep() const;
148  void SetAnimationTimeStep(double time_step);
149 
150  double GetAnimationDuration() const;
151  void SetAnimationDuration(double sec);
152 
153  double GetCurrentTime() const;
154  void SetCurrentTime(double t);
155 
156  bool GetIsAnimating() const;
157  void SetAnimating(bool is_animating);
158 
159  void SetOnAnimationFrame(std::function<void(O3DVisualizer&, double)> cb);
160 
161  enum class TickResult { NO_CHANGE, REDRAW };
162  void SetOnAnimationTick(
163  std::function<TickResult(O3DVisualizer&, double, double)> cb);
164 
165  void ExportCurrentImage(const std::string& path);
166 
167  UIState GetUIState() const;
168  rendering::Open3DScene* GetScene() const;
169 
171  void StartRPCInterface(const std::string& address, int timeout);
172 
173  void StopRPCInterface();
174 
175 protected:
176  void Layout(const gui::Theme& theme);
177 
178 private:
179  struct Impl;
180  std::unique_ptr<Impl> impl_;
181 };
182 
183 } // namespace visualizer
184 } // namespace visualization
185 } // namespace open3d
Definition: Theme.h:39
Definition: Window.h:50
std::string name
Definition: O3DVisualizer.h:61
std::shared_ptr< t::geometry::Geometry > tgeometry
Definition: O3DVisualizer.h:63
rendering::Material material
Definition: O3DVisualizer.h:64
std::string group
Definition: O3DVisualizer.h:65
std::set< std::string > enabled_groups
Definition: O3DVisualizer.h:79
Definition: PinholeCameraIntrinsic.cpp:35
TickResult
Definition: O3DVisualizer.h:161
std::string name
Definition: FilePCD.cpp:58
int height
Definition: FilePCD.cpp:72
std::shared_ptr< geometry::Geometry3D > geometry
Definition: O3DVisualizer.h:62
int width
Definition: FilePCD.cpp:71