Open3D (C++ API)  0.12.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  // Instructs LineSetBuffersBuilder to build lines out of triangles for wide
104  // lines shader.
105  virtual void SetWideLines() { wide_lines_ = true; }
106 
107  virtual void SetAdjustColorsForSRGBToneMapping(bool adjust) {
108  adjust_colors_for_srgb_tonemapping_ = adjust;
109  }
110 
111  virtual Buffers ConstructBuffers() = 0;
112  virtual filament::Box ComputeAABB() = 0;
113 
114 protected:
115  size_t downsample_threshold_ = SIZE_MAX;
116  bool wide_lines_ = false;
117  bool adjust_colors_for_srgb_tonemapping_ = true;
118 
119  static void DeallocateBuffer(void* buffer, size_t size, void* user_ptr);
120 
121  static IndexBufferHandle CreateIndexBuffer(size_t max_index,
122  size_t n_subsamples = SIZE_MAX);
123 };
124 
126 public:
127  explicit TriangleMeshBuffersBuilder(const geometry::TriangleMesh& geometry);
128 
129  filament::RenderableManager::PrimitiveType GetPrimitiveType()
130  const override;
131 
132  Buffers ConstructBuffers() override;
133  filament::Box ComputeAABB() override;
134 
135 private:
136  const geometry::TriangleMesh& geometry_;
137 };
138 
140 public:
141  explicit PointCloudBuffersBuilder(const geometry::PointCloud& geometry);
142 
143  filament::RenderableManager::PrimitiveType GetPrimitiveType()
144  const override;
145 
146  Buffers ConstructBuffers() override;
147  filament::Box ComputeAABB() override;
148 
149 private:
150  const geometry::PointCloud& geometry_;
151 };
152 
154 public:
155  explicit TPointCloudBuffersBuilder(const t::geometry::PointCloud& geometry);
156 
157  filament::RenderableManager::PrimitiveType GetPrimitiveType()
158  const override;
159 
160  Buffers ConstructBuffers() override;
161  filament::Box ComputeAABB() override;
162 
163 private:
164  const t::geometry::PointCloud& geometry_;
165 };
166 
168 public:
169  explicit LineSetBuffersBuilder(const geometry::LineSet& geometry);
170 
171  filament::RenderableManager::PrimitiveType GetPrimitiveType()
172  const override;
173 
174  Buffers ConstructBuffers() override;
175  filament::Box ComputeAABB() override;
176 
177 private:
178  Buffers ConstructThinLines();
179 
180  const geometry::LineSet& geometry_;
181 };
182 
183 } // namespace rendering
184 } // namespace visualization
185 } // 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:153
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:139
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:94
Definition: FilamentGeometryBuffersBuilder.h:75
virtual void SetAdjustColorsForSRGBToneMapping(bool adjust)
Definition: FilamentGeometryBuffersBuilder.h:107
Definition: PinholeCameraIntrinsic.cpp:35
Definition: FilamentGeometryBuffersBuilder.h:125
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:167
virtual void SetDownsampleThreshold(size_t min_points)
Definition: FilamentGeometryBuffersBuilder.h:99
virtual void SetWideLines()
Definition: FilamentGeometryBuffersBuilder.h:105