normal_3d.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.hpp 5026 2012-03-12 02:51:44Z rusu $
00037  *
00038  */
00039 
00040 #ifndef PCL_FEATURES_IMPL_NORMAL_3D_H_
00041 #define PCL_FEATURES_IMPL_NORMAL_3D_H_
00042 
00043 #include <pcl/features/normal_3d.h>
00044 
00046 template <typename PointInT, typename PointOutT> void
00047 pcl::NormalEstimation<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
00048 {
00049   // Allocate enough space to hold the results
00050   // \note This resize is irrelevant for a radiusSearch ().
00051   std::vector<int> nn_indices (k_);
00052   std::vector<float> nn_dists (k_);
00053 
00054   output.is_dense = true;
00055   // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
00056   if (input_->is_dense)
00057   {
00058     // Iterating over the entire index vector
00059     for (size_t idx = 0; idx < indices_->size (); ++idx)
00060     {
00061       if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00062       {
00063         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 ();
00064 
00065         output.is_dense = false;
00066         continue;
00067       }
00068 
00069       computePointNormal (*surface_, nn_indices,
00070                           output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2], output.points[idx].curvature);
00071 
00072       flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
00073                                   output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2]);
00074 
00075     }
00076   }
00077   else
00078   {
00079     // Iterating over the entire index vector
00080     for (size_t idx = 0; idx < indices_->size (); ++idx)
00081     {
00082       if (!isFinite ((*input_)[(*indices_)[idx]]) ||
00083           this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00084       {
00085         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 ();
00086 
00087         output.is_dense = false;
00088         continue;
00089       }
00090 
00091       computePointNormal (*surface_, nn_indices,
00092                           output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2], output.points[idx].curvature);
00093 
00094       flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
00095                                   output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2]);
00096 
00097     }
00098   }
00099 }
00100 
00102 template <typename PointInT> void
00103 pcl::NormalEstimation<PointInT, Eigen::MatrixXf>::computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output)
00104 {
00105   // Resize the output dataset
00106   output.points.resize (indices_->size (), 4);
00107 
00108   // Allocate enough space to hold the results
00109   // \note This resize is irrelevant for a radiusSearch ().
00110   std::vector<int> nn_indices (k_);
00111   std::vector<float> nn_dists (k_);
00112 
00113   output.is_dense = true;
00114   // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
00115   if (input_->is_dense)
00116   {
00117     // Iterating over the entire index vector
00118     for (size_t idx = 0; idx < indices_->size (); ++idx)
00119     {
00120       if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00121       {
00122         output.points (idx, 0) = output.points (idx, 1) = output.points (idx, 2) = output.points (idx, 3) = std::numeric_limits<float>::quiet_NaN ();
00123         output.is_dense = false;
00124         continue;
00125       }
00126 
00127       computePointNormal (*surface_, nn_indices,
00128                           output.points (idx, 0), output.points (idx, 1), output.points (idx, 2), output.points (idx, 3));
00129 
00130       flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
00131                                   output.points (idx, 0), output.points (idx, 1), output.points (idx, 2));
00132 
00133     }
00134   }
00135   else
00136   {
00137     // Iterating over the entire index vector
00138     for (size_t idx = 0; idx < indices_->size (); ++idx)
00139     {
00140       if (!isFinite ((*input_)[(*indices_)[idx]]) ||
00141           this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00142       {
00143         output.points (idx, 0) = output.points (idx, 1) = output.points (idx, 2) = output.points (idx, 3) = std::numeric_limits<float>::quiet_NaN ();
00144         output.is_dense = false;
00145         continue;
00146       }
00147 
00148       computePointNormal (*surface_, nn_indices,
00149                           output.points (idx, 0), output.points (idx, 1), output.points (idx, 2), output.points (idx, 3));
00150 
00151       flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
00152                                   output.points (idx, 0), output.points (idx, 1), output.points (idx, 2));
00153 
00154     }
00155   }
00156 }
00157 
00158 #define PCL_INSTANTIATE_NormalEstimation(T,NT) template class PCL_EXPORTS pcl::NormalEstimation<T,NT>;
00159 
00160 #endif    // PCL_FEATURES_IMPL_NORMAL_3D_H_ 


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