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