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