Point Cloud Library (PCL)
1.7.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 * Copyright (c) 2012-, Open Perception, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * * Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * * Redistributions in binary form must reproduce the above 00017 * copyright notice, this list of conditions and the following 00018 * disclaimer in the documentation and/or other materials provided 00019 * with the distribution. 00020 * * Neither the name of the copyright holder(s) nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00026 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00027 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00028 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00030 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00034 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 * $Id$ 00038 * 00039 */ 00040 00041 #ifndef PCL_FEATURES_IMPL_PRINCIPAL_CURVATURES_H_ 00042 #define PCL_FEATURES_IMPL_PRINCIPAL_CURVATURES_H_ 00043 00044 #include <pcl/features/principal_curvatures.h> 00045 00046 ////////////////////////////////////////////////////////////////////////////////////////////// 00047 template <typename PointInT, typename PointNT, typename PointOutT> void 00048 pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::computePointPrincipalCurvatures ( 00049 const pcl::PointCloud<PointNT> &normals, int p_idx, const std::vector<int> &indices, 00050 float &pcx, float &pcy, float &pcz, float &pc1, float &pc2) 00051 { 00052 EIGEN_ALIGN16 Eigen::Matrix3f I = Eigen::Matrix3f::Identity (); 00053 Eigen::Vector3f n_idx (normals.points[p_idx].normal[0], normals.points[p_idx].normal[1], normals.points[p_idx].normal[2]); 00054 EIGEN_ALIGN16 Eigen::Matrix3f M = I - n_idx * n_idx.transpose (); // projection matrix (into tangent plane) 00055 00056 // Project normals into the tangent plane 00057 Eigen::Vector3f normal; 00058 projected_normals_.resize (indices.size ()); 00059 xyz_centroid_.setZero (); 00060 for (size_t idx = 0; idx < indices.size(); ++idx) 00061 { 00062 normal[0] = normals.points[indices[idx]].normal[0]; 00063 normal[1] = normals.points[indices[idx]].normal[1]; 00064 normal[2] = normals.points[indices[idx]].normal[2]; 00065 00066 projected_normals_[idx] = M * normal; 00067 xyz_centroid_ += projected_normals_[idx]; 00068 } 00069 00070 // Estimate the XYZ centroid 00071 xyz_centroid_ /= static_cast<float> (indices.size ()); 00072 00073 // Initialize to 0 00074 covariance_matrix_.setZero (); 00075 00076 double demean_xy, demean_xz, demean_yz; 00077 // For each point in the cloud 00078 for (size_t idx = 0; idx < indices.size (); ++idx) 00079 { 00080 demean_ = projected_normals_[idx] - xyz_centroid_; 00081 00082 demean_xy = demean_[0] * demean_[1]; 00083 demean_xz = demean_[0] * demean_[2]; 00084 demean_yz = demean_[1] * demean_[2]; 00085 00086 covariance_matrix_(0, 0) += demean_[0] * demean_[0]; 00087 covariance_matrix_(0, 1) += static_cast<float> (demean_xy); 00088 covariance_matrix_(0, 2) += static_cast<float> (demean_xz); 00089 00090 covariance_matrix_(1, 0) += static_cast<float> (demean_xy); 00091 covariance_matrix_(1, 1) += demean_[1] * demean_[1]; 00092 covariance_matrix_(1, 2) += static_cast<float> (demean_yz); 00093 00094 covariance_matrix_(2, 0) += static_cast<float> (demean_xz); 00095 covariance_matrix_(2, 1) += static_cast<float> (demean_yz); 00096 covariance_matrix_(2, 2) += demean_[2] * demean_[2]; 00097 } 00098 00099 // Extract the eigenvalues and eigenvectors 00100 pcl::eigen33 (covariance_matrix_, eigenvalues_); 00101 pcl::computeCorrespondingEigenVector (covariance_matrix_, eigenvalues_ [2], eigenvector_); 00102 00103 pcx = eigenvector_ [0]; 00104 pcy = eigenvector_ [1]; 00105 pcz = eigenvector_ [2]; 00106 float indices_size = 1.0f / static_cast<float> (indices.size ()); 00107 pc1 = eigenvalues_ [2] * indices_size; 00108 pc2 = eigenvalues_ [1] * indices_size; 00109 } 00110 00111 00112 ////////////////////////////////////////////////////////////////////////////////////////////// 00113 template <typename PointInT, typename PointNT, typename PointOutT> void 00114 pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output) 00115 { 00116 // Allocate enough space to hold the results 00117 // \note This resize is irrelevant for a radiusSearch (). 00118 std::vector<int> nn_indices (k_); 00119 std::vector<float> nn_dists (k_); 00120 00121 output.is_dense = true; 00122 // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense 00123 if (input_->is_dense) 00124 { 00125 // Iterating over the entire index vector 00126 for (size_t idx = 0; idx < indices_->size (); ++idx) 00127 { 00128 if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0) 00129 { 00130 output.points[idx].principal_curvature[0] = output.points[idx].principal_curvature[1] = output.points[idx].principal_curvature[2] = 00131 output.points[idx].pc1 = output.points[idx].pc2 = std::numeric_limits<float>::quiet_NaN (); 00132 output.is_dense = false; 00133 continue; 00134 } 00135 00136 // Estimate the principal curvatures at each patch 00137 computePointPrincipalCurvatures (*normals_, (*indices_)[idx], nn_indices, 00138 output.points[idx].principal_curvature[0], output.points[idx].principal_curvature[1], output.points[idx].principal_curvature[2], 00139 output.points[idx].pc1, output.points[idx].pc2); 00140 } 00141 } 00142 else 00143 { 00144 // Iterating over the entire index vector 00145 for (size_t idx = 0; idx < indices_->size (); ++idx) 00146 { 00147 if (!isFinite ((*input_)[(*indices_)[idx]]) || 00148 this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0) 00149 { 00150 output.points[idx].principal_curvature[0] = output.points[idx].principal_curvature[1] = output.points[idx].principal_curvature[2] = 00151 output.points[idx].pc1 = output.points[idx].pc2 = std::numeric_limits<float>::quiet_NaN (); 00152 output.is_dense = false; 00153 continue; 00154 } 00155 00156 // Estimate the principal curvatures at each patch 00157 computePointPrincipalCurvatures (*normals_, (*indices_)[idx], nn_indices, 00158 output.points[idx].principal_curvature[0], output.points[idx].principal_curvature[1], output.points[idx].principal_curvature[2], 00159 output.points[idx].pc1, output.points[idx].pc2); 00160 } 00161 } 00162 } 00163 00164 #define PCL_INSTANTIATE_PrincipalCurvaturesEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PrincipalCurvaturesEstimation<T,NT,OutT>; 00165 00166 #endif // PCL_FEATURES_IMPL_PRINCIPAL_CURVATURES_H_