Open3D (C++ API)  0.18.0+252c867
Open3DScene.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 
10 #include <map>
11 #include <vector>
12 
17 
18 namespace open3d {
19 
20 namespace geometry {
21 class Geometry3D;
22 class Image;
23 } // namespace geometry
24 
25 namespace t {
26 namespace geometry {
27 class Geometry;
28 }
29 } // namespace t
30 
31 namespace visualization {
32 namespace rendering {
33 
34 class Camera;
35 struct MaterialRecord;
36 struct TriangleMeshModel;
37 
38 class Open3DScene {
39 public:
40  Open3DScene(Renderer& renderer);
41  ~Open3DScene();
42 
43  View* GetView() const;
44  ViewHandle GetViewId() const { return view_; }
46  std::int32_t y,
49 
50  void ShowSkybox(bool enable);
51  void ShowAxes(bool enable);
52  void SetBackground(const Eigen::Vector4f& color,
53  std::shared_ptr<geometry::Image> image = nullptr);
54  const Eigen::Vector4f GetBackgroundColor() const;
55  void ShowGroundPlane(bool enable, Scene::GroundPlane plane);
56 
57  enum class LightingProfile {
63  };
64 
65  void SetLighting(LightingProfile profile, const Eigen::Vector3f& sun_dir);
66 
70  void SetDownsampleThreshold(size_t n_points) {
71  downsample_threshold_ = n_points;
72  }
73  size_t GetDownsampleThreshold() const { return downsample_threshold_; }
74 
75  void ClearGeometry();
77  void AddGeometry(const std::string& name,
78  const geometry::Geometry3D* geom,
79  const MaterialRecord& mat,
80  bool add_downsampled_copy_for_fast_rendering = true);
81  // Note: we can't use shared_ptr here, as we might be given something
82  // from Python, which is using unique_ptr. The pointer must live long
83  // enough to get copied to the GPU by the render thread.
84  void AddGeometry(const std::string& name,
85  const t::geometry::Geometry* geom,
86  const MaterialRecord& mat,
87  bool add_downsampled_copy_for_fast_rendering = true);
88  bool HasGeometry(const std::string& name) const;
89  void RemoveGeometry(const std::string& name);
91  void ShowGeometry(const std::string& name, bool show);
92  bool GeometryIsVisible(const std::string& name);
93  void SetGeometryTransform(const std::string& name,
94  const Eigen::Matrix4d& transform);
95  Eigen::Matrix4d GetGeometryTransform(const std::string& name);
96 
97  void ModifyGeometryMaterial(const std::string& name,
98  const MaterialRecord& mat);
99  void AddModel(const std::string& name, const TriangleMeshModel& model);
100 
102  void UpdateMaterial(const MaterialRecord& mat);
104  void UpdateModelMaterial(const std::string& name,
105  const TriangleMeshModel& model);
106  std::vector<std::string> GetGeometries();
107 
109 
110  enum class LOD {
111  HIGH_DETAIL, // used when rendering time is not as important
112  FAST, // used when rendering time is important, like rotating
113  };
114  void SetLOD(LOD lod);
115  LOD GetLOD() const;
116 
117  Scene* GetScene() const;
118  Camera* GetCamera() const;
119  Renderer& GetRenderer() const;
120 
121 private:
122  struct GeometryData {
123  std::string name;
124  std::string fast_name;
125  std::string low_name;
126  bool visible;
127 
128  GeometryData() : visible(false) {} // for STL containers
129  GeometryData(const std::string& n, const std::string& fast)
130  : name(n), fast_name(fast), visible(true) {}
131  };
132 
133  void SetGeometryToLOD(const GeometryData&, LOD lod);
134 
135 private:
136  Renderer& renderer_;
137  SceneHandle scene_;
138  ViewHandle view_;
139 
140  Eigen::Vector4f background_color;
141  LOD lod_ = LOD::HIGH_DETAIL;
142  bool use_low_quality_if_available_ = false;
143  bool axis_dirty_ = true;
144  std::map<std::string, GeometryData> geometries_; // name -> data
145  geometry::AxisAlignedBoundingBox bounds_;
146  size_t downsample_threshold_ = 6000000;
147 };
148 
149 } // namespace rendering
150 } // namespace visualization
151 } // namespace open3d
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:183
math::float4 color
Definition: LineSetBuffers.cpp:45
Open3DScene::LightingProfile profile
Definition: O3DVisualizer.cpp:269
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:160
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
The base geometry class.
Definition: Geometry.h:21
void SetLighting(LightingProfile profile, const Eigen::Vector3f &sun_dir)
Definition: Open3DScene.cpp:168
void ShowGroundPlane(bool enable, Scene::GroundPlane plane)
Definition: Open3DScene.cpp:163
void SetBackground(const Eigen::Vector4f &color, std::shared_ptr< geometry::Image > image=nullptr)
Definition: Open3DScene.cpp:152
bool GeometryIsVisible(const std::string &name)
Definition: Open3DScene.cpp:326
void ClearGeometry()
Definition: Open3DScene.cpp:218
Eigen::Matrix4d GetGeometryTransform(const std::string &name)
Definition: Open3DScene.cpp:348
Renderer & GetRenderer() const
Definition: Open3DScene.cpp:476
void ShowAxes(bool enable)
Definition: Open3DScene.cpp:143
const Eigen::Vector4f GetBackgroundColor() const
Definition: Open3DScene.cpp:159
Camera * GetCamera() const
Definition: Open3DScene.cpp:470
Scene * GetScene() const
Definition: Open3DScene.cpp:468
ViewHandle GetViewId() const
Definition: Open3DScene.h:44
~Open3DScene()
Definition: Open3DScene.cpp:111
void UpdateModelMaterial(const std::string &name, const TriangleMeshModel &model)
Updates the named model to use this material.
Definition: Open3DScene.cpp:411
const geometry::AxisAlignedBoundingBox & GetBoundingBox()
Definition: Open3DScene.h:108
void AddGeometry(const std::string &name, const geometry::Geometry3D *geom, const MaterialRecord &mat, bool add_downsampled_copy_for_fast_rendering=true)
Adds a geometry with the specified name. Default visible is true.
Definition: Open3DScene.cpp:234
void ShowSkybox(bool enable)
Definition: Open3DScene.cpp:138
View * GetView() const
Definition: Open3DScene.cpp:118
void SetLOD(LOD lod)
Definition: Open3DScene.cpp:427
LOD GetLOD() const
Definition: Open3DScene.cpp:466
void SetGeometryTransform(const std::string &name, const Eigen::Matrix4d &transform)
Definition: Open3DScene.cpp:331
LightingProfile
Definition: Open3DScene.h:57
size_t GetDownsampleThreshold() const
Definition: Open3DScene.h:73
void SetViewport(std::int32_t x, std::int32_t y, std::uint32_t width, std::uint32_t height)
Definition: Open3DScene.cpp:123
void RemoveGeometry(const std::string &name)
Definition: Open3DScene.cpp:311
Open3DScene(Renderer &renderer)
Definition: Open3DScene.cpp:100
void SetDownsampleThreshold(size_t n_points)
Definition: Open3DScene.h:70
bool HasGeometry(const std::string &name) const
Definition: Open3DScene.cpp:306
void UpdateMaterial(const MaterialRecord &mat)
Updates all geometries to use this material.
Definition: Open3DScene.cpp:396
void AddModel(const std::string &name, const TriangleMeshModel &model)
Definition: Open3DScene.cpp:383
std::vector< std::string > GetGeometries()
Definition: Open3DScene.cpp:418
void ModifyGeometryMaterial(const std::string &name, const MaterialRecord &mat)
Definition: Open3DScene.cpp:353
void ShowGeometry(const std::string &name, bool show)
Shows or hides the geometry with the specified name.
Definition: Open3DScene.cpp:366
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 int32_t
Definition: K4aPlugin.cpp:395
REHandle< EntityType::Scene > SceneHandle
Definition: RendererHandle.h:128
REHandle< EntityType::View > ViewHandle
Definition: RendererHandle.h:127
Definition: PinholeCameraIntrinsic.cpp:16