normal_3d_omp.hpp
Go to the documentation of this file.
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: normal_3d_omp.hpp 5026 2012-03-12 02:51:44Z rusu $
00037  *
00038  */
00039 
00040 #ifndef PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
00041 #define PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
00042 
00043 #include <pcl/features/normal_3d_omp.h>
00044 
00046 template <typename PointInT> void
00047 pcl::NormalEstimationOMP<PointInT, Eigen::MatrixXf>::computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output)
00048 {
00049   float vpx, vpy, vpz;
00050   getViewPoint (vpx, vpy, vpz);
00051   output.is_dense = true;
00052 
00053   // Resize the output dataset
00054   output.points.resize (indices_->size (), 4);
00055 
00056   // GCC 4.2.x seems to segfault with "internal compiler error" on MacOS X here
00057 #if defined(_WIN32) || ((__GNUC__ > 4) && (__GNUC_MINOR__ > 2)) 
00058 #pragma omp parallel for schedule (dynamic, threads_)
00059 #endif
00060   // Iterating over the entire index vector
00061   for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
00062   {
00063     // Allocate enough space to hold the results
00064     // \note This resize is irrelevant for a radiusSearch ().
00065     std::vector<int> nn_indices (k_);
00066     std::vector<float> nn_dists (k_);
00067 
00068     if (!isFinite ((*input_)[(*indices_)[idx]]) ||
00069         this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00070     {
00071       output.points (idx, 0) = output.points (idx, 1) = output.points (idx, 2) = output.points (idx, 3) = std::numeric_limits<float>::quiet_NaN ();
00072       output.is_dense = false;
00073       continue;
00074     }
00075 
00076     // 16-bytes aligned placeholder for the XYZ centroid of a surface patch
00077     Eigen::Vector4f xyz_centroid;
00078     // Estimate the XYZ centroid
00079     compute3DCentroid (*surface_, nn_indices, xyz_centroid);
00080 
00081     // Placeholder for the 3x3 covariance matrix at each surface patch
00082     EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
00083     // Compute the 3x3 covariance matrix
00084     computeCovarianceMatrix (*surface_, nn_indices, xyz_centroid, covariance_matrix);
00085 
00086     // Get the plane normal and surface curvature
00087     solvePlaneParameters (covariance_matrix,
00088                           output.points (idx, 0), output.points (idx, 1), output.points (idx, 2), output.points (idx, 3));
00089 
00090     flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx, vpy, vpz,
00091                                 output.points (idx, 0), output.points (idx, 1), output.points (idx, 2));
00092   }
00093 }
00094 
00096 template <typename PointInT, typename PointOutT> void
00097 pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
00098 {
00099   float vpx, vpy, vpz;
00100   getViewPoint (vpx, vpy, vpz);
00101 
00102   output.is_dense = true;
00103   // Iterating over the entire index vector
00104 #pragma omp parallel for schedule (dynamic, threads_)
00105   for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
00106   {
00107     // Allocate enough space to hold the results
00108     // \note This resize is irrelevant for a radiusSearch ().
00109     std::vector<int> nn_indices (k_);
00110     std::vector<float> nn_dists (k_);
00111 
00112     if (!isFinite ((*input_)[(*indices_)[idx]]) ||
00113         this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00114     {
00115       output.points[idx].normal[0] = output.points[idx].normal[1] = output.points[idx].normal[2] = output.points[idx].curvature = std::numeric_limits<float>::quiet_NaN ();
00116   
00117       output.is_dense = false;
00118       continue;
00119     }
00120 
00121     // 16-bytes aligned placeholder for the XYZ centroid of a surface patch
00122     Eigen::Vector4f xyz_centroid;
00123     // Estimate the XYZ centroid
00124     compute3DCentroid (*surface_, nn_indices, xyz_centroid);
00125 
00126     // Placeholder for the 3x3 covariance matrix at each surface patch
00127     EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
00128     // Compute the 3x3 covariance matrix
00129     computeCovarianceMatrix (*surface_, nn_indices, xyz_centroid, covariance_matrix);
00130 
00131     // Get the plane normal and surface curvature
00132     solvePlaneParameters (covariance_matrix,
00133                           output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2], output.points[idx].curvature);
00134 
00135     flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx, vpy, vpz,
00136                                 output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2]);
00137   }
00138 }
00139 
00140 #define PCL_INSTANTIATE_NormalEstimationOMP(T,NT) template class PCL_EXPORTS pcl::NormalEstimationOMP<T,NT>;
00141 
00142 #endif    // PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
00143 


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:15:51