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