Open3D (C++ API)  0.18.0+252c867
Scene.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Geometry>
11 #include <memory>
12 #include <vector>
13 
16 
17 namespace open3d {
18 namespace geometry {
19 class Geometry3D;
20 class AxisAlignedBoundingBox;
21 class Image;
22 } // namespace geometry
23 
24 namespace t {
25 namespace geometry {
26 class Geometry;
27 class PointCloud;
28 } // namespace geometry
29 } // namespace t
30 
31 namespace visualization {
32 namespace rendering {
33 
34 class Renderer;
35 class View;
36 struct TriangleMeshModel;
37 struct MaterialRecord;
38 struct Light;
39 
40 // Contains renderable objects like geometry and lights
41 // Can have multiple views
42 class Scene {
43 public:
44  static const uint32_t kUpdatePointsFlag = (1 << 0);
45  static const uint32_t kUpdateNormalsFlag = (1 << 1);
46  static const uint32_t kUpdateColorsFlag = (1 << 2);
47  static const uint32_t kUpdateUv0Flag = (1 << 3);
48 
49  using Transform = Eigen::Transform<float, 3, Eigen::Affine>;
50 
51  Scene(Renderer& renderer) : renderer_(renderer) {}
52  virtual ~Scene() = default;
53 
54  virtual Scene* Copy() = 0;
55 
56  // NOTE: Temporarily need to support old View interface for ImGUI
58  std::int32_t y,
59  std::uint32_t w,
60  std::uint32_t h) = 0;
61 
62  virtual View* GetView(const ViewHandle& view_id) const = 0;
63  virtual void SetViewActive(const ViewHandle& view_id, bool is_active) = 0;
64  virtual void SetRenderOnce(const ViewHandle& view_id) = 0;
65  virtual void RemoveView(const ViewHandle& view_id) = 0;
66 
67  // Camera
68  virtual void AddCamera(const std::string& camera_name,
69  std::shared_ptr<Camera> cam) = 0;
70  virtual void RemoveCamera(const std::string& camera_name) = 0;
71  virtual void SetActiveCamera(const std::string& camera_name) = 0;
72 
73  // Scene geometry
74  virtual bool AddGeometry(const std::string& object_name,
75  const geometry::Geometry3D& geometry,
76  const MaterialRecord& material,
77  const std::string& downsampled_name = "",
78  size_t downsample_threshold = SIZE_MAX) = 0;
79  virtual bool AddGeometry(const std::string& object_name,
80  const t::geometry::Geometry& geometry,
81  const MaterialRecord& material,
82  const std::string& downsampled_name = "",
83  size_t downsample_threshold = SIZE_MAX) = 0;
84  virtual bool AddGeometry(const std::string& object_name,
85  const TriangleMeshModel& model) = 0;
86  virtual bool HasGeometry(const std::string& object_name) const = 0;
87  virtual void UpdateGeometry(const std::string& object_name,
88  const t::geometry::PointCloud& point_cloud,
89  uint32_t update_flags) = 0;
90  virtual void RemoveGeometry(const std::string& object_name) = 0;
91  virtual void ShowGeometry(const std::string& object_name, bool show) = 0;
92  virtual bool GeometryIsVisible(const std::string& object_name) = 0;
93  virtual void OverrideMaterial(const std::string& object_name,
94  const MaterialRecord& material) = 0;
95  virtual void GeometryShadows(const std::string& object_name,
96  bool cast_shadows,
97  bool receive_shadows) = 0;
98  virtual void SetGeometryCulling(const std::string& object_name,
99  bool enable) = 0;
100  virtual void SetGeometryPriority(const std::string& object_name,
101  uint8_t priority) = 0;
102  virtual void QueryGeometry(std::vector<std::string>& geometry) = 0;
103  virtual void SetGeometryTransform(const std::string& object_name,
104  const Transform& transform) = 0;
105  virtual Transform GetGeometryTransform(const std::string& object_name) = 0;
107  const std::string& object_name) = 0;
108  virtual void OverrideMaterialAll(const MaterialRecord& material,
109  bool shader_only = true) = 0;
110 
111  // Lighting Environment
112  virtual bool AddPointLight(const std::string& light_name,
113  const Eigen::Vector3f& color,
114  const Eigen::Vector3f& position,
115  float intensity,
116  float falloff,
117  bool cast_shadows) = 0;
118  virtual bool AddSpotLight(const std::string& light_name,
119  const Eigen::Vector3f& color,
120  const Eigen::Vector3f& position,
121  const Eigen::Vector3f& direction,
122  float intensity,
123  float falloff,
124  float inner_cone_angle,
125  float outer_cone_angle,
126  bool cast_shadows) = 0;
127  virtual bool AddDirectionalLight(const std::string& light_name,
128  const Eigen::Vector3f& color,
129  const Eigen::Vector3f& direction,
130  float intensity,
131  bool cast_shadows) = 0;
132  virtual Light& GetLight(const std::string& light_name) = 0;
133  virtual void RemoveLight(const std::string& light_name) = 0;
134  virtual void UpdateLight(const std::string& light_name,
135  const Light& light) = 0;
136  virtual void UpdateLightColor(const std::string& light_name,
137  const Eigen::Vector3f& color) = 0;
138  virtual void UpdateLightPosition(const std::string& light_name,
139  const Eigen::Vector3f& position) = 0;
140  virtual void UpdateLightDirection(const std::string& light_name,
141  const Eigen::Vector3f& direction) = 0;
142  virtual void UpdateLightIntensity(const std::string& light_name,
143  float intensity) = 0;
144  virtual void UpdateLightFalloff(const std::string& light_name,
145  float falloff) = 0;
146  virtual void UpdateLightConeAngles(const std::string& light_name,
147  float inner_cone_angle,
148  float outer_cone_angle) = 0;
149  virtual void EnableLightShadow(const std::string& light_name,
150  bool cast_shadows) = 0;
151 
152  virtual void SetSunLight(const Eigen::Vector3f& direction,
153  const Eigen::Vector3f& color,
154  float intensity) = 0;
155  virtual void EnableSunLight(bool enable) = 0;
156  virtual void EnableSunLightShadows(bool enable) = 0;
157  virtual void SetSunLightColor(const Eigen::Vector3f& color) = 0;
158  virtual Eigen::Vector3f GetSunLightColor() = 0;
159  virtual void SetSunLightIntensity(float intensity) = 0;
160  virtual float GetSunLightIntensity() = 0;
161  virtual void SetSunLightDirection(const Eigen::Vector3f& direction) = 0;
162  virtual Eigen::Vector3f GetSunLightDirection() = 0;
163  virtual void SetSunAngularRadius(float radius) = 0;
164  virtual void SetSunHaloSize(float size) = 0;
165  virtual void SetSunHaloFalloff(float falloff) = 0;
166 
167  virtual bool SetIndirectLight(const std::string& ibl_name) = 0;
168  virtual const std::string& GetIndirectLight() = 0;
169  virtual void EnableIndirectLight(bool enable) = 0;
170  virtual void SetIndirectLightIntensity(float intensity) = 0;
171  virtual float GetIndirectLightIntensity() = 0;
172  virtual void SetIndirectLightRotation(const Transform& rotation) = 0;
174  virtual void ShowSkybox(bool show) = 0;
175  virtual bool GetSkyboxVisible() const = 0;
176  virtual void SetBackground(
177  const Eigen::Vector4f& color,
178  const std::shared_ptr<geometry::Image> image = nullptr) = 0;
179  virtual void SetBackground(TextureHandle image) = 0;
180 
181  enum class GroundPlane { XZ, XY, YZ };
182  virtual void EnableGroundPlane(bool enable, GroundPlane plane) = 0;
183  virtual void SetGroundPlaneColor(const Eigen::Vector4f& color) = 0;
184 
186  virtual void RenderToImage(
187  std::function<void(std::shared_ptr<geometry::Image>)> callback) = 0;
188 
190  virtual void RenderToDepthImage(
191  std::function<void(std::shared_ptr<geometry::Image>)> callback) = 0;
192 
193 protected:
195 };
196 
197 } // namespace rendering
198 } // namespace visualization
199 } // namespace open3d
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:183
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:182
math::float4 color
Definition: LineSetBuffers.cpp:45
math::float3 position
Definition: LineSetBuffers.cpp:43
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:160
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
The base geometry class.
Definition: Geometry.h:21
A point cloud contains a list of 3D points.
Definition: PointCloud.h:80
virtual void SetGeometryCulling(const std::string &object_name, bool enable)=0
virtual void GeometryShadows(const std::string &object_name, bool cast_shadows, bool receive_shadows)=0
virtual Transform GetGeometryTransform(const std::string &object_name)=0
virtual void UpdateLightConeAngles(const std::string &light_name, float inner_cone_angle, float outer_cone_angle)=0
virtual bool SetIndirectLight(const std::string &ibl_name)=0
virtual void QueryGeometry(std::vector< std::string > &geometry)=0
Scene(Renderer &renderer)
Definition: Scene.h:51
virtual void SetRenderOnce(const ViewHandle &view_id)=0
virtual void SetSunLightDirection(const Eigen::Vector3f &direction)=0
virtual const std::string & GetIndirectLight()=0
virtual void SetIndirectLightIntensity(float intensity)=0
virtual void UpdateLightPosition(const std::string &light_name, const Eigen::Vector3f &position)=0
virtual bool AddGeometry(const std::string &object_name, const t::geometry::Geometry &geometry, const MaterialRecord &material, const std::string &downsampled_name="", size_t downsample_threshold=SIZE_MAX)=0
virtual bool GeometryIsVisible(const std::string &object_name)=0
virtual void SetSunHaloSize(float size)=0
virtual Eigen::Vector3f GetSunLightColor()=0
virtual void UpdateGeometry(const std::string &object_name, const t::geometry::PointCloud &point_cloud, uint32_t update_flags)=0
virtual void SetSunAngularRadius(float radius)=0
virtual void AddCamera(const std::string &camera_name, std::shared_ptr< Camera > cam)=0
static const uint32_t kUpdatePointsFlag
Definition: Scene.h:44
virtual void EnableSunLightShadows(bool enable)=0
virtual bool AddDirectionalLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &direction, float intensity, bool cast_shadows)=0
virtual void SetSunLightIntensity(float intensity)=0
virtual Light & GetLight(const std::string &light_name)=0
virtual bool HasGeometry(const std::string &object_name) const =0
virtual void OverrideMaterial(const std::string &object_name, const MaterialRecord &material)=0
Renderer & renderer_
Definition: Scene.h:194
virtual void SetViewActive(const ViewHandle &view_id, bool is_active)=0
virtual void SetBackground(TextureHandle image)=0
virtual void UpdateLightIntensity(const std::string &light_name, float intensity)=0
virtual void SetBackground(const Eigen::Vector4f &color, const std::shared_ptr< geometry::Image > image=nullptr)=0
virtual void RenderToImage(std::function< void(std::shared_ptr< geometry::Image >)> callback)=0
Size of image is the size of the window.
virtual void RemoveGeometry(const std::string &object_name)=0
virtual void UpdateLight(const std::string &light_name, const Light &light)=0
virtual void RenderToDepthImage(std::function< void(std::shared_ptr< geometry::Image >)> callback)=0
Size of image is the size of the window.
virtual void SetGeometryPriority(const std::string &object_name, uint8_t priority)=0
virtual void SetSunLightColor(const Eigen::Vector3f &color)=0
virtual void OverrideMaterialAll(const MaterialRecord &material, bool shader_only=true)=0
virtual ViewHandle AddView(std::int32_t x, std::int32_t y, std::uint32_t w, std::uint32_t h)=0
virtual void EnableLightShadow(const std::string &light_name, bool cast_shadows)=0
virtual void ShowGeometry(const std::string &object_name, bool show)=0
virtual void SetSunHaloFalloff(float falloff)=0
virtual bool AddGeometry(const std::string &object_name, const TriangleMeshModel &model)=0
virtual void SetGroundPlaneColor(const Eigen::Vector4f &color)=0
virtual void EnableGroundPlane(bool enable, GroundPlane plane)=0
virtual void RemoveLight(const std::string &light_name)=0
virtual void SetIndirectLightRotation(const Transform &rotation)=0
virtual geometry::AxisAlignedBoundingBox GetGeometryBoundingBox(const std::string &object_name)=0
virtual Transform GetIndirectLightRotation()=0
virtual void RemoveCamera(const std::string &camera_name)=0
static const uint32_t kUpdateNormalsFlag
Definition: Scene.h:45
virtual void UpdateLightColor(const std::string &light_name, const Eigen::Vector3f &color)=0
static const uint32_t kUpdateUv0Flag
Definition: Scene.h:47
virtual void RemoveView(const ViewHandle &view_id)=0
virtual void SetGeometryTransform(const std::string &object_name, const Transform &transform)=0
virtual void SetActiveCamera(const std::string &camera_name)=0
static const uint32_t kUpdateColorsFlag
Definition: Scene.h:46
virtual bool AddPointLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &position, float intensity, float falloff, bool cast_shadows)=0
virtual bool AddSpotLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &position, const Eigen::Vector3f &direction, float intensity, float falloff, float inner_cone_angle, float outer_cone_angle, bool cast_shadows)=0
virtual void EnableIndirectLight(bool enable)=0
virtual void UpdateLightFalloff(const std::string &light_name, float falloff)=0
virtual View * GetView(const ViewHandle &view_id) const =0
virtual void EnableSunLight(bool enable)=0
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Scene.h:49
virtual void ShowSkybox(bool show)=0
virtual void UpdateLightDirection(const std::string &light_name, const Eigen::Vector3f &direction)=0
virtual bool GetSkyboxVisible() const =0
virtual void SetSunLight(const Eigen::Vector3f &direction, const Eigen::Vector3f &color, float intensity)=0
virtual Eigen::Vector3f GetSunLightDirection()=0
virtual bool AddGeometry(const std::string &object_name, const geometry::Geometry3D &geometry, const MaterialRecord &material, const std::string &downsampled_name="", size_t downsample_threshold=SIZE_MAX)=0
int size
Definition: FilePCD.cpp:40
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:548
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:395
Definition: PinholeCameraIntrinsic.cpp:16