Open3D (C++ API)  0.11.0
FilamentGeometryBuffersBuilder.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 
29 // clang-format off
30 // NOTE: This header must precede the Filament headers otherwise a conflict
31 // occurs between Filament and standard headers
33 
34 // 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
35 // 4146: Filament's utils/algorithm.h utils::details::ctz() tries to negate
36 // an unsigned int.
37 // 4293: Filament's utils/algorithm.h utils::details::clz() does strange
38 // things with MSVC. Somehow sizeof(unsigned int) > 4, but its size is
39 // 32 so that x >> 32 gives a warning. (Or maybe the compiler can't
40 // determine the if statement does not run.)
41 #ifdef _MSC_VER
42 #pragma warning(push)
43 #pragma warning(disable : 4068 4146 4293)
44 #endif // _MSC_VER
45 
46 #include <filament/Box.h>
47 #include <filament/RenderableManager.h>
48 
49 #ifdef _MSC_VER
50 #pragma warning(pop)
51 #endif // _MSC_VER
52 // clang-format on
53 
54 #include <memory>
55 #include <tuple>
56 
57 namespace open3d {
58 
59 namespace geometry {
60 class Geometry3D;
61 class LineSet;
62 class PointCloud;
63 class TriangleMesh;
64 } // namespace geometry
65 
66 namespace t {
67 namespace geometry {
68 class PointCloud;
69 }
70 } // namespace t
71 
72 namespace visualization {
73 namespace rendering {
74 
76 public:
77  // Note that the downsampled index buffer may be kBadId if a downsampled
78  // buffer was not requested, failed, or cannot be created (e.g. if not
79  // a point cloud).
80  using Buffers = std::tuple<VertexBufferHandle, // vertex buffer
81  IndexBufferHandle, // index buffer
82  IndexBufferHandle>; // downsampled buffer
84 
85  static std::unique_ptr<GeometryBuffersBuilder> GetBuilder(
86  const geometry::Geometry3D& geometry);
87  static std::unique_ptr<GeometryBuffersBuilder> GetBuilder(
88  const t::geometry::PointCloud& geometry);
89 
90  virtual ~GeometryBuffersBuilder() = default;
91 
92  virtual filament::RenderableManager::PrimitiveType GetPrimitiveType()
93  const = 0;
94 
95  // Defaults to infinity (that is, no downsampling). If threshold is
96  // set and the number of points exceeds the threshold, ConstructBuffers()
97  // will return a downsampled index buffer. Certain builders may ignore
98  // this threshold.
99  virtual void SetDownsampleThreshold(size_t min_points) {
100  downsample_threshold_ = min_points;
101  }
102 
103  virtual Buffers ConstructBuffers() = 0;
104  virtual filament::Box ComputeAABB() = 0;
105 
106 protected:
107  size_t downsample_threshold_ = SIZE_MAX;
108 
109  static void DeallocateBuffer(void* buffer, size_t size, void* user_ptr);
110 
111  static IndexBufferHandle CreateIndexBuffer(size_t max_index,
112  size_t n_subsamples = SIZE_MAX);
113 };
114 
116 public:
117  explicit TriangleMeshBuffersBuilder(const geometry::TriangleMesh& geometry);
118 
119  filament::RenderableManager::PrimitiveType GetPrimitiveType()
120  const override;
121 
122  Buffers ConstructBuffers() override;
123  filament::Box ComputeAABB() override;
124 
125 private:
126  const geometry::TriangleMesh& geometry_;
127 };
128 
130 public:
131  explicit PointCloudBuffersBuilder(const geometry::PointCloud& geometry);
132 
133  filament::RenderableManager::PrimitiveType GetPrimitiveType()
134  const override;
135 
136  Buffers ConstructBuffers() override;
137  filament::Box ComputeAABB() override;
138 
139 private:
140  const geometry::PointCloud& geometry_;
141 };
142 
144 public:
145  explicit TPointCloudBuffersBuilder(const t::geometry::PointCloud& geometry);
146 
147  filament::RenderableManager::PrimitiveType GetPrimitiveType()
148  const override;
149 
150  Buffers ConstructBuffers() override;
151  filament::Box ComputeAABB() override;
152 
153 private:
154  const t::geometry::PointCloud& geometry_;
155 };
156 
158 public:
159  explicit LineSetBuffersBuilder(const geometry::LineSet& geometry);
160 
161  filament::RenderableManager::PrimitiveType GetPrimitiveType()
162  const override;
163 
164  Buffers ConstructBuffers() override;
165  filament::Box ComputeAABB() override;
166 
167 private:
168  const geometry::LineSet& geometry_;
169 };
170 
171 } // namespace rendering
172 } // namespace visualization
173 } // namespace open3d
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:554
Definition: FilamentGeometryBuffersBuilder.h:143
A point cloud consists of point coordinates, and optionally point colors and point normals...
Definition: PointCloud.h:54
int size
Definition: FilePCD.cpp:59
Definition: FilamentGeometryBuffersBuilder.h:129
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
std::tuple< VertexBufferHandle, IndexBufferHandle, IndexBufferHandle > Buffers
Definition: FilamentGeometryBuffersBuilder.h:82
A pointcloud contains a set of 3D points.
Definition: PointCloud.h:93
Definition: FilamentGeometryBuffersBuilder.h:75
Definition: PinholeCameraIntrinsic.cpp:35
Definition: FilamentGeometryBuffersBuilder.h:115
REHandle< EntityType::VertexBuffer > VertexBufferHandle
Definition: RendererHandle.h:162
REHandle< EntityType::IndexBuffer > IndexBufferHandle
Definition: RendererHandle.h:163
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:54
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:48
std::uint32_t IndexType
Definition: FilamentGeometryBuffersBuilder.h:83
Definition: FilamentGeometryBuffersBuilder.h:157
virtual void SetDownsampleThreshold(size_t min_points)
Definition: FilamentGeometryBuffersBuilder.h:99