Open3D (C++ API)  0.13.0
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 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 PointCloud;
47 }
48 } // namespace t
49 
50 namespace visualization {
51 namespace rendering {
52 
53 class Camera;
54 struct Material;
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 Material& 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::PointCloud* geom,
105  const Material& 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  void ModifyGeometryMaterial(const std::string& name, const Material& mat);
112  void AddModel(const std::string& name, const TriangleMeshModel& model);
113 
115  void UpdateMaterial(const Material& mat);
117  void UpdateModelMaterial(const std::string& name,
118  const TriangleMeshModel& model);
119  std::vector<std::string> GetGeometries();
120 
122 
123  enum class LOD {
124  HIGH_DETAIL, // used when rendering time is not as important
125  FAST, // used when rendering time is important, like rotating
126  };
127  void SetLOD(LOD lod);
128  LOD GetLOD() const;
129 
130  Scene* GetScene() const;
131  Camera* GetCamera() const;
132  Renderer& GetRenderer() const;
133 
134 private:
135  struct GeometryData {
136  std::string name;
137  std::string fast_name;
138  std::string low_name;
139  bool visible;
140 
141  GeometryData() : visible(false) {} // for STL containers
142  GeometryData(const std::string& n, const std::string& fast)
143  : name(n), fast_name(fast), visible(true) {}
144  };
145 
146  void SetGeometryToLOD(const GeometryData&, LOD lod);
147 
148 private:
149  Renderer& renderer_;
150  SceneHandle scene_;
151  ViewHandle view_;
152 
153  Eigen::Vector4f background_color;
154  LOD lod_ = LOD::HIGH_DETAIL;
155  bool use_low_quality_if_available_ = false;
156  bool axis_dirty_ = true;
157  std::map<std::string, GeometryData> geometries_; // name -> data
159  size_t downsample_threshold_ = 6000000;
160 };
161 
162 } // namespace rendering
163 } // namespace visualization
164 } // namespace open3d
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:557
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:150
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:398
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:92
A pointcloud contains a set of 3D points.
Definition: PointCloud.h:95
ViewHandle GetViewId() const
Definition: Open3DScene.h:63
Definition: PinholeCameraIntrinsic.cpp:35
std::string name
Definition: FilePCD.cpp:58
LightingProfile
Definition: Open3DScene.h:76
int height
Definition: FilePCD.cpp:72
void SetDownsampleThreshold(size_t n_points)
Definition: Open3DScene.h:89
const geometry::AxisAlignedBoundingBox & GetBoundingBox()
Definition: Open3DScene.h:121
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:228
Open3DScene::LightingProfile profile
Definition: O3DVisualizer.cpp:286
int width
Definition: FilePCD.cpp:71