Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.15.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
37 namespace open3d {
38 
39 namespace geometry {
40 class Geometry3D;
41 class Image;
42 } // namespace geometry
43 
44 namespace t {
45 namespace geometry {
46 class Geometry;
47 }
48 } // namespace t
49 
50 namespace visualization {
51 namespace rendering {
52 
53 class Camera;
54 struct MaterialRecord;
55 struct TriangleMeshModel;
56 
57 class Open3DScene {
58 public:
59  Open3DScene(Renderer& renderer);
60  ~Open3DScene();
61 
62  View* GetView() const;
63  ViewHandle GetViewId() const { return view_; }
64  void SetViewport(std::int32_t x,
65  std::int32_t y,
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 
140 private:
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 
154 private:
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
165  size_t downsample_threshold_ = 6000000;
166 };
167 
168 } // namespace rendering
169 } // namespace visualization
170 } // namespace open3d
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
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:155
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:408
math::float4 color
Definition: LineSetBuffers.cpp:64
The base geometry class for 3D geometries.
Definition: Geometry3D.h:47
size_t GetDownsampleThreshold() const
Definition: Open3DScene.h:92
ViewHandle GetViewId() const
Definition: Open3DScene.h:63
The base geometry class.
Definition: Geometry.h:38
Definition: PinholeCameraIntrinsic.cpp:35
LightingProfile
Definition: Open3DScene.h:76
void SetDownsampleThreshold(size_t n_points)
Definition: Open3DScene.h:89
const geometry::AxisAlignedBoundingBox & GetBoundingBox()
Definition: Open3DScene.h:127
int width
Definition: FilePCD.cpp:71
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:228
std::string name
Definition: FilePCD.cpp:58
Open3DScene::LightingProfile profile
Definition: O3DVisualizer.cpp:288