40 #ifndef PCL_FEATURES_IMPL_SHOT_LRF_H_
41 #define PCL_FEATURES_IMPL_SHOT_LRF_H_
43 #include <Eigen/Eigenvalues>
45 #include <pcl/features/shot_lrf.h>
49 template<
typename Po
intInT,
typename Po
intOutT>
float
52 const Eigen::Vector4f& central_point = (*input_)[current_point_idx].getVector4fMap ();
54 std::vector<float> n_sqr_distances;
56 this->searchForNeighbors (current_point_idx, search_parameter_, n_indices, n_sqr_distances);
58 Eigen::Matrix<double, Eigen::Dynamic, 4> vij (n_indices.size (), 4);
60 Eigen::Matrix3d cov_m = Eigen::Matrix3d::Zero ();
65 int valid_nn_points = 0;
67 for (std::size_t i_idx = 0; i_idx < n_indices.size (); ++i_idx)
69 Eigen::Vector4f pt = (*surface_)[n_indices[i_idx]].getVector4fMap ();
70 if (pt.head<3> () == central_point.head<3> ())
74 vij.row (valid_nn_points).matrix () = (pt - central_point).cast<double> ();
75 vij (valid_nn_points, 3) = 0;
77 distance = search_parameter_ - sqrt (n_sqr_distances[i_idx]);
80 cov_m +=
distance * (vij.row (valid_nn_points).head<3> ().transpose () * vij.row (valid_nn_points).head<3> ());
86 if (valid_nn_points < 5)
89 rf.setConstant (std::numeric_limits<float>::quiet_NaN ());
91 return (std::numeric_limits<float>::max ());
96 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> solver (cov_m);
98 const double& e1c = solver.eigenvalues ()[0];
99 const double& e2c = solver.eigenvalues ()[1];
100 const double& e3c = solver.eigenvalues ()[2];
102 if (!std::isfinite (e1c) || !std::isfinite (e2c) || !std::isfinite (e3c))
105 rf.setConstant (std::numeric_limits<float>::quiet_NaN ());
107 return (std::numeric_limits<float>::max ());
111 Eigen::Vector4d v1 = Eigen::Vector4d::Zero ();
112 Eigen::Vector4d v3 = Eigen::Vector4d::Zero ();
113 v1.head<3> ().matrix () = solver.eigenvectors ().col (2);
114 v3.head<3> ().matrix () = solver.eigenvectors ().col (0);
116 int plusNormal = 0, plusTangentDirection1=0;
117 for (
int ne = 0; ne < valid_nn_points; ne++)
119 double dp = vij.row (ne).dot (v1);
121 plusTangentDirection1++;
123 dp = vij.row (ne).dot (v3);
129 plusTangentDirection1 = 2*plusTangentDirection1 - valid_nn_points;
130 if (plusTangentDirection1 == 0)
133 int medianIndex = valid_nn_points/2;
135 for (
int i = -points/2; i <= points/2; i++)
136 if ( vij.row (medianIndex - i).dot (v1) > 0)
137 plusTangentDirection1 ++;
139 if (plusTangentDirection1 < points/2+1)
142 else if (plusTangentDirection1 < 0)
146 plusNormal = 2*plusNormal - valid_nn_points;
150 int medianIndex = valid_nn_points/2;
152 for (
int i = -points/2; i <= points/2; i++)
153 if ( vij.row (medianIndex - i).dot (v3) > 0)
156 if (plusNormal < points/2+1)
158 }
else if (plusNormal < 0)
161 rf.row (0).matrix () = v1.head<3> ().cast<float> ();
162 rf.row (2).matrix () = v3.head<3> ().cast<float> ();
163 rf.row (1).matrix () = rf.row (2).cross (rf.row (0));
169 template <
typename Po
intInT,
typename Po
intOutT>
void
173 if (this->getKSearch () != 0)
176 "[pcl::%s::computeFeature] Error! Search method set to k-neighborhood. Call setKSearch(0) and setRadiusSearch( radius ) to use this class.\n",
177 getClassName().c_str ());
180 tree_->setSortedResults (
true);
182 for (std::size_t i = 0; i < indices_->size (); ++i)
186 PointOutT& output_rf = output[i];
190 if (getLocalRF ((*indices_)[i], rf) == std::numeric_limits<float>::max ())
192 output.is_dense =
false;
195 for (
int d = 0; d < 3; ++d)
197 output_rf.x_axis[d] = rf.row (0)[d];
198 output_rf.y_axis[d] = rf.row (1)[d];
199 output_rf.z_axis[d] = rf.row (2)[d];
204 #define PCL_INSTANTIATE_SHOTLocalReferenceFrameEstimation(T,OutT) template class PCL_EXPORTS pcl::SHOTLocalReferenceFrameEstimation<T,OutT>;
void computeFeature(PointCloudOut &output) override
Feature estimation method.
float getLocalRF(const int &index, Eigen::Matrix3f &rf)
Computes disambiguated local RF for a point index.
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
float distance(const PointT &p1, const PointT &p2)
IndicesAllocator<> Indices
Type used for indices in PCL.