Open3D (C++ API)  0.11.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 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 
34 
35 namespace open3d {
36 
37 namespace geometry {
38 class Geometry3D;
39 } // namespace geometry
40 
41 namespace t {
42 namespace geometry {
43 class PointCloud;
44 }
45 } // namespace t
46 
47 namespace visualization {
48 namespace rendering {
49 
50 class Camera;
51 struct Material;
52 struct TriangleMeshModel;
53 
54 class Open3DScene {
55 public:
56  Open3DScene(Renderer& renderer);
57  ~Open3DScene();
58 
59  View* GetView() const;
60  ViewHandle GetViewId() const { return view_; }
61 
62  void ShowSkybox(bool enable);
63  void ShowAxes(bool enable);
64  void SetBackgroundColor(const Eigen::Vector4f& color);
65 
69  void SetDownsampleThreshold(size_t n_points) {
70  downsample_threshold_ = n_points;
71  }
72  size_t GetDownsampleThreshold() const { return downsample_threshold_; }
73 
74  void ClearGeometry();
76  void AddGeometry(const std::string& name,
77  std::shared_ptr<const geometry::Geometry3D> geom,
78  const Material& mat,
79  bool add_downsampled_copy_for_fast_rendering = true);
80  // Note: we can't use shared_ptr here, as we might be given something
81  // from Python, which is using unique_ptr. The pointer must live long
82  // enough to get copied to the GPU by the render thread.
83  void AddGeometry(const std::string& name,
84  const t::geometry::PointCloud* geom,
85  const Material& mat,
86  bool add_downsampled_copy_for_fast_rendering = true);
87  void RemoveGeometry(const std::string& name);
89  void ShowGeometry(const std::string& name, bool show);
90  void AddModel(const std::string& name, const TriangleMeshModel& model);
91 
93  void UpdateMaterial(const Material& mat);
95  void UpdateModelMaterial(const std::string& name,
96  const TriangleMeshModel& model);
97  std::vector<std::string> GetGeometries();
98 
99  const geometry::AxisAlignedBoundingBox& GetBoundingBox() { return bounds_; }
100 
101  enum class LOD {
102  HIGH_DETAIL, // used when rendering time is not as important
103  FAST, // used when rendering time is important, like rotating
104  };
105  void SetLOD(LOD lod);
106  LOD GetLOD() const;
107 
108  Scene* GetScene() const;
109  Camera* GetCamera() const;
110  Renderer& GetRenderer() const;
111 
112 private:
113  struct GeometryData {
114  std::string name;
115  std::string fast_name;
116  std::string low_name;
117  bool visible;
118 
119  GeometryData() : visible(false) {} // for STL containers
120  GeometryData(const std::string& n, const std::string& fast)
121  : name(n), fast_name(fast), visible(true) {}
122  };
123 
124  void SetGeometryToLOD(const GeometryData&, LOD lod);
125 
126 private:
127  Renderer& renderer_;
128  SceneHandle scene_;
129  ViewHandle view_;
130 
131  LOD lod_ = LOD::HIGH_DETAIL;
132  bool use_low_quality_if_available_ = false;
133  std::map<std::string, GeometryData> geometries_; // name -> data
135  size_t downsample_threshold_ = 6000000;
136 };
137 
138 } // namespace rendering
139 } // namespace visualization
140 } // namespace open3d
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:149
math::float4 color
Definition: LineSetBuffers.cpp:63
size_t GetDownsampleThreshold() const
Definition: Open3DScene.h:72
A pointcloud contains a set of 3D points.
Definition: PointCloud.h:93
ViewHandle GetViewId() const
Definition: Open3DScene.h:60
Definition: PinholeCameraIntrinsic.cpp:35
std::string name
Definition: FilePCD.cpp:58
void SetDownsampleThreshold(size_t n_points)
Definition: Open3DScene.h:69
const geometry::AxisAlignedBoundingBox & GetBoundingBox()
Definition: Open3DScene.h:99