00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
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 ();
00055
00056
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
00071 xyz_centroid_ /= static_cast<float> (indices.size ());
00072
00073
00074 covariance_matrix_.setZero ();
00075
00076 double demean_xy, demean_xz, demean_yz;
00077
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
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
00113 template <typename PointInT, typename PointNT, typename PointOutT> void
00114 pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output)
00115 {
00116
00117
00118 std::vector<int> nn_indices (k_);
00119 std::vector<float> nn_dists (k_);
00120
00121 output.is_dense = true;
00122
00123 if (input_->is_dense)
00124 {
00125
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
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
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
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_