39 #ifndef PCL_FEATURES_IMPL_FLARE_H_
40 #define PCL_FEATURES_IMPL_FLARE_H_
42 #include <pcl/features/flare.h>
46 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT,
typename SignedDistanceT>
bool
51 PCL_ERROR (
"[pcl::%s::initCompute] Init failed.\n", getClassName ().c_str ());
55 if (tangent_radius_ == 0.0f)
57 PCL_ERROR (
"[pcl::%s::initCompute] tangent_radius_ not set.\n", getClassName ().c_str ());
62 if (!sampled_surface_)
64 fake_sampled_surface_ =
true;
65 sampled_surface_ = surface_;
69 PCL_WARN (
"[pcl::%s::initCompute] sampled_surface_ is not set even if sampled_tree_ is already set.", getClassName ().c_str ());
70 PCL_WARN (
"sampled_tree_ will be rebuilt from surface_. Use sampled_surface_.\n");
77 if (sampled_surface_->isOrganized () && surface_->isOrganized () && input_->isOrganized ())
83 if (sampled_tree_->getInputCloud () != sampled_surface_)
84 sampled_tree_->setInputCloud (sampled_surface_);
90 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT,
typename SignedDistanceT>
bool
97 fake_surface_ =
false;
100 if (fake_sampled_surface_)
102 sampled_surface_.reset ();
103 fake_sampled_surface_ =
false;
109 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT,
typename SignedDistanceT> SignedDistanceT
111 Eigen::Matrix3f &lrf)
113 Eigen::Vector3f x_axis, y_axis;
114 Eigen::Vector3f fitted_normal;
120 std::vector<float> neighbours_distances;
122 const std::size_t n_normal_neighbours =
123 this->searchForNeighbors (index, search_parameter_, neighbours_indices, neighbours_distances);
124 if (n_normal_neighbours <
static_cast<std::size_t
>(min_neighbors_for_normal_axis_))
130 lrf.setConstant (std::numeric_limits<float>::quiet_NaN ());
131 return (std::numeric_limits<SignedDistanceT>::max ());
135 fitted_normal = (*normals_)[index].getNormalVector3fMap ();
139 float plane_curvature;
140 normal_estimation_.computePointNormal (*surface_, neighbours_indices, fitted_normal (0), fitted_normal (1), fitted_normal (2), plane_curvature);
143 if (!pcl::flipNormalTowardsNormalsMean<PointNT> (*normals_, neighbours_indices, fitted_normal))
147 lrf.setConstant (std::numeric_limits<float>::quiet_NaN ());
148 return (std::numeric_limits<SignedDistanceT>::max ());
153 lrf.row (2).matrix () = fitted_normal;
158 const std::size_t n_tangent_neighbours =
159 sampled_tree_->radiusSearch ((*input_)[index], tangent_radius_, neighbours_indices, neighbours_distances);
161 if (n_tangent_neighbours <
static_cast<std::size_t
>(min_neighbors_for_tangent_axis_))
165 y_axis = fitted_normal.cross (x_axis);
167 lrf.row (0).matrix () = x_axis;
168 lrf.row (1).matrix () = y_axis;
170 return (std::numeric_limits<SignedDistanceT>::max ());
175 SignedDistanceT shape_score;
176 SignedDistanceT best_shape_score = -std::numeric_limits<SignedDistanceT>::max ();
177 int best_shape_index = -1;
179 Eigen::Vector3f best_margin_point;
181 const float radius2 = tangent_radius_ * tangent_radius_;
182 const float margin_distance2 = margin_thresh_ * margin_thresh_ * radius2;
186 for (std::size_t curr_neigh = 0; curr_neigh < n_tangent_neighbours; ++curr_neigh)
188 const int& curr_neigh_idx = neighbours_indices[curr_neigh];
189 const float& neigh_distance_sqr = neighbours_distances[curr_neigh];
191 if (neigh_distance_sqr <= margin_distance2)
198 shape_score = fitted_normal.dot ((*sampled_surface_)[curr_neigh_idx].getVector3fMap ());
200 if (shape_score > best_shape_score)
202 best_shape_index = curr_neigh_idx;
203 best_shape_score = shape_score;
207 if (best_shape_index == -1)
210 y_axis = fitted_normal.cross (x_axis);
212 lrf.row (0).matrix () = x_axis;
213 lrf.row (1).matrix () = y_axis;
215 return (std::numeric_limits<SignedDistanceT>::max ());
221 y_axis = fitted_normal.cross (x_axis);
223 lrf.row (0).matrix () = x_axis;
224 lrf.row (1).matrix () = y_axis;
227 best_shape_score -= fitted_normal.dot (feature_point);
228 return (best_shape_score);
232 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT,
typename SignedDistanceT>
void
236 if (this->getKSearch () != 0)
239 "[pcl::%s::computeFeature] Error! Search method set to k-neighborhood. Call setKSearch (0) and setRadiusSearch (radius) to use this class.\n",
240 getClassName ().c_str ());
244 signed_distances_from_highest_points_.resize (indices_->size ());
246 for (std::size_t point_idx = 0; point_idx < indices_->size (); ++point_idx)
248 Eigen::Matrix3f currentLrf;
249 PointOutT &rf = output[point_idx];
251 signed_distances_from_highest_points_[point_idx] = computePointLRF ((*indices_)[point_idx], currentLrf);
252 if (signed_distances_from_highest_points_[point_idx] == std::numeric_limits<SignedDistanceT>::max ())
254 output.is_dense =
false;
257 rf.getXAxisVector3fMap () = currentLrf.row (0);
258 rf.getYAxisVector3fMap () = currentLrf.row (1);
259 rf.getZAxisVector3fMap () = currentLrf.row (2);
263 #define PCL_INSTANTIATE_FLARELocalReferenceFrameEstimation(T,NT,OutT,SdT) template class PCL_EXPORTS pcl::FLARELocalReferenceFrameEstimation<T,NT,OutT,SdT>;
bool deinitCompute() override
This method should get called after the actual computation is ended.
void computeFeature(PointCloudOut &output) override
Abstract feature estimation method.
bool initCompute() override
This method should get called before starting the actual computation.
SignedDistanceT computePointLRF(const int index, Eigen::Matrix3f &lrf)
Estimate the LRF descriptor for a given point based on its spatial neighborhood of 3D points with nor...
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
OrganizedNeighbor is a class for optimized nearest neighbor search in organized projectable point clo...
Defines some geometrical functions and utility functions.
Eigen::Vector3f projectedAsUnitVector(Eigen::Vector3f const &point, Eigen::Vector3f const &plane_origin, Eigen::Vector3f const &plane_normal)
Given a plane defined by plane_origin and plane_normal, find the unit vector pointing from plane_orig...
Eigen::Vector3f randomOrthogonalAxis(Eigen::Vector3f const &axis)
Define a random unit vector orthogonal to axis.
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...
const Eigen::Map< const Eigen::Vector3f > Vector3fMapConst
IndicesAllocator<> Indices
Type used for indices in PCL.