|
Point Cloud Library (PCL)
1.6.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: mls_omp.hpp 5835 2012-06-04 05:27:21Z holzers $ 00037 * 00038 */ 00039 00040 #ifndef PCL_SURFACE_IMPL_MLS_OMP_H_ 00041 #define PCL_SURFACE_IMPL_MLS_OMP_H_ 00042 00043 #include <cstddef> 00044 #include <pcl/surface/mls_omp.h> 00045 00047 template <typename PointInT, typename PointOutT> void 00048 pcl::MovingLeastSquaresOMP<PointInT, PointOutT>::performProcessing (PointCloudOut &output) 00049 { 00050 typedef std::size_t size_t; 00051 // Compute the number of coefficients 00052 nr_coeff_ = (order_ + 1) * (order_ + 2) / 2; 00053 00054 #pragma omp parallel for schedule (dynamic, threads_) 00055 // For all points 00056 for (int cp = 0; cp < static_cast<int> (indices_->size ()); ++cp) 00057 { 00058 // Allocate enough space to hold the results of nearest neighbor searches 00059 // \note resize is irrelevant for a radiusSearch (). 00060 std::vector<int> nn_indices; 00061 std::vector<float> nn_sqr_dists; 00062 00063 // Get the initial estimates of point positions and their neighborhoods 00064 if (!searchForNeighbors (cp, nn_indices, nn_sqr_dists)) 00065 continue; 00066 00067 00068 // Check the number of nearest neighbors for normal estimation (and later 00069 // for polynomial fit as well) 00070 if (nn_indices.size () < 3) 00071 continue; 00072 00073 00074 PointCloudOut projected_points; 00075 NormalCloud projected_points_normals; 00076 00077 // Get a plane approximating the local surface's tangent and project point onto it 00078 this->computeMLSPointNormal (cp, *input_, nn_indices, nn_sqr_dists, projected_points, projected_points_normals); 00079 00080 #pragma omp critical 00081 { 00082 // Append projected points to output 00083 output.insert (output.end (), projected_points.begin (), projected_points.end ()); 00084 if (compute_normals_) 00085 normals_->insert (normals_->end (), projected_points_normals.begin (), projected_points_normals.end ()); 00086 } 00087 } 00088 00089 00090 // For the voxel grid upsampling method, generate the voxel grid and dilate it 00091 // Then, project the newly obtained points to the MLS surface 00092 if (upsample_method_ == MovingLeastSquares<PointInT, PointOutT>::VOXEL_GRID_DILATION) 00093 { 00094 MLSVoxelGrid voxel_grid (input_, indices_, voxel_size_); 00095 00096 for (int iteration = 0; iteration < dilation_iteration_num_; ++iteration) 00097 voxel_grid.dilate (); 00098 00099 #if /*defined(_WIN32) ||*/ ((__GNUC__ > 4) && (__GNUC_MINOR__ > 2)) 00100 #pragma omp parallel for schedule (dynamic, threads_) 00101 #endif 00102 for (typename MLSVoxelGrid::HashMap::iterator h_it = voxel_grid.voxel_grid_.begin (); h_it != voxel_grid.voxel_grid_.end (); ++h_it) 00103 { 00104 typename MLSVoxelGrid::HashMap::value_type voxel = *h_it; 00105 00106 // Get 3D position of point 00107 Eigen::Vector3f pos; 00108 voxel_grid.getPosition (voxel.first, pos); 00109 00110 PointInT p; 00111 p.x = pos[0]; 00112 p.y = pos[1]; 00113 p.z = pos[2]; 00114 00115 std::vector<int> nn_indices; 00116 std::vector<float> nn_dists; 00117 tree_->nearestKSearch (p, 1, nn_indices, nn_dists); 00118 int input_index = nn_indices.front (); 00119 00120 // If the closest point did not have a valid MLS fitting result 00121 // OR if it is too far away from the sampled point 00122 if (mls_results_[input_index].valid == false) 00123 continue; 00124 00125 Eigen::Vector3f add_point = p.getVector3fMap (), 00126 input_point = input_->points[input_index].getVector3fMap (); 00127 00128 Eigen::Vector3d aux = mls_results_[input_index].u; 00129 Eigen::Vector3f u = aux.cast<float> (); 00130 aux = mls_results_[input_index].v; 00131 Eigen::Vector3f v = aux.cast<float> (); 00132 00133 float u_disp = (add_point - input_point).dot (u), 00134 v_disp = (add_point - input_point).dot (v); 00135 00136 PointOutT result_point; 00137 pcl::Normal result_normal; 00138 this->projectPointToMLSSurface (u_disp, v_disp, 00139 mls_results_[input_index].u, mls_results_[input_index].v, 00140 mls_results_[input_index].plane_normal, 00141 mls_results_[input_index].curvature, 00142 input_point, 00143 mls_results_[input_index].c_vec, 00144 mls_results_[input_index].num_neighbors, 00145 result_point, result_normal); 00146 00147 float d_before = (pos - input_point).norm (), 00148 d_after = (result_point.getVector3fMap () - input_point). norm(); 00149 if (d_after > d_before) 00150 continue; 00151 00152 #pragma critical 00153 { 00154 output.push_back (result_point); 00155 if (compute_normals_) 00156 normals_->push_back (result_normal); 00157 } 00158 } 00159 } 00160 } 00161 00162 #define PCL_INSTANTIATE_MovingLeastSquaresOMP(T,OutT) template class PCL_EXPORTS pcl::MovingLeastSquaresOMP<T,OutT>; 00163 00164 #endif // PCL_SURFACE_IMPL_MLS_OMP_H_ 00165
1.7.6.1