ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CloudViewerScene.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 
10 #include <ecvBBox.h>
11 
12 #include <map>
13 #include <vector>
14 
18 
19 class ccHObject;
20 namespace cloudViewer {
21 
22 namespace geometry {
23 class Image;
24 } // namespace geometry
25 
26 namespace t {
27 namespace geometry {
28 class PointCloud;
29 }
30 } // namespace t
31 
32 namespace visualization {
33 namespace rendering {
34 
35 class Camera;
36 struct MaterialRecord;
37 struct TriangleMeshModel;
38 
40 public:
41  CloudViewerScene(Renderer& renderer);
43 
44  View* GetView() const;
45  ViewHandle GetViewId() const { return view_; }
46  void SetViewport(std::int32_t x,
47  std::int32_t y,
48  std::uint32_t width,
49  std::uint32_t height);
50 
51  void ShowSkybox(bool enable);
52  void ShowAxes(bool enable);
53  void SetBackground(const Eigen::Vector4f& color,
54  std::shared_ptr<geometry::Image> image = nullptr);
55  const Eigen::Vector4f GetBackgroundColor() const;
56  void ShowGroundPlane(bool enable, Scene::GroundPlane plane);
57 
58  enum class LightingProfile {
64  };
65 
66  void SetLighting(LightingProfile profile, const Eigen::Vector3f& sun_dir);
67 
71  void SetDownsampleThreshold(size_t n_points) {
72  downsample_threshold_ = n_points;
73  }
74  size_t GetDownsampleThreshold() const { return downsample_threshold_; }
75 
76  void ClearGeometry();
78  void AddGeometry(const std::string& name,
79  const ccHObject* geom,
80  const MaterialRecord& mat,
81  bool add_downsampled_copy_for_fast_rendering = true);
82  // Note: we can't use shared_ptr here, as we might be given something
83  // from Python, which is using unique_ptr. The pointer must live long
84  // enough to get copied to the GPU by the render thread.
85  void AddGeometry(const std::string& name,
86  const t::geometry::Geometry* geom,
87  const MaterialRecord& mat,
88  bool add_downsampled_copy_for_fast_rendering = true);
89  bool HasGeometry(const std::string& name) const;
90  void RemoveGeometry(const std::string& name);
92  void ShowGeometry(const std::string& name, bool show);
93  bool GeometryIsVisible(const std::string& name);
94  void SetGeometryTransform(const std::string& name,
95  const Eigen::Matrix4d& transform);
96  Eigen::Matrix4d GetGeometryTransform(const std::string& name);
97 
98  void ModifyGeometryMaterial(const std::string& name,
99  const MaterialRecord& mat);
100  void AddModel(const std::string& name, const TriangleMeshModel& model);
101 
103  void UpdateMaterial(const MaterialRecord& mat);
105  void UpdateModelMaterial(const std::string& name,
106  const TriangleMeshModel& model);
107  std::vector<std::string> GetGeometries();
108 
109  const ccBBox& GetBoundingBox() { return bounds_; }
110 
111  enum class LOD {
112  HIGH_DETAIL, // used when rendering time is not as important
113  FAST, // used when rendering time is important, like rotating
114  };
115  void SetLOD(LOD lod);
116  LOD GetLOD() const;
117 
118  Scene* GetScene() const;
119  Camera* GetCamera() const;
120  Renderer& GetRenderer() const;
121 
122 private:
123  struct GeometryData {
124  std::string name;
125  std::string fast_name;
126  std::string low_name;
127  bool visible;
128 
129  GeometryData() : visible(false) {} // for STL containers
130  GeometryData(const std::string& n, const std::string& fast)
131  : name(n), fast_name(fast), visible(true) {}
132  };
133 
134  void SetGeometryToLOD(const GeometryData&, LOD lod);
135 
136 private:
137  Renderer& renderer_;
138  SceneHandle scene_;
139  ViewHandle view_;
140 
141  Eigen::Vector4f background_color;
142  LOD lod_ = LOD::HIGH_DETAIL;
143  bool use_low_quality_if_available_ = false;
144  bool axis_dirty_ = true;
145  std::map<std::string, GeometryData> geometries_; // name -> data
146  ccBBox bounds_;
147  size_t downsample_threshold_ = 6000000;
148 };
149 
150 } // namespace rendering
151 } // namespace visualization
152 } // namespace cloudViewer
std::shared_ptr< core::Tensor > image
int width
std::string name
int height
math::float4 color
CloudViewerScene::LightingProfile profile
Bounding box structure.
Definition: ecvBBox.h:25
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
The base geometry class.
Definition: Geometry.h:23
void SetViewport(std::int32_t x, std::int32_t y, std::uint32_t width, std::uint32_t height)
Eigen::Matrix4d GetGeometryTransform(const std::string &name)
void ShowGeometry(const std::string &name, bool show)
Shows or hides the geometry with the specified name.
void ModifyGeometryMaterial(const std::string &name, const MaterialRecord &mat)
void UpdateModelMaterial(const std::string &name, const TriangleMeshModel &model)
Updates the named model to use this material.
void SetBackground(const Eigen::Vector4f &color, std::shared_ptr< geometry::Image > image=nullptr)
void SetGeometryTransform(const std::string &name, const Eigen::Matrix4d &transform)
void ShowGroundPlane(bool enable, Scene::GroundPlane plane)
void UpdateMaterial(const MaterialRecord &mat)
Updates all geometries to use this material.
void SetLighting(LightingProfile profile, const Eigen::Vector3f &sun_dir)
void AddGeometry(const std::string &name, const ccHObject *geom, const MaterialRecord &mat, bool add_downsampled_copy_for_fast_rendering=true)
Adds a geometry with the specified name. Default visible is true.
void AddModel(const std::string &name, const TriangleMeshModel &model)
::ccPointCloud PointCloud
Definition: PointCloud.h:19
REHandle< EntityType::Scene > SceneHandle
REHandle< EntityType::View > ViewHandle
Generic file read and write utility for python interface.