41 #ifndef PCL_FEATURES_IMPL_VFH_H_
42 #define PCL_FEATURES_IMPL_VFH_H_
49 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
bool
52 if (input_->points.size () < 2 || (surface_ && surface_->points.size () < 2))
54 PCL_ERROR (
"[pcl::VFHEstimation::initCompute] Input dataset must have at least 2 points!\n");
57 if (search_radius_ == 0 && k_ == 0)
59 return (Feature<PointInT, PointOutT>::initCompute ());
63 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
73 output.
header = input_->header;
84 computeFeature (output);
90 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
92 const Eigen::Vector4f ¢roid_n,
95 const std::vector<int> &indices)
97 Eigen::Vector4f pfh_tuple;
99 hist_f1_.setZero (nr_bins_f1_);
100 hist_f2_.setZero (nr_bins_f2_);
101 hist_f3_.setZero (nr_bins_f3_);
102 hist_f4_.setZero (nr_bins_f4_);
113 double distance_normalization_factor = 1.0;
114 if (normalize_distances_)
116 Eigen::Vector4f max_pt;
119 distance_normalization_factor = (centroid_p - max_pt).norm ();
125 hist_incr = 100.0f /
static_cast<float> (indices.size () - 1);
129 float hist_incr_size_component;
131 hist_incr_size_component = hist_incr;
133 hist_incr_size_component = 0.0;
136 for (
size_t idx = 0; idx < indices.size (); ++idx)
140 normals.
points[indices[idx]].getNormalVector4fMap (), pfh_tuple[0], pfh_tuple[1],
141 pfh_tuple[2], pfh_tuple[3]))
145 int h_index =
static_cast<int> (floor (nr_bins_f1_ * ((pfh_tuple[0] + M_PI) * d_pi_)));
148 if (h_index >= nr_bins_f1_)
149 h_index = nr_bins_f1_ - 1;
150 hist_f1_ (h_index) += hist_incr;
152 h_index =
static_cast<int> (floor (nr_bins_f2_ * ((pfh_tuple[1] + 1.0) * 0.5)));
155 if (h_index >= nr_bins_f2_)
156 h_index = nr_bins_f2_ - 1;
157 hist_f2_ (h_index) += hist_incr;
159 h_index =
static_cast<int> (floor (nr_bins_f3_ * ((pfh_tuple[2] + 1.0) * 0.5)));
162 if (h_index >= nr_bins_f3_)
163 h_index = nr_bins_f3_ - 1;
164 hist_f3_ (h_index) += hist_incr;
166 if (normalize_distances_)
167 h_index =
static_cast<int> (floor (nr_bins_f4_ * (pfh_tuple[3] / distance_normalization_factor)));
169 h_index =
static_cast<int> (
pcl_round (pfh_tuple[3] * 100));
173 if (h_index >= nr_bins_f4_)
174 h_index = nr_bins_f4_ - 1;
176 hist_f4_ (h_index) += hist_incr_size_component;
180 template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
184 Eigen::Vector4f xyz_centroid;
186 if (use_given_centroid_)
187 xyz_centroid = centroid_to_use_;
192 Eigen::Vector4f normal_centroid = Eigen::Vector4f::Zero ();
196 if (use_given_normal_)
197 normal_centroid = normal_to_use_;
200 if (normals_->is_dense)
202 for (
size_t i = 0; i < indices_->size (); ++i)
204 normal_centroid += normals_->points[(*indices_)[i]].getNormalVector4fMap ();
211 for (
size_t i = 0; i < indices_->size (); ++i)
213 if (!
pcl_isfinite (normals_->points[(*indices_)[i]].normal[0])
215 !
pcl_isfinite (normals_->points[(*indices_)[i]].normal[1])
217 !
pcl_isfinite (normals_->points[(*indices_)[i]].normal[2]))
219 normal_centroid += normals_->points[(*indices_)[i]].getNormalVector4fMap ();
223 normal_centroid /=
static_cast<float> (cp);
227 Eigen::Vector4f viewpoint (vpx_, vpy_, vpz_, 0);
228 Eigen::Vector4f d_vp_p = viewpoint - xyz_centroid;
232 computePointSPFHSignature (xyz_centroid, normal_centroid, *surface_, *normals_, *indices_);
235 output.points.resize (1);
240 for (
int d = 0; d < hist_f1_.size (); ++d)
241 output.points[0].histogram[d + 0] = hist_f1_[d];
243 size_t data_size = hist_f1_.size ();
244 for (
int d = 0; d < hist_f2_.size (); ++d)
245 output.points[0].histogram[d + data_size] = hist_f2_[d];
247 data_size += hist_f2_.size ();
248 for (
int d = 0; d < hist_f3_.size (); ++d)
249 output.points[0].histogram[d + data_size] = hist_f3_[d];
251 data_size += hist_f3_.size ();
252 for (
int d = 0; d < hist_f4_.size (); ++d)
253 output.points[0].histogram[d + data_size] = hist_f4_[d];
256 hist_vp_.setZero (nr_bins_vp_);
260 hist_incr = 100.0 /
static_cast<double> (indices_->size ());
264 for (
size_t i = 0; i < indices_->size (); ++i)
266 Eigen::Vector4f normal (normals_->points[(*indices_)[i]].normal[0],
267 normals_->points[(*indices_)[i]].normal[1],
268 normals_->points[(*indices_)[i]].normal[2], 0);
270 double alpha = (normal.dot (d_vp_p) + 1.0) * 0.5;
271 int fi =
static_cast<int> (floor (alpha * static_cast<double> (hist_vp_.size ())));
274 if (fi > (static_cast<int> (hist_vp_.size ()) - 1))
275 fi = static_cast<int> (hist_vp_.size ()) - 1;
277 hist_vp_ [fi] +=
static_cast<float> (hist_incr);
279 data_size += hist_f4_.size ();
281 for (
int d = 0; d < hist_vp_.size (); ++d)
282 output.points[0].histogram[d + data_size] = hist_vp_[d];
285 #define PCL_INSTANTIATE_VFHEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::VFHEstimation<T,NT,OutT>;
287 #endif // PCL_FEATURES_IMPL_VFH_H_