41 #ifndef PCL_SURFACE_ORGANIZED_FAST_MESH_HPP_
42 #define PCL_SURFACE_ORGANIZED_FAST_MESH_HPP_
44 #include <pcl/surface/organized_fast_mesh.h>
45 #include <pcl/common/io.h>
48 template <
typename Po
intInT>
void
51 if (!input_->isOrganized()) {
52 PCL_ERROR(
"[OrganizedFastMesh::performReconstruction] Input point cloud must be organized but isn't!\n");
55 reconstructPolygons (output.
polygons);
61 if (x_idx == -1 || y_idx == -1 || z_idx == -1)
67 for (std::size_t i = 0; i < input_->size (); ++i)
69 resetPointData (i, output, 0.0f, x_idx, y_idx, z_idx);
73 template <
typename Po
intInT>
void
76 if (!input_->isOrganized()) {
77 PCL_ERROR(
"[OrganizedFastMesh::performReconstruction] Input point cloud must be organized but isn't!\n");
80 reconstructPolygons (polygons);
84 template <
typename Po
intInT>
void
87 if (triangulation_type_ == TRIANGLE_RIGHT_CUT)
88 makeRightCutMesh (polygons);
89 else if (triangulation_type_ == TRIANGLE_LEFT_CUT)
90 makeLeftCutMesh (polygons);
91 else if (triangulation_type_ == TRIANGLE_ADAPTIVE_CUT)
92 makeAdaptiveCutMesh (polygons);
93 else if (triangulation_type_ == QUAD_MESH)
94 makeQuadMesh (polygons);
98 template <
typename Po
intInT>
void
101 int last_column = input_->width - triangle_pixel_size_columns_;
102 int last_row = input_->height - triangle_pixel_size_rows_;
104 int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
105 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
106 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
108 polygons.resize (input_->width * input_->height);
111 for (
int y = 0; y < last_row; y += triangle_pixel_size_rows_)
114 i = y * input_->width;
115 index_right = i + triangle_pixel_size_columns_;
116 index_down = i + y_big_incr;
117 index_down_right = i + x_big_incr;
120 for (
int x = 0; x < last_column; x += triangle_pixel_size_columns_,
121 i += triangle_pixel_size_columns_,
122 index_right += triangle_pixel_size_columns_,
123 index_down += triangle_pixel_size_columns_,
124 index_down_right += triangle_pixel_size_columns_)
126 if (isValidQuad (i, index_right, index_down_right, index_down))
127 if (store_shadowed_faces_ || !isShadowedQuad (i, index_right, index_down_right, index_down))
128 addQuad (i, index_right, index_down_right, index_down, idx++, polygons);
131 polygons.resize (idx);
135 template <
typename Po
intInT>
void
138 int last_column = input_->width - triangle_pixel_size_columns_;
139 int last_row = input_->height - triangle_pixel_size_rows_;
141 int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
142 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
143 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
145 polygons.resize (input_->width * input_->height * 2);
148 for (
int y = 0; y < last_row; y += triangle_pixel_size_rows_)
151 i = y * input_->width;
152 index_right = i + triangle_pixel_size_columns_;
153 index_down = i + y_big_incr;
154 index_down_right = i + x_big_incr;
157 for (
int x = 0; x < last_column; x += triangle_pixel_size_columns_,
158 i += triangle_pixel_size_columns_,
159 index_right += triangle_pixel_size_columns_,
160 index_down += triangle_pixel_size_columns_,
161 index_down_right += triangle_pixel_size_columns_)
163 if (isValidTriangle (i, index_down_right, index_right))
164 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down_right, index_right))
165 addTriangle (i, index_down_right, index_right, idx++, polygons);
167 if (isValidTriangle (i, index_down, index_down_right))
168 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_down_right))
169 addTriangle (i, index_down, index_down_right, idx++, polygons);
172 polygons.resize (idx);
176 template <
typename Po
intInT>
void
179 int last_column = input_->width - triangle_pixel_size_columns_;
180 int last_row = input_->height - triangle_pixel_size_rows_;
182 int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
183 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
184 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
186 polygons.resize (input_->width * input_->height * 2);
189 for (
int y = 0; y < last_row; y += triangle_pixel_size_rows_)
192 i = y * input_->width;
193 index_right = i + triangle_pixel_size_columns_;
194 index_down = i + y_big_incr;
195 index_down_right = i + x_big_incr;
198 for (
int x = 0; x < last_column; x += triangle_pixel_size_columns_,
199 i += triangle_pixel_size_columns_,
200 index_right += triangle_pixel_size_columns_,
201 index_down += triangle_pixel_size_columns_,
202 index_down_right += triangle_pixel_size_columns_)
204 if (isValidTriangle (i, index_down, index_right))
205 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_right))
206 addTriangle (i, index_down, index_right, idx++, polygons);
208 if (isValidTriangle (index_right, index_down, index_down_right))
209 if (store_shadowed_faces_ || !isShadowedTriangle (index_right, index_down, index_down_right))
210 addTriangle (index_right, index_down, index_down_right, idx++, polygons);
213 polygons.resize (idx);
217 template <
typename Po
intInT>
void
220 int last_column = input_->width - triangle_pixel_size_columns_;
221 int last_row = input_->height - triangle_pixel_size_rows_;
224 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
225 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
227 polygons.resize (input_->width * input_->height * 2);
230 for (
int y = 0; y < last_row; y += triangle_pixel_size_rows_)
233 int i = y * input_->width;
234 int index_right = i + triangle_pixel_size_columns_;
235 int index_down = i + y_big_incr;
236 int index_down_right = i + x_big_incr;
239 for (
int x = 0; x < last_column; x += triangle_pixel_size_columns_,
240 i += triangle_pixel_size_columns_,
241 index_right += triangle_pixel_size_columns_,
242 index_down += triangle_pixel_size_columns_,
243 index_down_right += triangle_pixel_size_columns_)
245 const bool right_cut_upper = isValidTriangle (i, index_down_right, index_right);
246 const bool right_cut_lower = isValidTriangle (i, index_down, index_down_right);
247 const bool left_cut_upper = isValidTriangle (i, index_down, index_right);
248 const bool left_cut_lower = isValidTriangle (index_right, index_down, index_down_right);
250 if (right_cut_upper && right_cut_lower && left_cut_upper && left_cut_lower)
252 float dist_right_cut = std::abs ((*input_)[index_down].z - (*input_)[index_right].z);
253 float dist_left_cut = std::abs ((*input_)[i].z - (*input_)[index_down_right].z);
254 if (dist_right_cut >= dist_left_cut)
256 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down_right, index_right))
257 addTriangle (i, index_down_right, index_right, idx++, polygons);
258 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_down_right))
259 addTriangle (i, index_down, index_down_right, idx++, polygons);
263 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_right))
264 addTriangle (i, index_down, index_right, idx++, polygons);
265 if (store_shadowed_faces_ || !isShadowedTriangle (index_right, index_down, index_down_right))
266 addTriangle (index_right, index_down, index_down_right, idx++, polygons);
272 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down_right, index_right))
273 addTriangle (i, index_down_right, index_right, idx++, polygons);
275 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_down_right))
276 addTriangle (i, index_down, index_down_right, idx++, polygons);
278 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_right))
279 addTriangle (i, index_down, index_right, idx++, polygons);
281 if (store_shadowed_faces_ || !isShadowedTriangle (index_right, index_down, index_down_right))
282 addTriangle (index_right, index_down, index_down_right, idx++, polygons);
286 polygons.resize (idx);
289 #define PCL_INSTANTIATE_OrganizedFastMesh(T) \
290 template class PCL_EXPORTS pcl::OrganizedFastMesh<T>;
void makeRightCutMesh(std::vector< pcl::Vertices > &polygons)
Create a right cut mesh.
void makeQuadMesh(std::vector< pcl::Vertices > &polygons)
Create a quad mesh.
void reconstructPolygons(std::vector< pcl::Vertices > &polygons)
Perform the actual polygonal reconstruction.
void performReconstruction(std::vector< pcl::Vertices > &polygons) override
Create the surface.
void makeAdaptiveCutMesh(std::vector< pcl::Vertices > &polygons)
Create an adaptive cut mesh.
void makeLeftCutMesh(std::vector< pcl::Vertices > &polygons)
Create a left cut mesh.
int getFieldIndex(const pcl::PointCloud< PointT > &, const std::string &field_name, std::vector< pcl::PCLPointField > &fields)
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
std::vector< ::pcl::Vertices > polygons
::pcl::PCLPointCloud2 cloud