ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
RenderToBuffer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <cstdint>
11 #include <functional>
12 #include <memory>
13 
14 namespace cloudViewer {
15 namespace visualization {
16 namespace rendering {
17 
18 class Scene;
19 class View;
20 
22 public:
23  struct Buffer {
24  std::size_t width = 0;
25  std::size_t height = 0;
26  std::size_t n_channels = 0;
27  const std::uint8_t* bytes = nullptr;
28  std::size_t size = 0;
29  };
30 
31  using BufferReadyCallback = std::function<void(const Buffer&)>;
32 
33  virtual ~RenderToBuffer() = default;
34 
35  // Sets a callback that will be called after rendering is finished
36  // and after the BufferReadyCallback from Configure() is finished.
37  // This callback can be used to deallocate the object. In particular,
38  // SetCleanupCallback([](RenderToBuffer *self) { delete self; });
39  // is valid.
40  void SetCleanupCallback(std::function<void(RenderToBuffer*)> cb) {
41  cleanup_callback_ = cb;
42  }
43 
44  // BufferReadyCallback does not need to free Buffer::bytes.
45  // It should also not cache the pointer.
46  virtual void Configure(const View* view,
47  Scene* scene,
48  int width,
49  int height,
50  int n_channels,
51  bool depth_image,
52  BufferReadyCallback cb) = 0;
53  virtual void SetDimensions(std::uint32_t width, std::uint32_t height) = 0;
54  virtual View& GetView() = 0;
55 
56  virtual void Render() = 0;
57 
58 protected:
59  std::function<void(RenderToBuffer*)> cleanup_callback_;
60 };
61 
62 } // namespace rendering
63 } // namespace visualization
64 } // namespace cloudViewer
int width
int height
std::function< void(RenderToBuffer *)> cleanup_callback_
void SetCleanupCallback(std::function< void(RenderToBuffer *)> cb)
virtual void Configure(const View *view, Scene *scene, int width, int height, int n_channels, bool depth_image, BufferReadyCallback cb)=0
virtual void SetDimensions(std::uint32_t width, std::uint32_t height)=0
std::function< void(const Buffer &)> BufferReadyCallback
Generic file read and write utility for python interface.