Open3D (C++ API)  0.17.0
Loading...
Searching...
No Matches
RenderToBuffer.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
10#include <cstdint>
11#include <functional>
12#include <memory>
13
14namespace open3d {
15namespace visualization {
16namespace rendering {
17
18class Scene;
19class View;
20
22public:
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) {
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
58protected:
59 std::function<void(RenderToBuffer*)> cleanup_callback_;
60};
61
62} // namespace rendering
63} // namespace visualization
64} // namespace open3d
void SetCleanupCallback(std::function< void(RenderToBuffer *)> cb)
Definition RenderToBuffer.h:40
virtual void Configure(const View *view, Scene *scene, int width, int height, int n_channels, bool depth_image, BufferReadyCallback cb)=0
std::function< void(RenderToBuffer *)> cleanup_callback_
Definition RenderToBuffer.h:59
virtual void SetDimensions(std::uint32_t width, std::uint32_t height)=0
std::function< void(const Buffer &)> BufferReadyCallback
Definition RenderToBuffer.h:31
int width
Definition FilePCD.cpp:52
int height
Definition FilePCD.cpp:53
Definition PinholeCameraIntrinsic.cpp:16
std::size_t height
Definition RenderToBuffer.h:25
std::size_t width
Definition RenderToBuffer.h:24
std::size_t size
Definition RenderToBuffer.h:28
const std::uint8_t * bytes
Definition RenderToBuffer.h:27
std::size_t n_channels
Definition RenderToBuffer.h:26