Open3D (C++ API)  0.18.0+5c982c7
FilamentGeometryBuffersBuilder.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 
13 
14 // clang-format off
15 // NOTE: This header must precede the Filament headers otherwise a conflict
16 // occurs between Filament and standard headers
18 
19 // 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
20 // 4146: Filament's utils/algorithm.h utils::details::ctz() tries to negate
21 // an unsigned int.
22 // 4293: Filament's utils/algorithm.h utils::details::clz() does strange
23 // things with MSVC. Somehow sizeof(unsigned int) > 4, but its size is
24 // 32 so that x >> 32 gives a warning. (Or maybe the compiler can't
25 // determine the if statement does not run.)
26 #ifdef _MSC_VER
27 #pragma warning(push)
28 #pragma warning(disable : 4068 4146 4293)
29 // Filament uses OPAQUE and TRANSPARENT as enums which conflicts with windows.h
30 #undef OPAQUE
31 #undef TRANSPARENT
32 #endif // _MSC_VER
33 
34 #include <filament/Box.h>
35 #include <filament/RenderableManager.h>
36 
37 #ifdef _MSC_VER
38 #pragma warning(pop)
39 #endif // _MSC_VER
40 // clang-format on
41 
42 #include <memory>
43 #include <tuple>
44 
45 namespace open3d {
46 
47 namespace geometry {
48 class Geometry3D;
49 class LineSet;
50 class PointCloud;
51 class TriangleMesh;
52 } // namespace geometry
53 
54 namespace visualization {
55 namespace rendering {
56 
58 public:
59  // Note that the downsampled index buffer may be kBadId if a downsampled
60  // buffer was not requested, failed, or cannot be created (e.g. if not
61  // a point cloud).
62  using Buffers = std::tuple<VertexBufferHandle, // vertex buffer
63  IndexBufferHandle, // index buffer
64  IndexBufferHandle>; // downsampled buffer
66 
67  static std::unique_ptr<GeometryBuffersBuilder> GetBuilder(
68  const geometry::Geometry3D& geometry);
69  static std::unique_ptr<GeometryBuffersBuilder> GetBuilder(
70  const t::geometry::Geometry& geometry);
71 
72  virtual ~GeometryBuffersBuilder() = default;
73 
74  virtual filament::RenderableManager::PrimitiveType GetPrimitiveType()
75  const = 0;
76 
77  // Defaults to infinity (that is, no downsampling). If threshold is
78  // set and the number of points exceeds the threshold, ConstructBuffers()
79  // will return a downsampled index buffer. Certain builders may ignore
80  // this threshold.
81  virtual void SetDownsampleThreshold(size_t min_points) {
82  downsample_threshold_ = min_points;
83  }
84 
85  // Instructs LineSetBuffersBuilder to build lines out of triangles for wide
86  // lines shader.
87  virtual void SetWideLines() { wide_lines_ = true; }
88 
89  virtual void SetAdjustColorsForSRGBToneMapping(bool adjust) {
91  }
92 
93  virtual Buffers ConstructBuffers() = 0;
94  virtual filament::Box ComputeAABB() = 0;
95 
96 protected:
97  size_t downsample_threshold_ = SIZE_MAX;
98  bool wide_lines_ = false;
100 
101  static void DeallocateBuffer(void* buffer, size_t size, void* user_ptr);
102 
103  static IndexBufferHandle CreateIndexBuffer(size_t max_index,
104  size_t n_subsamples = SIZE_MAX);
105 };
106 
108 public:
109  explicit TriangleMeshBuffersBuilder(const geometry::TriangleMesh& geometry);
110 
111  filament::RenderableManager::PrimitiveType GetPrimitiveType()
112  const override;
113 
114  Buffers ConstructBuffers() override;
115  filament::Box ComputeAABB() override;
116 
117 private:
118  const geometry::TriangleMesh& geometry_;
119 };
120 
122 public:
123  explicit PointCloudBuffersBuilder(const geometry::PointCloud& geometry);
124 
125  filament::RenderableManager::PrimitiveType GetPrimitiveType()
126  const override;
127 
128  Buffers ConstructBuffers() override;
129  filament::Box ComputeAABB() override;
130 
131 private:
132  const geometry::PointCloud& geometry_;
133 };
134 
136 public:
137  explicit LineSetBuffersBuilder(const geometry::LineSet& geometry);
138 
139  filament::RenderableManager::PrimitiveType GetPrimitiveType()
140  const override;
141 
142  Buffers ConstructBuffers() override;
143  filament::Box ComputeAABB() override;
144 
145 private:
146  Buffers ConstructThinLines();
147 
148  const geometry::LineSet& geometry_;
149 };
150 
152 public:
153  explicit TMeshBuffersBuilder(const t::geometry::TriangleMesh& geometry);
154 
155  filament::RenderableManager::PrimitiveType GetPrimitiveType()
156  const override;
157 
158  Buffers ConstructBuffers() override;
159  filament::Box ComputeAABB() override;
160 
161 private:
162  t::geometry::TriangleMesh geometry_;
163 };
164 
166 public:
167  explicit TPointCloudBuffersBuilder(const t::geometry::PointCloud& geometry);
168 
169  filament::RenderableManager::PrimitiveType GetPrimitiveType()
170  const override;
171 
172  Buffers ConstructBuffers() override;
173  filament::Box ComputeAABB() override;
174 
175 private:
176  t::geometry::PointCloud geometry_;
177 };
178 
180 public:
181  explicit TLineSetBuffersBuilder(const t::geometry::LineSet& geometry);
182 
183  filament::RenderableManager::PrimitiveType GetPrimitiveType()
184  const override;
185 
186  Buffers ConstructBuffers() override;
187  filament::Box ComputeAABB() override;
188 
189 private:
192  void ConstructThinLines(uint32_t& n_vertices,
193  float** vertex_data,
194  uint32_t& n_indices,
195  uint32_t& indices_bytes,
196  uint32_t** line_indices);
199  void ConstructWideLines(uint32_t& n_vertices,
200  float** vertex_data,
201  uint32_t& n_indices,
202  uint32_t& indices_bytes,
203  uint32_t** line_indices);
204  t::geometry::LineSet geometry_;
205 };
206 
207 } // namespace rendering
208 } // namespace visualization
209 } // namespace open3d
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:29
A point cloud consists of point coordinates, and optionally point colors and point normals.
Definition: PointCloud.h:36
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:35
The base geometry class.
Definition: Geometry.h:21
A LineSet contains points and lines joining them and optionally attributes on the points and lines.
Definition: LineSet.h:84
A point cloud contains a list of 3D points.
Definition: PointCloud.h:80
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:94
Definition: FilamentGeometryBuffersBuilder.h:57
std::tuple< VertexBufferHandle, IndexBufferHandle, IndexBufferHandle > Buffers
Definition: FilamentGeometryBuffersBuilder.h:64
bool adjust_colors_for_srgb_tonemapping_
Definition: FilamentGeometryBuffersBuilder.h:99
static void DeallocateBuffer(void *buffer, size_t size, void *user_ptr)
Definition: FilamentGeometryBuffersBuilder.cpp:269
virtual void SetAdjustColorsForSRGBToneMapping(bool adjust)
Definition: FilamentGeometryBuffersBuilder.h:89
std::uint32_t IndexType
Definition: FilamentGeometryBuffersBuilder.h:65
static std::unique_ptr< GeometryBuffersBuilder > GetBuilder(const geometry::Geometry3D &geometry)
Definition: FilamentGeometryBuffersBuilder.cpp:200
bool wide_lines_
Definition: FilamentGeometryBuffersBuilder.h:98
size_t downsample_threshold_
Definition: FilamentGeometryBuffersBuilder.h:97
virtual void SetWideLines()
Definition: FilamentGeometryBuffersBuilder.h:87
static IndexBufferHandle CreateIndexBuffer(size_t max_index, size_t n_subsamples=SIZE_MAX)
Definition: PointCloudBuffers.cpp:89
virtual void SetDownsampleThreshold(size_t min_points)
Definition: FilamentGeometryBuffersBuilder.h:81
virtual filament::RenderableManager::PrimitiveType GetPrimitiveType() const =0
Definition: FilamentGeometryBuffersBuilder.h:135
filament::RenderableManager::PrimitiveType GetPrimitiveType() const override
Definition: LineSetBuffers.cpp:86
LineSetBuffersBuilder(const geometry::LineSet &geometry)
Definition: LineSetBuffers.cpp:83
Buffers ConstructBuffers() override
Definition: LineSetBuffers.cpp:226
filament::Box ComputeAABB() override
Definition: LineSetBuffers.cpp:349
Definition: FilamentGeometryBuffersBuilder.h:121
Buffers ConstructBuffers() override
Definition: PointCloudBuffers.cpp:160
filament::RenderableManager::PrimitiveType GetPrimitiveType() const override
Definition: PointCloudBuffers.cpp:155
filament::Box ComputeAABB() override
Definition: PointCloudBuffers.cpp:266
PointCloudBuffersBuilder(const geometry::PointCloud &geometry)
Definition: PointCloudBuffers.cpp:151
Definition: FilamentGeometryBuffersBuilder.h:179
Buffers ConstructBuffers() override
Definition: LineSetBuffers.cpp:550
filament::RenderableManager::PrimitiveType GetPrimitiveType() const override
Definition: LineSetBuffers.cpp:402
filament::Box ComputeAABB() override
Definition: LineSetBuffers.cpp:632
TLineSetBuffersBuilder(const t::geometry::LineSet &geometry)
Definition: LineSetBuffers.cpp:365
Definition: FilamentGeometryBuffersBuilder.h:151
Buffers ConstructBuffers() override
Definition: TriangleMeshBuffers.cpp:614
filament::RenderableManager::PrimitiveType GetPrimitiveType() const override
Definition: TriangleMeshBuffers.cpp:610
filament::Box ComputeAABB() override
Definition: TriangleMeshBuffers.cpp:810
TMeshBuffersBuilder(const t::geometry::TriangleMesh &geometry)
Definition: TriangleMeshBuffers.cpp:565
Definition: FilamentGeometryBuffersBuilder.h:165
Buffers ConstructBuffers() override
Definition: PointCloudBuffers.cpp:337
filament::Box ComputeAABB() override
Definition: PointCloudBuffers.cpp:468
filament::RenderableManager::PrimitiveType GetPrimitiveType() const override
Definition: PointCloudBuffers.cpp:332
TPointCloudBuffersBuilder(const t::geometry::PointCloud &geometry)
Definition: PointCloudBuffers.cpp:289
Definition: FilamentGeometryBuffersBuilder.h:107
filament::Box ComputeAABB() override
Definition: TriangleMeshBuffers.cpp:549
Buffers ConstructBuffers() override
Definition: TriangleMeshBuffers.cpp:415
TriangleMeshBuffersBuilder(const geometry::TriangleMesh &geometry)
Definition: TriangleMeshBuffers.cpp:406
filament::RenderableManager::PrimitiveType GetPrimitiveType() const override
Definition: TriangleMeshBuffers.cpp:410
int size
Definition: FilePCD.cpp:40
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:548
REHandle< EntityType::IndexBuffer > IndexBufferHandle
Definition: RendererHandle.h:139
REHandle< EntityType::VertexBuffer > VertexBufferHandle
Definition: RendererHandle.h:138
Definition: PinholeCameraIntrinsic.cpp:16