Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
flare.hpp
1/*
2* Software License Agreement (BSD License)
3*
4* Point Cloud Library (PCL) - www.pointclouds.org
5* Copyright (c) 2016-, Open Perception, Inc.
6*
7* All rights reserved.
8*
9* Redistribution and use in source and binary forms, with or without
10* modification, are permitted provided that the following conditions
11* are met:
12*
13* * Redistributions of source code must retain the above copyright
14* notice, this list of conditions and the following disclaimer.
15* * Redistributions in binary form must reproduce the above
16* copyright notice, this list of conditions and the following
17* disclaimer in the documentation and/or other materials provided
18* with the distribution.
19* * Neither the name of the copyright holder(s) nor the names of its
20* contributors may be used to endorse or promote products derived
21* from this software without specific prior written permission.
22*
23* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34* POSSIBILITY OF SUCH DAMAGE.
35*
36*
37*/
38
39#ifndef PCL_FEATURES_IMPL_FLARE_H_
40#define PCL_FEATURES_IMPL_FLARE_H_
41
42#include <pcl/features/flare.h>
43#include <pcl/common/geometry.h>
44#include <pcl/search/auto.h> // for autoSelectMethod
45
46//////////////////////////////////////////////////////////////////////////////////////////////
47template<typename PointInT, typename PointNT, typename PointOutT, typename SignedDistanceT> bool
49{
51 {
52 PCL_ERROR ("[pcl::%s::initCompute] Init failed.\n", getClassName ().c_str ());
53 return (false);
54 }
55
56 if (tangent_radius_ == 0.0f)
57 {
58 PCL_ERROR ("[pcl::%s::initCompute] tangent_radius_ not set.\n", getClassName ().c_str ());
59 return (false);
60 }
61
62 // If no search sampled_surface_ has been defined, use the surface_ dataset as the search sampled_surface_ itself
63 if (!sampled_surface_)
64 {
65 fake_sampled_surface_ = true;
66 sampled_surface_ = surface_;
67
68 if (sampled_tree_)
69 {
70 PCL_WARN ("[pcl::%s::initCompute] sampled_surface_ is not set even if sampled_tree_ is already set.", getClassName ().c_str ());
71 PCL_WARN ("sampled_tree_ will be rebuilt from surface_. Use sampled_surface_.\n");
72 }
73 }
74
75 // Check if a space search locator was given for sampled_surface_
76 if (!sampled_tree_)
77 {
78 sampled_tree_.reset (pcl::search::autoSelectMethod<PointInT>(sampled_surface_, false, pcl::search::Purpose::radius_search));
79 }
80
81 if (sampled_tree_->getInputCloud () != sampled_surface_) // Make sure the tree searches the sampled surface
82 sampled_tree_->setInputCloud (sampled_surface_);
83
84 return (true);
85}
86
87//////////////////////////////////////////////////////////////////////////////////////////////
88template<typename PointInT, typename PointNT, typename PointOutT, typename SignedDistanceT> bool
90{
91 // Reset the surface
92 if (fake_surface_)
93 {
94 surface_.reset ();
95 fake_surface_ = false;
96 }
97 // Reset the sampled surface
98 if (fake_sampled_surface_)
99 {
100 sampled_surface_.reset ();
101 fake_sampled_surface_ = false;
102 }
103 return (true);
104}
105
106//////////////////////////////////////////////////////////////////////////////////////////////
107template<typename PointInT, typename PointNT, typename PointOutT, typename SignedDistanceT> SignedDistanceT
109 Eigen::Matrix3f &lrf)
110{
111 Eigen::Vector3f x_axis, y_axis;
112 Eigen::Vector3f fitted_normal; //z_axis
113
114 //find Z axis
115
116 //extract support points for the computation of Z axis
117 pcl::Indices neighbours_indices;
118 std::vector<float> neighbours_distances;
119
120 const std::size_t n_normal_neighbours =
121 this->searchForNeighbors (index, search_parameter_, neighbours_indices, neighbours_distances);
122 if (n_normal_neighbours < static_cast<std::size_t>(min_neighbors_for_normal_axis_))
123 {
124 if (!pcl::isFinite ((*normals_)[index]))
125 {
126 //normal is invalid
127 //setting lrf to NaN
128 lrf.setConstant (std::numeric_limits<float>::quiet_NaN ());
129 return (std::numeric_limits<SignedDistanceT>::max ());
130 }
131
132 //set z_axis as the normal of index point
133 fitted_normal = (*normals_)[index].getNormalVector3fMap ();
134 }
135 else
136 {
137 float plane_curvature;
138 normal_estimation_.computePointNormal (*surface_, neighbours_indices, fitted_normal (0), fitted_normal (1), fitted_normal (2), plane_curvature);
139
140 //disambiguate Z axis with normal mean
141 if (!pcl::flipNormalTowardsNormalsMean<PointNT> (*normals_, neighbours_indices, fitted_normal))
142 {
143 //all normals in the neighbourhood are invalid
144 //setting lrf to NaN
145 lrf.setConstant (std::numeric_limits<float>::quiet_NaN ());
146 return (std::numeric_limits<SignedDistanceT>::max ());
147 }
148 }
149
150 //setting LRF Z axis
151 lrf.row (2).matrix () = fitted_normal;
152
153 //find X axis
154
155 //extract support points for Rx radius
156 const std::size_t n_tangent_neighbours =
157 sampled_tree_->radiusSearch ((*input_)[index], tangent_radius_, neighbours_indices, neighbours_distances);
158
159 if (n_tangent_neighbours < static_cast<std::size_t>(min_neighbors_for_tangent_axis_))
160 {
161 //set X axis as a random axis
162 x_axis = pcl::geometry::randomOrthogonalAxis (fitted_normal);
163 y_axis = fitted_normal.cross (x_axis);
164
165 lrf.row (0).matrix () = x_axis;
166 lrf.row (1).matrix () = y_axis;
167
168 return (std::numeric_limits<SignedDistanceT>::max ());
169 }
170
171 //find point with the largest signed distance from tangent plane
172
173 SignedDistanceT shape_score;
174 SignedDistanceT best_shape_score = -std::numeric_limits<SignedDistanceT>::max ();
175 int best_shape_index = -1;
176
177 const float radius2 = tangent_radius_ * tangent_radius_;
178 const float margin_distance2 = margin_thresh_ * margin_thresh_ * radius2;
179
180 Vector3fMapConst feature_point = (*input_)[index].getVector3fMap ();
181
182 for (std::size_t curr_neigh = 0; curr_neigh < n_tangent_neighbours; ++curr_neigh)
183 {
184 const int& curr_neigh_idx = neighbours_indices[curr_neigh];
185 const float& neigh_distance_sqr = neighbours_distances[curr_neigh];
186
187 if (neigh_distance_sqr <= margin_distance2)
188 {
189 continue;
190 }
191
192 //point curr_neigh_idx is inside the ring between marginThresh and Radius
193
194 shape_score = fitted_normal.dot ((*sampled_surface_)[curr_neigh_idx].getVector3fMap ());
195
196 if (shape_score > best_shape_score)
197 {
198 best_shape_index = curr_neigh_idx;
199 best_shape_score = shape_score;
200 }
201 } //for each neighbor
202
203 if (best_shape_index == -1)
204 {
205 x_axis = pcl::geometry::randomOrthogonalAxis (fitted_normal);
206 y_axis = fitted_normal.cross (x_axis);
207
208 lrf.row (0).matrix () = x_axis;
209 lrf.row (1).matrix () = y_axis;
210
211 return (std::numeric_limits<SignedDistanceT>::max ());
212 }
213
214 //find orthogonal axis directed to best_shape_index point projection on plane with fittedNormal as axis
215 x_axis = pcl::geometry::projectedAsUnitVector (sampled_surface_->at (best_shape_index).getVector3fMap (), feature_point, fitted_normal);
216
217 y_axis = fitted_normal.cross (x_axis);
218
219 lrf.row (0).matrix () = x_axis;
220 lrf.row (1).matrix () = y_axis;
221 //z axis already set
222
223 best_shape_score -= fitted_normal.dot (feature_point);
224 return (best_shape_score);
225}
226
227//////////////////////////////////////////////////////////////////////////////////////////////
228template<typename PointInT, typename PointNT, typename PointOutT, typename SignedDistanceT> void
230{
231 //check whether used with search radius or search k-neighbors
232 if (this->getKSearch () != 0)
233 {
234 PCL_ERROR (
235 "[pcl::%s::computeFeature] Error! Search method set to k-neighborhood. Call setKSearch (0) and setRadiusSearch (radius) to use this class.\n",
236 getClassName ().c_str ());
237 return;
238 }
239
240 signed_distances_from_highest_points_.resize (indices_->size ());
241
242 for (std::size_t point_idx = 0; point_idx < indices_->size (); ++point_idx)
243 {
244 Eigen::Matrix3f currentLrf;
245 PointOutT &rf = output[point_idx];
246
247 signed_distances_from_highest_points_[point_idx] = computePointLRF ((*indices_)[point_idx], currentLrf);
248 if (signed_distances_from_highest_points_[point_idx] == std::numeric_limits<SignedDistanceT>::max ())
249 {
250 output.is_dense = false;
251 }
252
253 rf.getXAxisVector3fMap () = currentLrf.row (0);
254 rf.getYAxisVector3fMap () = currentLrf.row (1);
255 rf.getZAxisVector3fMap () = currentLrf.row (2);
256 }
257}
258
259#define PCL_INSTANTIATE_FLARELocalReferenceFrameEstimation(T,NT,OutT,SdT) template class PCL_EXPORTS pcl::FLARELocalReferenceFrameEstimation<T,NT,OutT,SdT>;
260
261#endif // PCL_FEATURES_IMPL_FLARE_H_
bool deinitCompute() override
This method should get called after the actual computation is ended.
Definition flare.hpp:89
void computeFeature(PointCloudOut &output) override
Abstract feature estimation method.
Definition flare.hpp:229
bool initCompute() override
This method should get called before starting the actual computation.
Definition flare.hpp:48
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...
Definition flare.hpp:108
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...
Definition geometry.h:115
Eigen::Vector3f randomOrthogonalAxis(Eigen::Vector3f const &axis)
Define a random unit vector orthogonal to axis.
Definition geometry.h:134
@ radius_search
The search method will mainly be used for radiusSearch.
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...
Definition point_tests.h:56
const Eigen::Map< const Eigen::Vector3f > Vector3fMapConst
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133