Open3D (C++ API)  0.11.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 QueryGeometry(std::vector<std::string>& geometry) = 0;
115  virtual void SetGeometryTransform(const std::string& object_name,
116  const Transform& transform) = 0;
117  virtual Transform GetGeometryTransform(const std::string& object_name) = 0;
118  virtual geometry::AxisAlignedBoundingBox GetGeometryBoundingBox(
119  const std::string& object_name) = 0;
120  virtual void OverrideMaterialAll(const Material& material,
121  bool shader_only = true) = 0;
122 
123  // Lighting Environment
124  virtual bool AddPointLight(const std::string& light_name,
125  const Eigen::Vector3f& color,
126  const Eigen::Vector3f& position,
127  float intensity,
128  float falloff,
129  bool cast_shadows) = 0;
130  virtual bool AddSpotLight(const std::string& light_name,
131  const Eigen::Vector3f& color,
132  const Eigen::Vector3f& position,
133  const Eigen::Vector3f& direction,
134  float intensity,
135  float falloff,
136  float inner_cone_angle,
137  float outer_cone_angle,
138  bool cast_shadows) = 0;
139  virtual Light& GetLight(const std::string& light_name) = 0;
140  virtual void RemoveLight(const std::string& light_name) = 0;
141  virtual void UpdateLight(const std::string& light_name,
142  const Light& light) = 0;
143  virtual void UpdateLightColor(const std::string& light_name,
144  const Eigen::Vector3f& color) = 0;
145  virtual void UpdateLightPosition(const std::string& light_name,
146  const Eigen::Vector3f& position) = 0;
147  virtual void UpdateLightDirection(const std::string& light_name,
148  const Eigen::Vector3f& direction) = 0;
149  virtual void UpdateLightIntensity(const std::string& light_name,
150  float intensity) = 0;
151  virtual void UpdateLightFalloff(const std::string& light_name,
152  float falloff) = 0;
153  virtual void UpdateLightConeAngles(const std::string& light_name,
154  float inner_cone_angle,
155  float outer_cone_angle) = 0;
156  virtual void EnableLightShadow(const std::string& light_name,
157  bool cast_shadows) = 0;
158 
159  virtual void SetDirectionalLight(const Eigen::Vector3f& direction,
160  const Eigen::Vector3f& color,
161  float intensity) = 0;
162  virtual void EnableDirectionalLight(bool enable) = 0;
163  virtual void EnableDirectionalLightShadows(bool enable) = 0;
164  virtual void SetDirectionalLightDirection(
165  const Eigen::Vector3f& direction) = 0;
166  virtual Eigen::Vector3f GetDirectionalLightDirection() = 0;
167 
168  virtual bool SetIndirectLight(const std::string& ibl_name) = 0;
169  virtual const std::string& GetIndirectLight() = 0;
170  virtual void EnableIndirectLight(bool enable) = 0;
171  virtual void SetIndirectLightIntensity(float intensity) = 0;
172  virtual float GetIndirectLightIntensity() = 0;
173  virtual void SetIndirectLightRotation(const Transform& rotation) = 0;
174  virtual Transform GetIndirectLightRotation() = 0;
175  virtual void ShowSkybox(bool show) = 0;
176  virtual void SetBackgroundColor(const Eigen::Vector4f& color) = 0;
177 
179  virtual void RenderToImage(
180  std::function<void(std::shared_ptr<geometry::Image>)> callback) = 0;
181 
182 protected:
184 };
185 
186 } // namespace rendering
187 } // namespace visualization
188 } // 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:554
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:395
Renderer & renderer_
Definition: Scene.h:183
math::float4 color
Definition: LineSetBuffers.cpp:63
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:93
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