Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Scene.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 <Eigen/Geometry>
30 #include <memory>
31 #include <vector>
32 
35 
36 namespace open3d {
37 namespace geometry {
38 class Geometry3D;
39 class AxisAlignedBoundingBox;
40 class Image;
41 } // namespace geometry
42 
43 namespace t {
44 namespace geometry {
45 class Geometry;
46 class PointCloud;
47 } // namespace geometry
48 } // namespace t
49 
50 namespace visualization {
51 namespace rendering {
52 
53 class Renderer;
54 class View;
55 struct TriangleMeshModel;
56 struct MaterialRecord;
57 struct Light;
58 
59 // Contains renderable objects like geometry and lights
60 // Can have multiple views
61 class Scene {
62 public:
63  static const uint32_t kUpdatePointsFlag = (1 << 0);
64  static const uint32_t kUpdateNormalsFlag = (1 << 1);
65  static const uint32_t kUpdateColorsFlag = (1 << 2);
66  static const uint32_t kUpdateUv0Flag = (1 << 3);
67 
68  using Transform = Eigen::Transform<float, 3, Eigen::Affine>;
69 
70  Scene(Renderer& renderer) : renderer_(renderer) {}
71  virtual ~Scene() = default;
72 
73  virtual Scene* Copy() = 0;
74 
75  // NOTE: Temporarily need to support old View interface for ImGUI
76  virtual ViewHandle AddView(std::int32_t x,
77  std::int32_t y,
78  std::uint32_t w,
79  std::uint32_t h) = 0;
80 
81  virtual View* GetView(const ViewHandle& view_id) const = 0;
82  virtual void SetViewActive(const ViewHandle& view_id, bool is_active) = 0;
83  virtual void SetRenderOnce(const ViewHandle& view_id) = 0;
84  virtual void RemoveView(const ViewHandle& view_id) = 0;
85 
86  // Camera
87  virtual void AddCamera(const std::string& camera_name,
88  std::shared_ptr<Camera> cam) = 0;
89  virtual void RemoveCamera(const std::string& camera_name) = 0;
90  virtual void SetActiveCamera(const std::string& camera_name) = 0;
91 
92  // Scene geometry
93  virtual bool AddGeometry(const std::string& object_name,
94  const geometry::Geometry3D& geometry,
95  const MaterialRecord& material,
96  const std::string& downsampled_name = "",
97  size_t downsample_threshold = SIZE_MAX) = 0;
98  virtual bool AddGeometry(const std::string& object_name,
99  const t::geometry::Geometry& geometry,
100  const MaterialRecord& material,
101  const std::string& downsampled_name = "",
102  size_t downsample_threshold = SIZE_MAX) = 0;
103  virtual bool AddGeometry(const std::string& object_name,
104  const TriangleMeshModel& model) = 0;
105  virtual bool HasGeometry(const std::string& object_name) const = 0;
106  virtual void UpdateGeometry(const std::string& object_name,
107  const t::geometry::PointCloud& point_cloud,
108  uint32_t update_flags) = 0;
109  virtual void RemoveGeometry(const std::string& object_name) = 0;
110  virtual void ShowGeometry(const std::string& object_name, bool show) = 0;
111  virtual bool GeometryIsVisible(const std::string& object_name) = 0;
112  virtual void OverrideMaterial(const std::string& object_name,
113  const MaterialRecord& material) = 0;
114  virtual void GeometryShadows(const std::string& object_name,
115  bool cast_shadows,
116  bool receive_shadows) = 0;
117  virtual void SetGeometryCulling(const std::string& object_name,
118  bool enable) = 0;
119  virtual void SetGeometryPriority(const std::string& object_name,
120  uint8_t priority) = 0;
121  virtual void QueryGeometry(std::vector<std::string>& geometry) = 0;
122  virtual void SetGeometryTransform(const std::string& object_name,
123  const Transform& transform) = 0;
124  virtual Transform GetGeometryTransform(const std::string& object_name) = 0;
125  virtual geometry::AxisAlignedBoundingBox GetGeometryBoundingBox(
126  const std::string& object_name) = 0;
127  virtual void OverrideMaterialAll(const MaterialRecord& material,
128  bool shader_only = true) = 0;
129 
130  // Lighting Environment
131  virtual bool AddPointLight(const std::string& light_name,
132  const Eigen::Vector3f& color,
133  const Eigen::Vector3f& position,
134  float intensity,
135  float falloff,
136  bool cast_shadows) = 0;
137  virtual bool AddSpotLight(const std::string& light_name,
138  const Eigen::Vector3f& color,
139  const Eigen::Vector3f& position,
140  const Eigen::Vector3f& direction,
141  float intensity,
142  float falloff,
143  float inner_cone_angle,
144  float outer_cone_angle,
145  bool cast_shadows) = 0;
146  virtual bool AddDirectionalLight(const std::string& light_name,
147  const Eigen::Vector3f& color,
148  const Eigen::Vector3f& direction,
149  float intensity,
150  bool cast_shadows) = 0;
151  virtual Light& GetLight(const std::string& light_name) = 0;
152  virtual void RemoveLight(const std::string& light_name) = 0;
153  virtual void UpdateLight(const std::string& light_name,
154  const Light& light) = 0;
155  virtual void UpdateLightColor(const std::string& light_name,
156  const Eigen::Vector3f& color) = 0;
157  virtual void UpdateLightPosition(const std::string& light_name,
158  const Eigen::Vector3f& position) = 0;
159  virtual void UpdateLightDirection(const std::string& light_name,
160  const Eigen::Vector3f& direction) = 0;
161  virtual void UpdateLightIntensity(const std::string& light_name,
162  float intensity) = 0;
163  virtual void UpdateLightFalloff(const std::string& light_name,
164  float falloff) = 0;
165  virtual void UpdateLightConeAngles(const std::string& light_name,
166  float inner_cone_angle,
167  float outer_cone_angle) = 0;
168  virtual void EnableLightShadow(const std::string& light_name,
169  bool cast_shadows) = 0;
170 
171  virtual void SetSunLight(const Eigen::Vector3f& direction,
172  const Eigen::Vector3f& color,
173  float intensity) = 0;
174  virtual void EnableSunLight(bool enable) = 0;
175  virtual void EnableSunLightShadows(bool enable) = 0;
176  virtual void SetSunLightColor(const Eigen::Vector3f& color) = 0;
177  virtual Eigen::Vector3f GetSunLightColor() = 0;
178  virtual void SetSunLightIntensity(float intensity) = 0;
179  virtual float GetSunLightIntensity() = 0;
180  virtual void SetSunLightDirection(const Eigen::Vector3f& direction) = 0;
181  virtual Eigen::Vector3f GetSunLightDirection() = 0;
182  virtual void SetSunAngularRadius(float radius) = 0;
183  virtual void SetSunHaloSize(float size) = 0;
184  virtual void SetSunHaloFalloff(float falloff) = 0;
185 
186  virtual bool SetIndirectLight(const std::string& ibl_name) = 0;
187  virtual const std::string& GetIndirectLight() = 0;
188  virtual void EnableIndirectLight(bool enable) = 0;
189  virtual void SetIndirectLightIntensity(float intensity) = 0;
190  virtual float GetIndirectLightIntensity() = 0;
191  virtual void SetIndirectLightRotation(const Transform& rotation) = 0;
192  virtual Transform GetIndirectLightRotation() = 0;
193  virtual void ShowSkybox(bool show) = 0;
194  virtual bool GetSkyboxVisible() const = 0;
195  virtual void SetBackground(
196  const Eigen::Vector4f& color,
197  const std::shared_ptr<geometry::Image> image = nullptr) = 0;
198  virtual void SetBackground(TextureHandle image) = 0;
199 
200  enum class GroundPlane { XZ, XY, YZ };
201  virtual void EnableGroundPlane(bool enable, GroundPlane plane) = 0;
202  virtual void SetGroundPlaneColor(const Eigen::Vector4f& color) = 0;
203 
205  virtual void RenderToImage(
206  std::function<void(std::shared_ptr<geometry::Image>)> callback) = 0;
207 
209  virtual void RenderToDepthImage(
210  std::function<void(std::shared_ptr<geometry::Image>)> callback) = 0;
211 
212 protected:
214 };
215 
216 } // namespace rendering
217 } // namespace visualization
218 } // namespace open3d
void Copy(const Tensor &src, Tensor &dst)
Definition: UnaryEW.cpp:65
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
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Scene.h:68
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
Renderer & renderer_
Definition: Scene.h:213
math::float4 color
Definition: LineSetBuffers.cpp:64
The base geometry class for 3D geometries.
Definition: Geometry3D.h:47
math::float3 position
Definition: LineSetBuffers.cpp:62
A point cloud contains a list of 3D points.
Definition: PointCloud.h:95
The base geometry class.
Definition: Geometry.h:38
Definition: PinholeCameraIntrinsic.cpp:35
int size
Definition: FilePCD.cpp:59
Scene(Renderer &renderer)
Definition: Scene.h:70
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:228
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:388
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:227