Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Renderer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2019 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 
31 
32 namespace open3d {
33 
34 namespace t {
35 namespace geometry {
36 class Image;
37 }
38 } // namespace t
39 
40 namespace geometry {
41 class Image;
42 }
43 
44 namespace core {
45 class Tensor;
46 }
47 
48 namespace visualization {
49 namespace rendering {
50 
51 class RenderToBuffer;
52 class Scene;
53 class View;
54 
56 public:
57  using ErrorCallback = std::function<void(
58  const ResourceLoadRequest&, const uint8_t, const std::string&)>;
59 
60  ResourceLoadRequest(const void* data, size_t data_size);
61  explicit ResourceLoadRequest(const char* path);
62 
63  ResourceLoadRequest(const void* data,
64  size_t data_size,
65  ErrorCallback error_callback);
66  ResourceLoadRequest(const char* path, ErrorCallback error_callback);
67 
68  const void* data_;
69  const size_t data_size_;
70  const std::string path_;
72 };
73 
74 class Renderer {
75 public:
76  virtual ~Renderer() = default;
77 
78  virtual SceneHandle CreateScene() = 0;
79  virtual Scene* GetScene(const SceneHandle& id) const = 0;
80  virtual void DestroyScene(const SceneHandle& id) = 0;
81 
82  virtual void SetClearColor(const Eigen::Vector4f& color) = 0;
83  virtual void UpdateSwapChain() = 0;
84  virtual void UpdateBitmapSwapChain(int width, int height) = 0;
85 
86  virtual void BeginFrame() = 0;
87  virtual void Draw() = 0;
88  // If using the Filament renderer this must be called *before* EndFrame()!
89  virtual void RequestReadPixels(
90  int width,
91  int height,
92  std::function<void(std::shared_ptr<core::Tensor>)> callback) = 0;
93  virtual void EndFrame() = 0;
94 
95  virtual void SetOnAfterDraw(std::function<void()> callback) = 0;
96 
97  virtual MaterialHandle AddMaterial(const ResourceLoadRequest& request) = 0;
98  virtual MaterialInstanceHandle AddMaterialInstance(
99  const MaterialHandle& material) = 0;
100  virtual MaterialModifier& ModifyMaterial(const MaterialHandle& id) = 0;
101  virtual MaterialModifier& ModifyMaterial(
102  const MaterialInstanceHandle& id) = 0;
103  virtual void RemoveMaterialInstance(const MaterialInstanceHandle& id) = 0;
104 
105  virtual TextureHandle AddTexture(const ResourceLoadRequest& request,
106  bool srgb = false) = 0;
107  virtual TextureHandle AddTexture(
108  const std::shared_ptr<geometry::Image> image,
109  bool srgb = false) = 0;
110  virtual TextureHandle AddTexture(const t::geometry::Image& image,
111  bool srgb = false) = 0;
112  virtual bool UpdateTexture(TextureHandle texture,
113  const std::shared_ptr<geometry::Image> image,
114  bool srgb) = 0;
115  virtual bool UpdateTexture(TextureHandle texture,
116  const t::geometry::Image& image,
117  bool srgb) = 0;
118 
119  virtual void RemoveTexture(const TextureHandle& id) = 0;
120 
121  virtual IndirectLightHandle AddIndirectLight(
122  const ResourceLoadRequest& request) = 0;
123  virtual void RemoveIndirectLight(const IndirectLightHandle& id) = 0;
124 
125  virtual SkyboxHandle AddSkybox(const ResourceLoadRequest& request) = 0;
126  virtual void RemoveSkybox(const SkyboxHandle& id) = 0;
127 
128  virtual std::shared_ptr<RenderToBuffer> CreateBufferRenderer() = 0;
129 
130  void RenderToImage(
131  View* view,
132  Scene* scene,
133  std::function<void(std::shared_ptr<geometry::Image>)> cb);
134 
135  // Returns a float image ranging from 0 (near plane) to 1 (far plane)
136  void RenderToDepthImage(
137  View* view,
138  Scene* scene,
139  std::function<void(std::shared_ptr<geometry::Image>)> cb);
140 };
141 
142 } // namespace rendering
143 } // namespace visualization
144 } // namespace open3d
void Draw(const std::vector< std::shared_ptr< geometry::Geometry3D >> &geometries, const std::string &window_name, int width, int height, const std::vector< DrawAction > &actions)
Definition: Draw.cpp:63
ErrorCallback error_callback_
Definition: Renderer.h:71
Definition: MaterialModifier.h:126
const size_t data_size_
Definition: Renderer.h:69
const void * data_
Definition: Renderer.h:68
std::function< void(const ResourceLoadRequest &, const uint8_t, const std::string &)> ErrorCallback
Definition: Renderer.h:58
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:48
math::float4 color
Definition: LineSetBuffers.cpp:64
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:259
const std::string path_
Definition: Renderer.h:70
Definition: PinholeCameraIntrinsic.cpp:35
int height
Definition: FilePCD.cpp:72
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:228
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:227
int width
Definition: FilePCD.cpp:71
const char const char value recording_handle imu_sample recording_handle uint8_t data
Definition: K4aPlugin.cpp:274