41 #include <pcl/features/pfh.h>
42 #include <pcl/features/pfh_tools.h>
44 #include <pcl/common/point_tests.h>
48 template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
bool
51 int p_idx,
int q_idx,
float &f1,
float &f2,
float &f3,
float &f4)
54 cloud[q_idx].getVector4fMap (), normals[q_idx].getNormalVector4fMap (),
60 template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
63 const pcl::Indices &indices,
int nr_split, Eigen::VectorXf &pfh_histogram)
68 pfh_histogram.setZero ();
71 float hist_incr = 100.0f /
static_cast<float> (indices.size () * (indices.size () - 1) / 2);
73 std::pair<int, int> key;
74 bool key_found =
false;
77 for (std::size_t i_idx = 0; i_idx < indices.size (); ++i_idx)
79 for (std::size_t j_idx = 0; j_idx < i_idx; ++j_idx)
99 key = std::pair<int, int> (p1, p2);
102 auto fm_it = feature_map_.find (key);
103 if (fm_it != feature_map_.end ())
105 pfh_tuple_ = fm_it->second;
112 pfh_tuple_[0], pfh_tuple_[1], pfh_tuple_[2], pfh_tuple_[3]))
120 pfh_tuple_[0], pfh_tuple_[1], pfh_tuple_[2], pfh_tuple_[3]))
124 f_index_[0] =
static_cast<int> (std::floor (nr_split * ((pfh_tuple_[0] +
M_PI) * d_pi_)));
125 if (f_index_[0] < 0) f_index_[0] = 0;
126 if (f_index_[0] >= nr_split) f_index_[0] = nr_split - 1;
128 f_index_[1] =
static_cast<int> (std::floor (nr_split * ((pfh_tuple_[1] + 1.0) * 0.5)));
129 if (f_index_[1] < 0) f_index_[1] = 0;
130 if (f_index_[1] >= nr_split) f_index_[1] = nr_split - 1;
132 f_index_[2] =
static_cast<int> (std::floor (nr_split * ((pfh_tuple_[2] + 1.0) * 0.5)));
133 if (f_index_[2] < 0) f_index_[2] = 0;
134 if (f_index_[2] >= nr_split) f_index_[2] = nr_split - 1;
139 for (
const int &d : f_index_)
144 pfh_histogram[h_index] += hist_incr;
146 if (use_cache_ && !key_found)
149 feature_map_[key] = pfh_tuple_;
152 key_list_.push (key);
154 if (key_list_.size () > max_cache_size_)
157 feature_map_.erase (key_list_.front ());
166 template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
170 feature_map_.clear ();
171 std::queue<std::pair<int, int> > empty;
172 std::swap (key_list_, empty);
174 pfh_histogram_.setZero (
static_cast<Eigen::Index
>(nr_subdiv_) * nr_subdiv_ * nr_subdiv_);
179 std::vector<float> nn_dists (k_);
183 if (input_->is_dense)
186 for (std::size_t idx = 0; idx < indices_->size (); ++idx)
188 if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
190 for (Eigen::Index d = 0; d < pfh_histogram_.size (); ++d)
191 output[idx].histogram[d] = std::numeric_limits<float>::quiet_NaN ();
198 computePointPFHSignature (*surface_, *normals_, nn_indices, nr_subdiv_, pfh_histogram_);
201 for (Eigen::Index d = 0; d < pfh_histogram_.size (); ++d)
202 output[idx].histogram[d] = pfh_histogram_[d];
208 for (std::size_t idx = 0; idx < indices_->size (); ++idx)
210 if (!
isFinite ((*input_)[(*indices_)[idx]]) ||
211 this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
213 for (Eigen::Index d = 0; d < pfh_histogram_.size (); ++d)
214 output[idx].histogram[d] = std::numeric_limits<float>::quiet_NaN ();
221 computePointPFHSignature (*surface_, *normals_, nn_indices, nr_subdiv_, pfh_histogram_);
224 for (Eigen::Index d = 0; d < pfh_histogram_.size (); ++d)
225 output[idx].histogram[d] = pfh_histogram_[d];
230 #define PCL_INSTANTIATE_PFHEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PFHEstimation<T,NT,OutT>;
void computePointPFHSignature(const pcl::PointCloud< PointInT > &cloud, const pcl::PointCloud< PointNT > &normals, const pcl::Indices &indices, int nr_split, Eigen::VectorXf &pfh_histogram)
Estimate the PFH (Point Feature Histograms) individual signatures of the three angular (f1,...
bool computePairFeatures(const pcl::PointCloud< PointInT > &cloud, const pcl::PointCloud< PointNT > &normals, int p_idx, int q_idx, float &f1, float &f2, float &f3, float &f4)
Compute the 4-tuple representation containing the three angles and one distance between two points re...
void computeFeature(PointCloudOut &output) override
Estimate the Point Feature Histograms (PFH) descriptors at a set of points given by <setInputCloud ()...
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
PCL_EXPORTS bool computePairFeatures(const Eigen::Vector4f &p1, const Eigen::Vector4f &n1, const Eigen::Vector4f &p2, const Eigen::Vector4f &n2, float &f1, float &f2, float &f3, float &f4)
Compute the 4-tuple representation containing the three angles and one distance between two points re...
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
IndicesAllocator<> Indices
Type used for indices in PCL.