00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef PCL_SURFACE_ORGANIZED_FAST_MESH_HPP_
00042 #define PCL_SURFACE_ORGANIZED_FAST_MESH_HPP_
00043
00044 #include <pcl18/surface/organized_fast_mesh.h>
00045 #include <rtabmap/utilite/ULogger.h>
00046
00048 template <typename PointInT> void
00049 pcl::OrganizedFastMesh<PointInT>::performReconstruction (pcl::PolygonMesh &output)
00050 {
00051 reconstructPolygons (output.polygons);
00052
00053
00054 int x_idx = pcl::getFieldIndex (output.cloud, "x");
00055 int y_idx = pcl::getFieldIndex (output.cloud, "y");
00056 int z_idx = pcl::getFieldIndex (output.cloud, "z");
00057 if (x_idx == -1 || y_idx == -1 || z_idx == -1)
00058 return;
00059
00060
00061
00062
00063 for (unsigned int i = 0; i < input_->points.size (); ++i)
00064 if (!isFinite (input_->points[i]))
00065 resetPointData (i, output, 0.0f, x_idx, y_idx, z_idx);
00066 }
00067
00069 template <typename PointInT> void
00070 pcl::OrganizedFastMesh<PointInT>::performReconstruction (std::vector<pcl::Vertices> &polygons)
00071 {
00072 reconstructPolygons (polygons);
00073 }
00074
00076 template <typename PointInT> void
00077 pcl::OrganizedFastMesh<PointInT>::reconstructPolygons (std::vector<pcl::Vertices> &polygons)
00078 {
00079 if (triangulation_type_ == TRIANGLE_RIGHT_CUT)
00080 makeRightCutMesh (polygons);
00081 else if (triangulation_type_ == TRIANGLE_LEFT_CUT)
00082 makeLeftCutMesh (polygons);
00083 else if (triangulation_type_ == TRIANGLE_ADAPTIVE_CUT)
00084 makeAdaptiveCutMesh (polygons);
00085 else if (triangulation_type_ == QUAD_MESH)
00086 makeQuadMesh (polygons);
00087 }
00088
00090 template <typename PointInT> void
00091 pcl::OrganizedFastMesh<PointInT>::makeQuadMesh (std::vector<pcl::Vertices>& polygons)
00092 {
00093 int last_column = input_->width - triangle_pixel_size_columns_;
00094 int last_row = input_->height - triangle_pixel_size_rows_;
00095
00096 int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
00097 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
00098 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
00099
00100 polygons.resize (input_->width * input_->height);
00101
00102
00103 for (int y = 0; y < last_row; y += triangle_pixel_size_rows_)
00104 {
00105
00106 i = y * input_->width;
00107 index_right = i + triangle_pixel_size_columns_;
00108 index_down = i + y_big_incr;
00109 index_down_right = i + x_big_incr;
00110
00111
00112 for (int x = 0; x < last_column; x += triangle_pixel_size_columns_,
00113 i += triangle_pixel_size_columns_,
00114 index_right += triangle_pixel_size_columns_,
00115 index_down += triangle_pixel_size_columns_,
00116 index_down_right += triangle_pixel_size_columns_)
00117 {
00118 if (isValidQuad (i, index_right, index_down_right, index_down))
00119 if (store_shadowed_faces_ || !isShadowedQuad (i, index_right, index_down_right, index_down))
00120 addQuad (i, index_right, index_down_right, index_down, idx++, polygons);
00121 }
00122 }
00123 polygons.resize (idx);
00124 }
00125
00127 template <typename PointInT> void
00128 pcl::OrganizedFastMesh<PointInT>::makeRightCutMesh (std::vector<pcl::Vertices>& polygons)
00129 {
00130 int last_column = input_->width - triangle_pixel_size_columns_;
00131 int last_row = input_->height - triangle_pixel_size_rows_;
00132
00133 int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
00134 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
00135 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
00136
00137 polygons.resize (input_->width * input_->height * 2);
00138
00139
00140 for (int y = 0; y < last_row; y += triangle_pixel_size_rows_)
00141 {
00142
00143 i = y * input_->width;
00144 index_right = i + triangle_pixel_size_columns_;
00145 index_down = i + y_big_incr;
00146 index_down_right = i + x_big_incr;
00147
00148
00149 for (int x = 0; x < last_column; x += triangle_pixel_size_columns_,
00150 i += triangle_pixel_size_columns_,
00151 index_right += triangle_pixel_size_columns_,
00152 index_down += triangle_pixel_size_columns_,
00153 index_down_right += triangle_pixel_size_columns_)
00154 {
00155 if (isValidTriangle (i, index_down_right, index_right))
00156 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down_right, index_right))
00157 addTriangle (i, index_down_right, index_right, idx++, polygons);
00158
00159 if (isValidTriangle (i, index_down, index_down_right))
00160 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_down_right))
00161 addTriangle (i, index_down, index_down_right, idx++, polygons);
00162 }
00163 }
00164 polygons.resize (idx);
00165 }
00166
00168 template <typename PointInT> void
00169 pcl::OrganizedFastMesh<PointInT>::makeLeftCutMesh (std::vector<pcl::Vertices>& polygons)
00170 {
00171 int last_column = input_->width - triangle_pixel_size_columns_;
00172 int last_row = input_->height - triangle_pixel_size_rows_;
00173
00174 int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
00175 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
00176 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
00177
00178 polygons.resize (input_->width * input_->height * 2);
00179
00180
00181 for (int y = 0; y < last_row; y += triangle_pixel_size_rows_)
00182 {
00183
00184 i = y * input_->width;
00185 index_right = i + triangle_pixel_size_columns_;
00186 index_down = i + y_big_incr;
00187 index_down_right = i + x_big_incr;
00188
00189
00190 for (int x = 0; x < last_column; x += triangle_pixel_size_columns_,
00191 i += triangle_pixel_size_columns_,
00192 index_right += triangle_pixel_size_columns_,
00193 index_down += triangle_pixel_size_columns_,
00194 index_down_right += triangle_pixel_size_columns_)
00195 {
00196 if (isValidTriangle (i, index_down, index_right))
00197 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_right))
00198 addTriangle (i, index_down, index_right, idx++, polygons);
00199
00200 if (isValidTriangle (index_right, index_down, index_down_right))
00201 if (store_shadowed_faces_ || !isShadowedTriangle (index_right, index_down, index_down_right))
00202 addTriangle (index_right, index_down, index_down_right, idx++, polygons);
00203 }
00204 }
00205 polygons.resize (idx);
00206 }
00207
00209 template <typename PointInT> void
00210 pcl::OrganizedFastMesh<PointInT>::makeAdaptiveCutMesh (std::vector<pcl::Vertices>& polygons)
00211 {
00212 int last_column = input_->width - triangle_pixel_size_columns_;
00213 int last_row = input_->height - triangle_pixel_size_rows_;
00214
00215 int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
00216 int y_big_incr = triangle_pixel_size_rows_ * input_->width,
00217 x_big_incr = y_big_incr + triangle_pixel_size_columns_;
00218
00219 polygons.resize (input_->width * input_->height * 2);
00220
00221
00222 for (int y = 0; y < last_row; y += triangle_pixel_size_rows_)
00223 {
00224
00225 i = y * input_->width;
00226 index_right = i + triangle_pixel_size_columns_;
00227 index_down = i + y_big_incr;
00228 index_down_right = i + x_big_incr;
00229
00230
00231 for (int x = 0; x < last_column; x += triangle_pixel_size_columns_,
00232 i += triangle_pixel_size_columns_,
00233 index_right += triangle_pixel_size_columns_,
00234 index_down += triangle_pixel_size_columns_,
00235 index_down_right += triangle_pixel_size_columns_)
00236 {
00237 const bool right_cut_upper = isValidTriangle (i, index_down_right, index_right);
00238 const bool right_cut_lower = isValidTriangle (i, index_down, index_down_right);
00239 const bool left_cut_upper = isValidTriangle (i, index_down, index_right);
00240 const bool left_cut_lower = isValidTriangle (index_right, index_down, index_down_right);
00241
00242 if (right_cut_upper && right_cut_lower && left_cut_upper && left_cut_lower)
00243 {
00244 float dist_right_cut = fabsf (input_->points[index_down].z - input_->points[index_right].z);
00245 float dist_left_cut = fabsf (input_->points[i].z - input_->points[index_down_right].z);
00246 if (dist_right_cut >= dist_left_cut)
00247 {
00248 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down_right, index_right))
00249 addTriangle (i, index_down_right, index_right, idx++, polygons);
00250 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_down_right))
00251 addTriangle (i, index_down, index_down_right, idx++, polygons);
00252 }
00253 else
00254 {
00255 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_right))
00256 addTriangle (i, index_down, index_right, idx++, polygons);
00257 if (store_shadowed_faces_ || !isShadowedTriangle (index_right, index_down, index_down_right))
00258 addTriangle (index_right, index_down, index_down_right, idx++, polygons);
00259 }
00260 }
00261 else
00262 {
00263 if (right_cut_upper)
00264 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down_right, index_right))
00265 addTriangle (i, index_down_right, index_right, idx++, polygons);
00266 if (right_cut_lower)
00267 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_down_right))
00268 addTriangle (i, index_down, index_down_right, idx++, polygons);
00269 if (left_cut_upper)
00270 if (store_shadowed_faces_ || !isShadowedTriangle (i, index_down, index_right))
00271 addTriangle (i, index_down, index_right, idx++, polygons);
00272 if (left_cut_lower)
00273 if (store_shadowed_faces_ || !isShadowedTriangle (index_right, index_down, index_down_right))
00274 addTriangle (index_right, index_down, index_down_right, idx++, polygons);
00275 }
00276 }
00277 }
00278 polygons.resize (idx);
00279 }
00280
00281 #define PCL_INSTANTIATE_OrganizedFastMesh(T) \
00282 template class PCL_EXPORTS pcl::OrganizedFastMesh<T>;
00283
00284 #endif // PCL_SURFACE_ORGANIZED_FAST_MESH_HPP_