44 #include <pcl/features/usc.h>
45 #include <pcl/features/shot_lrf.h>
48 #include <pcl/common/point_tests.h>
49 #include <pcl/common/utils.h>
53 template <
typename Po
intInT,
typename Po
intOutT,
typename Po
intRFT>
bool
58 PCL_ERROR (
"[pcl::%s::initCompute] Init failed.\n", getClassName ().c_str ());
72 PCL_ERROR (
"[pcl::%s::initCompute] Init failed.\n", getClassName ().c_str ());
76 if (search_radius_< min_radius_)
78 PCL_ERROR (
"[pcl::%s::initCompute] search_radius_ must be GREATER than min_radius_.\n", getClassName ().c_str ());
83 descriptor_length_ = elevation_bins_ * azimuth_bins_ * radius_bins_;
86 float azimuth_interval = 360.0f /
static_cast<float> (azimuth_bins_);
87 float elevation_interval = 180.0f /
static_cast<float> (elevation_bins_);
90 radii_interval_.clear ();
91 phi_divisions_.clear ();
92 theta_divisions_.clear ();
96 radii_interval_.resize (radius_bins_ + 1);
97 for (std::size_t j = 0; j < radius_bins_ + 1; j++)
98 radii_interval_[j] =
static_cast<float> (std::exp (std::log (min_radius_) + ((
static_cast<float> (j) /
static_cast<float> (radius_bins_)) * std::log (search_radius_/min_radius_))));
101 theta_divisions_.resize (elevation_bins_ + 1, elevation_interval);
102 theta_divisions_[0] = 0;
103 std::partial_sum(theta_divisions_.begin (), theta_divisions_.end (), theta_divisions_.begin ());
106 phi_divisions_.resize (azimuth_bins_ + 1, azimuth_interval);
107 phi_divisions_[0] = 0;
108 std::partial_sum(phi_divisions_.begin (), phi_divisions_.end (), phi_divisions_.begin ());
115 float e = 1.0f / 3.0f;
117 volume_lut_.resize (radius_bins_ * elevation_bins_ * azimuth_bins_);
119 for (std::size_t j = 0; j < radius_bins_; j++)
122 float integr_r = (radii_interval_[j+1]*radii_interval_[j+1]*radii_interval_[j+1] / 3) - (radii_interval_[j]*radii_interval_[j]*radii_interval_[j]/ 3);
124 for (std::size_t k = 0; k < elevation_bins_; k++)
127 float integr_theta = std::cos (
deg2rad (theta_divisions_[k])) - std::cos (
deg2rad (theta_divisions_[k+1]));
129 float V = integr_phi * integr_theta * integr_r;
135 for (std::size_t l = 0; l < azimuth_bins_; l++)
138 volume_lut_[(l*elevation_bins_*radius_bins_) + k*radius_bins_ + j] = 1.0f / powf (V, e);
145 template <
typename Po
intInT,
typename Po
intOutT,
typename Po
intRFT>
void
150 const Eigen::Vector3f x_axis ((*frames_)[index].x_axis[0],
151 (*frames_)[index].x_axis[1],
152 (*frames_)[index].x_axis[2]);
154 const Eigen::Vector3f normal ((*frames_)[index].z_axis[0],
155 (*frames_)[index].z_axis[1],
156 (*frames_)[index].z_axis[2]);
160 std::vector<float> nn_dists;
161 const std::size_t neighb_cnt = searchForNeighbors ((*indices_)[index], search_radius_, nn_indices, nn_dists);
163 for (std::size_t ne = 0; ne < neighb_cnt; ne++)
168 Eigen::Vector3f neighbour = (*surface_)[nn_indices[ne]].getVector3fMap ();
173 float r = std::sqrt (nn_dists[ne]);
176 Eigen::Vector3f proj;
184 Eigen::Vector3f cross = x_axis.cross (proj);
185 float phi =
rad2deg (std::atan2 (cross.norm (), x_axis.dot (proj)));
186 phi = cross.dot (normal) < 0.f ? (360.0f - phi) : phi;
188 Eigen::Vector3f no = neighbour - origin;
190 float theta = normal.dot (no);
191 theta =
pcl::rad2deg (std::acos (std::min (1.0f, std::max (-1.0f, theta))));
194 const auto rad_min = std::lower_bound(std::next (radii_interval_.cbegin ()), radii_interval_.cend (), r);
195 const auto theta_min = std::lower_bound(std::next (theta_divisions_.cbegin ()), theta_divisions_.cend (), theta);
196 const auto phi_min = std::lower_bound(std::next (phi_divisions_.cbegin ()), phi_divisions_.cend (), phi);
199 const auto j =
std::distance(radii_interval_.cbegin (), std::prev(rad_min));
200 const auto k =
std::distance(theta_divisions_.cbegin (), std::prev(theta_min));
201 const auto l =
std::distance(phi_divisions_.cbegin (), std::prev(phi_min));
205 std::vector<float> neighbour_didtances;
206 float point_density =
static_cast<float> (searchForNeighbors (*surface_, nn_indices[ne], point_density_radius_, neighbour_indices, neighbour_didtances));
208 float w = (1.0f / point_density) * volume_lut_[(l*elevation_bins_*radius_bins_) +
213 if (w == std::numeric_limits<float>::infinity ())
214 PCL_ERROR (
"Shape Context Error INF!\n");
216 PCL_ERROR (
"Shape Context Error IND!\n");
218 desc[(l*elevation_bins_*radius_bins_) + (k*radius_bins_) + j] += w;
220 assert (desc[(l*elevation_bins_*radius_bins_) + (k*radius_bins_) + j] >= 0);
225 template <
typename Po
intInT,
typename Po
intOutT,
typename Po
intRFT>
void
228 assert (descriptor_length_ == 1960);
230 output.is_dense =
true;
232 for (std::size_t point_index = 0; point_index < indices_->size (); ++point_index)
237 const PointRFT& current_frame = (*frames_)[point_index];
238 if (!
isFinite ((*input_)[(*indices_)[point_index]]) ||
239 !std::isfinite (current_frame.x_axis[0]) ||
240 !std::isfinite (current_frame.y_axis[0]) ||
241 !std::isfinite (current_frame.z_axis[0]) )
243 std::fill_n (output[point_index].descriptor, descriptor_length_,
244 std::numeric_limits<float>::quiet_NaN ());
245 std::fill_n (output[point_index].rf, 9, 0);
246 output.is_dense =
false;
250 for (
int d = 0; d < 3; ++d)
252 output[point_index].rf[0 + d] = current_frame.x_axis[d];
253 output[point_index].rf[3 + d] = current_frame.y_axis[d];
254 output[point_index].rf[6 + d] = current_frame.z_axis[d];
257 std::vector<float> descriptor (descriptor_length_);
258 computePointDescriptor (point_index, descriptor);
259 std::copy (descriptor.cbegin (), descriptor.cend (), output[point_index].descriptor);
263 #define PCL_INSTANTIATE_UniqueShapeContext(T,OutT,RFT) template class PCL_EXPORTS pcl::UniqueShapeContext<T,OutT,RFT>;
Define standard C methods to do angle calculations.
Feature represents the base feature class.
void setSearchSurface(const PointCloudInConstPtr &cloud)
Provide a pointer to a dataset to add additional information to estimate the features for every point...
void setRadiusSearch(double radius)
Set the sphere radius that is to be used for determining the nearest neighbors used for the feature e...
FeatureWithLocalReferenceFrames provides a public interface for descriptor extractor classes which ne...
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
virtual void setIndices(const IndicesPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
SHOTLocalReferenceFrameEstimation estimates the Local Reference Frame used in the calculation of the ...
shared_ptr< SHOTLocalReferenceFrameEstimation< PointInT, PointOutT > > Ptr
void computeFeature(PointCloudOut &output) override
The actual feature computation.
bool initCompute() override
Initialize computation by allocating all the intervals and the volume lookup table.
void computePointDescriptor(std::size_t index, std::vector< float > &desc)
Compute 3D shape context feature descriptor.
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Defines some geometrical functions and utility functions.
float deg2rad(float alpha)
Convert an angle from degrees to radians.
float rad2deg(float alpha)
Convert an angle from radians to degrees.
float distance(const PointT &p1, const PointT &p2)
void project(const PointT &point, const PointT &plane_origin, const NormalT &plane_normal, PointT &projected)
bool equal(T val1, T val2, T eps=std::numeric_limits< T >::min())
Check if val1 and val2 are equal to an epsilon extent.
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.