ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
O3DVisualizer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
15 
16 class ccHObject;
17 namespace cloudViewer {
18 
19 namespace geometry {
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 CloudViewerScene;
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<ccHObject> 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 
100  void AddGeometry(const std::string& name,
101  std::shared_ptr<ccHObject> geom,
102  const rendering::MaterialRecord* material = nullptr,
103  const std::string& group = "",
104  double time = 0.0,
105  bool is_visible = true);
106 
107  void AddGeometry(const std::string& name,
108  std::shared_ptr<t::geometry::Geometry> tgeom,
109  const rendering::MaterialRecord* material = nullptr,
110  const std::string& group = "",
111  double time = 0.0,
112  bool is_visible = true);
113 
114  void AddGeometry(const std::string& name,
115  std::shared_ptr<rendering::TriangleMeshModel> tgeom,
116  const rendering::MaterialRecord* material = nullptr,
117  const std::string& group = "",
118  double time = 0.0,
119  bool is_visible = true);
120 
122  void RemoveGeometry(const std::string& name);
123 
126  void UpdateGeometry(const std::string& name,
127  std::shared_ptr<t::geometry::Geometry> tgeom,
128  uint32_t update_flags);
129 
131  void ShowGeometry(const std::string& name, bool show);
132 
134  DrawObject GetGeometry(const std::string& name) const;
136  const std::string& name) const;
137 
138  void ModifyGeometryMaterial(const std::string& name,
139  const rendering::MaterialRecord* material);
140 
141  void Add3DLabel(const Eigen::Vector3f& pos, const char* text);
142  void Clear3DLabels();
143 
144  void SetupCamera(float fov,
145  const Eigen::Vector3f& center,
146  const Eigen::Vector3f& eye,
147  const Eigen::Vector3f& up);
148  void SetupCamera(const camera::PinholeCameraIntrinsic& intrinsic,
149  const Eigen::Matrix4d& extrinsic);
150  void SetupCamera(const Eigen::Matrix3d& intrinsic,
151  const Eigen::Matrix4d& extrinsic,
152  int intrinsic_width_px,
153  int intrinsic_height_px);
154 
155  void ResetCameraToDefault();
156 
157  void ShowSettings(bool show);
158  void ShowSkybox(bool show);
159  void SetIBL(const std::string& path);
160  void SetIBLIntensity(float intensity);
161  void ShowAxes(bool show);
162  void ShowGround(bool show);
164  void EnableSunFollowsCamera(bool enable);
165  void EnableBasicMode(bool enable);
166  void EnableWireframeMode(bool enable);
167  void SetPointSize(int point_size);
168  void SetLineWidth(int line_width);
169  void EnableGroup(const std::string& group, bool enable);
171  void SetPanelOpen(const std::string& name, bool open);
172 
173  std::vector<O3DVisualizerSelections::SelectionSet> GetSelectionSets() const;
174 
175  double GetAnimationFrameDelay() const;
176  void SetAnimationFrameDelay(double secs);
177 
178  double GetAnimationTimeStep() const;
179  void SetAnimationTimeStep(double time_step);
180 
181  double GetAnimationDuration() const;
182  void SetAnimationDuration(double sec);
183 
184  double GetCurrentTime() const;
185  void SetCurrentTime(double t);
186 
187  bool GetIsAnimating() const;
188  void SetAnimating(bool is_animating);
189 
190  void SetOnAnimationFrame(std::function<void(O3DVisualizer&, double)> cb);
191 
192  enum class TickResult { NO_CHANGE, REDRAW };
193  void SetOnAnimationTick(
194  std::function<TickResult(O3DVisualizer&, double, double)> cb);
195 
196  void ExportCurrentImage(const std::string& path);
197 
198  UIState GetUIState() const;
200 
202  void StartRPCInterface(const std::string& address, int timeout);
203 
204  void StopRPCInterface();
205 
206 protected:
207  void Layout(const gui::LayoutContext& context);
208 
209 private:
210  struct Impl;
211  std::unique_ptr<Impl> impl_;
212 };
213 
214 } // namespace visualizer
215 } // namespace visualization
216 } // namespace cloudViewer
std::function< void(std::shared_ptr< core::Tensor >)> callback
int width
std::string name
int height
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Contains the pinhole camera intrinsic parameters.
void StartRPCInterface(const std::string &address, int timeout)
Starts the RPC interface. See io/rpc/ZMQReceiver for the parameters.
void SetMouseMode(gui::SceneWidget::Controls mode)
void SetOnAnimationTick(std::function< TickResult(O3DVisualizer &, double, double)> cb)
void SetGroundPlane(rendering::Scene::GroundPlane plane)
void SetBackground(const Eigen::Vector4f &bg_color, std::shared_ptr< geometry::Image > bg_image=nullptr)
DrawObject GetGeometry(const std::string &name) const
Returns Visualizer's internal DrawObject for the named geometry.
void SetOnAnimationFrame(std::function< void(O3DVisualizer &, double)> cb)
rendering::MaterialRecord GetGeometryMaterial(const std::string &name) const
void EnableGroup(const std::string &group, bool enable)
void SetPanelOpen(const std::string &name, bool open)
void ShowGeometry(const std::string &name, bool show)
Show/hide the named geometry.
void SetupCamera(float fov, const Eigen::Vector3f &center, const Eigen::Vector3f &eye, const Eigen::Vector3f &up)
rendering::CloudViewerScene * GetScene() const
void RemoveGeometry(const std::string &name)
Removes the named geometry from the Visualizer.
void UpdateGeometry(const std::string &name, std::shared_ptr< t::geometry::Geometry > tgeom, uint32_t update_flags)
std::vector< O3DVisualizerSelections::SelectionSet > GetSelectionSets() const
void Add3DLabel(const Eigen::Vector3f &pos, const char *text)
void Layout(const gui::LayoutContext &context)
void AddAction(const std::string &name, std::function< void(O3DVisualizer &)> callback)
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)
void ModifyGeometryMaterial(const std::string &name, const rendering::MaterialRecord *material)
O3DVisualizer(const std::string &title, int width, int height)
void AddGeometry(const std::string &name, std::shared_ptr< ccHObject > geom, const rendering::MaterialRecord *material=nullptr, const std::string &group="", double time=0.0, bool is_visible=true)
ImGuiContext * context
Definition: Window.cpp:76
::ccHObject Geometry
Definition: Geometry.h:18
static const std::string path
Definition: PointCloud.cpp:59
Generic file read and write utility for python interface.
struct Window Window
Definition: sqlite3.c:14678
std::shared_ptr< rendering::TriangleMeshModel > model
Definition: O3DVisualizer.h:48