Open3D (C++ API)  0.18.0+252c867
Renderer.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 
12 
13 namespace open3d {
14 
15 namespace t {
16 namespace geometry {
17 class Image;
18 }
19 } // namespace t
20 
21 namespace geometry {
22 class Image;
23 }
24 
25 namespace core {
26 class Tensor;
27 }
28 
29 namespace visualization {
30 namespace rendering {
31 
32 class RenderToBuffer;
33 class Scene;
34 class View;
35 
37 public:
38  using ErrorCallback = std::function<void(
39  const ResourceLoadRequest&, const uint8_t, const std::string&)>;
40 
41  ResourceLoadRequest(const void* data, size_t data_size);
42  explicit ResourceLoadRequest(const char* path);
43 
44  ResourceLoadRequest(const void* data,
45  size_t data_size,
46  ErrorCallback error_callback);
47  ResourceLoadRequest(const char* path, ErrorCallback error_callback);
48 
49  const void* data_;
50  const size_t data_size_;
51  const std::string path_;
53 };
54 
55 class Renderer {
56 public:
57  virtual ~Renderer() = default;
58 
59  virtual SceneHandle CreateScene() = 0;
60  virtual Scene* GetScene(const SceneHandle& id) const = 0;
61  virtual void DestroyScene(const SceneHandle& id) = 0;
62 
63  virtual void SetClearColor(const Eigen::Vector4f& color) = 0;
64  virtual void UpdateSwapChain() = 0;
65  virtual void UpdateBitmapSwapChain(int width, int height) = 0;
66 
67  virtual void BeginFrame() = 0;
68  virtual void Draw() = 0;
69  // If using the Filament renderer this must be called *before* EndFrame()!
70  virtual void RequestReadPixels(
71  int width,
72  int height,
73  std::function<void(std::shared_ptr<core::Tensor>)> callback) = 0;
74  virtual void EndFrame() = 0;
75 
76  virtual void SetOnAfterDraw(std::function<void()> callback) = 0;
77 
78  virtual MaterialHandle AddMaterial(const ResourceLoadRequest& request) = 0;
80  const MaterialHandle& material) = 0;
83  const MaterialInstanceHandle& id) = 0;
84  virtual void RemoveMaterialInstance(const MaterialInstanceHandle& id) = 0;
85 
87  bool srgb = false) = 0;
89  const std::shared_ptr<geometry::Image> image,
90  bool srgb = false) = 0;
92  bool srgb = false) = 0;
93  virtual bool UpdateTexture(TextureHandle texture,
94  const std::shared_ptr<geometry::Image> image,
95  bool srgb) = 0;
96  virtual bool UpdateTexture(TextureHandle texture,
98  bool srgb) = 0;
99 
100  virtual void RemoveTexture(const TextureHandle& id) = 0;
101 
103  const ResourceLoadRequest& request) = 0;
104  virtual void RemoveIndirectLight(const IndirectLightHandle& id) = 0;
105 
106  virtual SkyboxHandle AddSkybox(const ResourceLoadRequest& request) = 0;
107  virtual void RemoveSkybox(const SkyboxHandle& id) = 0;
108 
109  virtual std::shared_ptr<RenderToBuffer> CreateBufferRenderer() = 0;
110 
111  void RenderToImage(
112  View* view,
113  Scene* scene,
114  std::function<void(std::shared_ptr<geometry::Image>)> cb);
115 
116  // Returns a float image ranging from 0 (near plane) to 1 (far plane)
117  void RenderToDepthImage(
118  View* view,
119  Scene* scene,
120  std::function<void(std::shared_ptr<geometry::Image>)> cb,
121  bool z_in_view_space = false);
122 };
123 
124 } // namespace rendering
125 } // namespace visualization
126 } // 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
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:29
Definition: MaterialModifier.h:107
virtual void RemoveMaterialInstance(const MaterialInstanceHandle &id)=0
virtual void RemoveTexture(const TextureHandle &id)=0
virtual void RemoveIndirectLight(const IndirectLightHandle &id)=0
virtual TextureHandle AddTexture(const ResourceLoadRequest &request, bool srgb=false)=0
virtual void RequestReadPixels(int width, int height, std::function< void(std::shared_ptr< core::Tensor >)> callback)=0
virtual bool UpdateTexture(TextureHandle texture, const t::geometry::Image &image, bool srgb)=0
virtual std::shared_ptr< RenderToBuffer > CreateBufferRenderer()=0
virtual void SetClearColor(const Eigen::Vector4f &color)=0
virtual Scene * GetScene(const SceneHandle &id) const =0
virtual SkyboxHandle AddSkybox(const ResourceLoadRequest &request)=0
virtual void RemoveSkybox(const SkyboxHandle &id)=0
virtual IndirectLightHandle AddIndirectLight(const ResourceLoadRequest &request)=0
void RenderToDepthImage(View *view, Scene *scene, std::function< void(std::shared_ptr< geometry::Image >)> cb, bool z_in_view_space=false)
Definition: Renderer.cpp:94
virtual TextureHandle AddTexture(const t::geometry::Image &image, bool srgb=false)=0
virtual bool UpdateTexture(TextureHandle texture, const std::shared_ptr< geometry::Image > image, bool srgb)=0
virtual MaterialModifier & ModifyMaterial(const MaterialHandle &id)=0
virtual void DestroyScene(const SceneHandle &id)=0
virtual MaterialModifier & ModifyMaterial(const MaterialInstanceHandle &id)=0
virtual void UpdateBitmapSwapChain(int width, int height)=0
virtual MaterialInstanceHandle AddMaterialInstance(const MaterialHandle &material)=0
virtual MaterialHandle AddMaterial(const ResourceLoadRequest &request)=0
virtual TextureHandle AddTexture(const std::shared_ptr< geometry::Image > image, bool srgb=false)=0
void RenderToImage(View *view, Scene *scene, std::function< void(std::shared_ptr< geometry::Image >)> cb)
Definition: Renderer.cpp:67
virtual void SetOnAfterDraw(std::function< void()> callback)=0
const void * data_
Definition: Renderer.h:49
const size_t data_size_
Definition: Renderer.h:50
std::function< void(const ResourceLoadRequest &, const uint8_t, const std::string &)> ErrorCallback
Definition: Renderer.h:39
ResourceLoadRequest(const void *data, size_t data_size)
Definition: Renderer.cpp:40
ErrorCallback error_callback_
Definition: Renderer.h:52
const std::string path_
Definition: Renderer.h:51
int width
Definition: FilePCD.cpp:52
int height
Definition: FilePCD.cpp:53
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:250
const char const char value recording_handle imu_sample recording_handle uint8_t data
Definition: K4aPlugin.cpp:269
Definition: PinholeCameraIntrinsic.cpp:16