Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id: intensity_gradient.hpp 1667 2011-07-10 22:44:00Z rusu $ 00035 * 00036 */ 00037 00038 #ifndef PCL_FEATURES_IMPL_INTENSITY_GRADIENT_H_ 00039 #define PCL_FEATURES_IMPL_INTENSITY_GRADIENT_H_ 00040 00041 #include "pcl/features/intensity_gradient.h" 00042 00044 template <typename PointInT, typename PointNT, typename PointOutT> void 00045 pcl::IntensityGradientEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output) 00046 { 00047 // Allocate enough space to hold the results 00048 // \note This resize is irrelevant for a radiusSearch (). 00049 std::vector<int> nn_indices (k_); 00050 std::vector<float> nn_dists (k_); 00051 00052 // Iterating over the entire index vector 00053 for (size_t idx = 0; idx < indices_->size (); ++idx) 00054 { 00055 PointOutT &p_out = output.points[idx]; 00056 00057 if (!this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists)) 00058 { 00059 p_out.gradient[0] = p_out.gradient[1] = p_out.gradient[2] = std::numeric_limits<float>::quiet_NaN (); 00060 continue; 00061 } 00062 00063 Eigen::Vector4f centroid; 00064 compute3DCentroid (*surface_, nn_indices, centroid); 00065 00066 Eigen::Vector3f normal = Eigen::Vector3f::Map (normals_->points[idx].normal); 00067 Eigen::Vector3f gradient; 00068 computePointIntensityGradient (*surface_, nn_indices, centroid.head<3> (), normal, gradient); 00069 00070 p_out.gradient[0] = gradient[0]; 00071 p_out.gradient[1] = gradient[1]; 00072 p_out.gradient[2] = gradient[2]; 00073 00074 } 00075 } 00076 00078 template <typename PointInT, typename PointNT, typename PointOutT> void 00079 pcl::IntensityGradientEstimation <PointInT, PointNT, PointOutT>::computePointIntensityGradient ( 00080 const pcl::PointCloud <PointInT> &cloud, const std::vector <int> &indices, 00081 const Eigen::Vector3f &point, const Eigen::Vector3f &normal, Eigen::Vector3f &gradient) 00082 { 00083 if (indices.size () < 3) 00084 { 00085 gradient[0] = gradient[1] = gradient[2] = std::numeric_limits<float>::quiet_NaN (); 00086 return; 00087 } 00088 00089 Eigen::Matrix3f A = Eigen::Matrix3f::Zero (); 00090 Eigen::Vector3f b = Eigen::Vector3f::Zero (); 00091 00092 for (size_t i_point = 0; i_point < indices.size (); ++i_point) 00093 { 00094 PointInT p = cloud.points[indices[i_point]]; 00095 if (!pcl_isfinite (p.x) || 00096 !pcl_isfinite (p.y) || 00097 !pcl_isfinite (p.z) || 00098 !pcl_isfinite (p.intensity)) 00099 continue; 00100 00101 p.x -= point[0]; 00102 p.y -= point[1]; 00103 p.z -= point[2]; 00104 00105 A (0, 0) += p.x*p.x; 00106 A (0, 1) += p.x*p.y; 00107 A (0, 2) += p.x*p.z; 00108 00109 A (1, 1) += p.y*p.y; 00110 A (1, 2) += p.y*p.z; 00111 00112 A (2, 2) += p.z*p.z; 00113 00114 b[0] += p.x * p.intensity; 00115 b[1] += p.y * p.intensity; 00116 b[2] += p.z * p.intensity; 00117 } 00118 // Fill in the lower triangle of A 00119 A (1, 0) = A (0, 1); 00120 A (2, 0) = A (0, 2); 00121 A (2, 1) = A (1, 2); 00122 00123 // Fit a hyperplane to the data 00124 Eigen::Vector3f x = A.colPivHouseholderQr ().solve (b); 00125 00126 // Project the gradient vector, x, onto the tangent plane 00127 gradient = (Eigen::Matrix3f::Identity () - normal*normal.transpose ()) * x; 00128 } 00129 00130 00131 #define PCL_INSTANTIATE_IntensityGradientEstimation(InT,NT,OutT) template class PCL_EXPORTS pcl::IntensityGradientEstimation<InT,NT,OutT>; 00132 00133 #endif // PCL_FEATURES_IMPL_INTENSITY_GRADIENT_H_