Open3D (C++ API)  0.16.0
Open3DScene.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 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
29#include <map>
30#include <vector>
31
36
37namespace open3d {
38
39namespace geometry {
40class Geometry3D;
41class Image;
42} // namespace geometry
43
44namespace t {
45namespace geometry {
46class Geometry;
47}
48} // namespace t
49
50namespace visualization {
51namespace rendering {
52
53class Camera;
54struct MaterialRecord;
55struct TriangleMeshModel;
56
58public:
59 Open3DScene(Renderer& renderer);
61
62 View* GetView() const;
63 ViewHandle GetViewId() const { return view_; }
68
69 void ShowSkybox(bool enable);
70 void ShowAxes(bool enable);
71 void SetBackground(const Eigen::Vector4f& color,
72 std::shared_ptr<geometry::Image> image = nullptr);
73 const Eigen::Vector4f GetBackgroundColor() const;
74 void ShowGroundPlane(bool enable, Scene::GroundPlane plane);
75
76 enum class LightingProfile {
77 HARD_SHADOWS,
78 DARK_SHADOWS,
79 MED_SHADOWS,
80 SOFT_SHADOWS,
81 NO_SHADOWS
82 };
83
84 void SetLighting(LightingProfile profile, const Eigen::Vector3f& sun_dir);
85
89 void SetDownsampleThreshold(size_t n_points) {
90 downsample_threshold_ = n_points;
91 }
92 size_t GetDownsampleThreshold() const { return downsample_threshold_; }
93
94 void ClearGeometry();
96 void AddGeometry(const std::string& name,
97 const geometry::Geometry3D* geom,
98 const MaterialRecord& mat,
99 bool add_downsampled_copy_for_fast_rendering = true);
100 // Note: we can't use shared_ptr here, as we might be given something
101 // from Python, which is using unique_ptr. The pointer must live long
102 // enough to get copied to the GPU by the render thread.
103 void AddGeometry(const std::string& name,
104 const t::geometry::Geometry* geom,
105 const MaterialRecord& mat,
106 bool add_downsampled_copy_for_fast_rendering = true);
107 bool HasGeometry(const std::string& name) const;
108 void RemoveGeometry(const std::string& name);
110 void ShowGeometry(const std::string& name, bool show);
111 bool GeometryIsVisible(const std::string& name);
112 void SetGeometryTransform(const std::string& name,
113 const Eigen::Matrix4d& transform);
114 Eigen::Matrix4d GetGeometryTransform(const std::string& name);
115
116 void ModifyGeometryMaterial(const std::string& name,
117 const MaterialRecord& mat);
118 void AddModel(const std::string& name, const TriangleMeshModel& model);
119
121 void UpdateMaterial(const MaterialRecord& mat);
123 void UpdateModelMaterial(const std::string& name,
124 const TriangleMeshModel& model);
125 std::vector<std::string> GetGeometries();
126
128
129 enum class LOD {
130 HIGH_DETAIL, // used when rendering time is not as important
131 FAST, // used when rendering time is important, like rotating
132 };
133 void SetLOD(LOD lod);
134 LOD GetLOD() const;
135
136 Scene* GetScene() const;
137 Camera* GetCamera() const;
138 Renderer& GetRenderer() const;
139
140private:
141 struct GeometryData {
142 std::string name;
143 std::string fast_name;
144 std::string low_name;
145 bool visible;
146
147 GeometryData() : visible(false) {} // for STL containers
148 GeometryData(const std::string& n, const std::string& fast)
149 : name(n), fast_name(fast), visible(true) {}
150 };
151
152 void SetGeometryToLOD(const GeometryData&, LOD lod);
153
154private:
155 Renderer& renderer_;
156 SceneHandle scene_;
157 ViewHandle view_;
158
159 Eigen::Vector4f background_color;
160 LOD lod_ = LOD::HIGH_DETAIL;
161 bool use_low_quality_if_available_ = false;
162 bool axis_dirty_ = true;
163 std::map<std::string, GeometryData> geometries_; // name -> data
164 geometry::AxisAlignedBoundingBox bounds_;
165 size_t downsample_threshold_ = 6000000;
166};
167
168} // namespace rendering
169} // namespace visualization
170} // namespace open3d
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:202
math::float4 color
Definition: LineSetBuffers.cpp:64
Open3DScene::LightingProfile profile
Definition: O3DVisualizer.cpp:288
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:155
The base geometry class for 3D geometries.
Definition: Geometry3D.h:47
The base geometry class.
Definition: Geometry.h:42
void SetLighting(LightingProfile profile, const Eigen::Vector3f &sun_dir)
Definition: Open3DScene.cpp:187
void ShowGroundPlane(bool enable, Scene::GroundPlane plane)
Definition: Open3DScene.cpp:182
void SetBackground(const Eigen::Vector4f &color, std::shared_ptr< geometry::Image > image=nullptr)
Definition: Open3DScene.cpp:171
bool GeometryIsVisible(const std::string &name)
Definition: Open3DScene.cpp:345
void ClearGeometry()
Definition: Open3DScene.cpp:237
Eigen::Matrix4d GetGeometryTransform(const std::string &name)
Definition: Open3DScene.cpp:367
Renderer & GetRenderer() const
Definition: Open3DScene.cpp:495
void ShowAxes(bool enable)
Definition: Open3DScene.cpp:162
const Eigen::Vector4f GetBackgroundColor() const
Definition: Open3DScene.cpp:178
Camera * GetCamera() const
Definition: Open3DScene.cpp:489
Scene * GetScene() const
Definition: Open3DScene.cpp:487
ViewHandle GetViewId() const
Definition: Open3DScene.h:63
~Open3DScene()
Definition: Open3DScene.cpp:130
void UpdateModelMaterial(const std::string &name, const TriangleMeshModel &model)
Updates the named model to use this material.
Definition: Open3DScene.cpp:430
const geometry::AxisAlignedBoundingBox & GetBoundingBox()
Definition: Open3DScene.h:127
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:253
void ShowSkybox(bool enable)
Definition: Open3DScene.cpp:157
View * GetView() const
Definition: Open3DScene.cpp:137
void SetLOD(LOD lod)
Definition: Open3DScene.cpp:446
LOD GetLOD() const
Definition: Open3DScene.cpp:485
void SetGeometryTransform(const std::string &name, const Eigen::Matrix4d &transform)
Definition: Open3DScene.cpp:350
LightingProfile
Definition: Open3DScene.h:76
size_t GetDownsampleThreshold() const
Definition: Open3DScene.h:92
void SetViewport(std::int32_t x, std::int32_t y, std::uint32_t width, std::uint32_t height)
Definition: Open3DScene.cpp:142
void RemoveGeometry(const std::string &name)
Definition: Open3DScene.cpp:330
Open3DScene(Renderer &renderer)
Definition: Open3DScene.cpp:119
void SetDownsampleThreshold(size_t n_points)
Definition: Open3DScene.h:89
bool HasGeometry(const std::string &name) const
Definition: Open3DScene.cpp:325
void UpdateMaterial(const MaterialRecord &mat)
Updates all geometries to use this material.
Definition: Open3DScene.cpp:415
void AddModel(const std::string &name, const TriangleMeshModel &model)
Definition: Open3DScene.cpp:402
std::vector< std::string > GetGeometries()
Definition: Open3DScene.cpp:437
void ModifyGeometryMaterial(const std::string &name, const MaterialRecord &mat)
Definition: Open3DScene.cpp:372
void ShowGeometry(const std::string &name, bool show)
Shows or hides the geometry with the specified name.
Definition: Open3DScene.cpp:385
int width
Definition: FilePCD.cpp:71
std::string name
Definition: FilePCD.cpp:58
int height
Definition: FilePCD.cpp:72
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:567
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:414
REHandle< EntityType::Scene > SceneHandle
Definition: RendererHandle.h:147
REHandle< EntityType::View > ViewHandle
Definition: RendererHandle.h:146
Definition: PinholeCameraIntrinsic.cpp:35