Open3D (C++ API)  0.12.0
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  // NOTE: Temporarily need to support old View interface for ImGUI
73  virtual ViewHandle AddView(std::int32_t x,
74  std::int32_t y,
75  std::uint32_t w,
76  std::uint32_t h) = 0;
77 
78  virtual View* GetView(const ViewHandle& view_id) const = 0;
79  virtual void SetViewActive(const ViewHandle& view_id, bool is_active) = 0;
80  virtual void SetRenderOnce(const ViewHandle& view_id) = 0;
81  virtual void RemoveView(const ViewHandle& view_id) = 0;
82 
83  // Camera
84  virtual void AddCamera(const std::string& camera_name,
85  std::shared_ptr<Camera> cam) = 0;
86  virtual void RemoveCamera(const std::string& camera_name) = 0;
87  virtual void SetActiveCamera(const std::string& camera_name) = 0;
88 
89  // Scene geometry
90  virtual bool AddGeometry(const std::string& object_name,
91  const geometry::Geometry3D& geometry,
92  const Material& material,
93  const std::string& downsampled_name = "",
94  size_t downsample_threshold = SIZE_MAX) = 0;
95  virtual bool AddGeometry(const std::string& object_name,
96  const t::geometry::PointCloud& point_cloud,
97  const Material& material,
98  const std::string& downsampled_name = "",
99  size_t downsample_threshold = SIZE_MAX) = 0;
100  virtual bool AddGeometry(const std::string& object_name,
101  const TriangleMeshModel& model) = 0;
102  virtual bool HasGeometry(const std::string& object_name) const = 0;
103  virtual void UpdateGeometry(const std::string& object_name,
104  const t::geometry::PointCloud& point_cloud,
105  uint32_t update_flags) = 0;
106  virtual void RemoveGeometry(const std::string& object_name) = 0;
107  virtual void ShowGeometry(const std::string& object_name, bool show) = 0;
108  virtual bool GeometryIsVisible(const std::string& object_name) = 0;
109  virtual void OverrideMaterial(const std::string& object_name,
110  const Material& material) = 0;
111  virtual void GeometryShadows(const std::string& object_name,
112  bool cast_shadows,
113  bool receive_shadows) = 0;
114  virtual void SetGeometryCulling(const std::string& object_name,
115  bool enable) = 0;
116  virtual void SetGeometryPriority(const std::string& object_name,
117  uint8_t priority) = 0;
118  virtual void QueryGeometry(std::vector<std::string>& geometry) = 0;
119  virtual void SetGeometryTransform(const std::string& object_name,
120  const Transform& transform) = 0;
121  virtual Transform GetGeometryTransform(const std::string& object_name) = 0;
122  virtual geometry::AxisAlignedBoundingBox GetGeometryBoundingBox(
123  const std::string& object_name) = 0;
124  virtual void OverrideMaterialAll(const Material& material,
125  bool shader_only = true) = 0;
126 
127  // Lighting Environment
128  virtual bool AddPointLight(const std::string& light_name,
129  const Eigen::Vector3f& color,
130  const Eigen::Vector3f& position,
131  float intensity,
132  float falloff,
133  bool cast_shadows) = 0;
134  virtual bool AddSpotLight(const std::string& light_name,
135  const Eigen::Vector3f& color,
136  const Eigen::Vector3f& position,
137  const Eigen::Vector3f& direction,
138  float intensity,
139  float falloff,
140  float inner_cone_angle,
141  float outer_cone_angle,
142  bool cast_shadows) = 0;
143  virtual bool AddDirectionalLight(const std::string& light_name,
144  const Eigen::Vector3f& color,
145  const Eigen::Vector3f& direction,
146  float intensity,
147  bool cast_shadows) = 0;
148  virtual Light& GetLight(const std::string& light_name) = 0;
149  virtual void RemoveLight(const std::string& light_name) = 0;
150  virtual void UpdateLight(const std::string& light_name,
151  const Light& light) = 0;
152  virtual void UpdateLightColor(const std::string& light_name,
153  const Eigen::Vector3f& color) = 0;
154  virtual void UpdateLightPosition(const std::string& light_name,
155  const Eigen::Vector3f& position) = 0;
156  virtual void UpdateLightDirection(const std::string& light_name,
157  const Eigen::Vector3f& direction) = 0;
158  virtual void UpdateLightIntensity(const std::string& light_name,
159  float intensity) = 0;
160  virtual void UpdateLightFalloff(const std::string& light_name,
161  float falloff) = 0;
162  virtual void UpdateLightConeAngles(const std::string& light_name,
163  float inner_cone_angle,
164  float outer_cone_angle) = 0;
165  virtual void EnableLightShadow(const std::string& light_name,
166  bool cast_shadows) = 0;
167 
168  virtual void SetSunLight(const Eigen::Vector3f& direction,
169  const Eigen::Vector3f& color,
170  float intensity) = 0;
171  virtual void EnableSunLight(bool enable) = 0;
172  virtual void EnableSunLightShadows(bool enable) = 0;
173  virtual float GetSunLightIntensity() = 0;
174  virtual void SetSunLightDirection(const Eigen::Vector3f& direction) = 0;
175  virtual Eigen::Vector3f GetSunLightDirection() = 0;
176  virtual void SetSunAngularRadius(float radius) = 0;
177  virtual void SetSunHaloSize(float size) = 0;
178  virtual void SetSunHaloFalloff(float falloff) = 0;
179 
180  virtual bool SetIndirectLight(const std::string& ibl_name) = 0;
181  virtual const std::string& GetIndirectLight() = 0;
182  virtual void EnableIndirectLight(bool enable) = 0;
183  virtual void SetIndirectLightIntensity(float intensity) = 0;
184  virtual float GetIndirectLightIntensity() = 0;
185  virtual void SetIndirectLightRotation(const Transform& rotation) = 0;
186  virtual Transform GetIndirectLightRotation() = 0;
187  virtual void ShowSkybox(bool show) = 0;
188  virtual void SetBackground(
189  const Eigen::Vector4f& color,
190  const std::shared_ptr<geometry::Image> image = nullptr) = 0;
191 
193  virtual void RenderToImage(
194  std::function<void(std::shared_ptr<geometry::Image>)> callback) = 0;
195 
196 protected:
198 };
199 
200 } // namespace rendering
201 } // namespace visualization
202 } // 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
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Scene.h:67
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:149
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:197
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:94
Definition: PinholeCameraIntrinsic.cpp:35
Scene(Renderer &renderer)
Definition: Scene.h:69
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:394