Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ppfrgb.hpp
Go to the documentation of this file.
1 #ifndef PCL_FEATURES_IMPL_PPFRGB_H_
2 #define PCL_FEATURES_IMPL_PPFRGB_H_
3 
4 #include <pcl/features/ppfrgb.h>
5 #include <pcl/features/pfhrgb.h>
6 
8 template <typename PointInT, typename PointNT, typename PointOutT>
10 : FeatureFromNormals <PointInT, PointNT, PointOutT> ()
11 {
12  feature_name_ = "PPFRGBEstimation";
13  // Slight hack in order to pass the check for the presence of a search method in Feature::initCompute ()
16 }
17 
18 
20 template <typename PointInT, typename PointNT, typename PointOutT> void
22 {
23  // Initialize output container - overwrite the sizes done by Feature::initCompute ()
24  output.points.resize (indices_->size () * input_->points.size ());
25  output.height = 1;
26  output.width = static_cast<uint32_t> (output.points.size ());
27 
28  // Compute point pair features for every pair of points in the cloud
29  for (size_t index_i = 0; index_i < indices_->size (); ++index_i)
30  {
31  size_t i = (*indices_)[index_i];
32  for (size_t j = 0 ; j < input_->points.size (); ++j)
33  {
34  PointOutT p;
35  if (i != j)
36  {
38  (input_->points[i].getVector4fMap (), normals_->points[i].getNormalVector4fMap (), input_->points[i].getRGBVector4i (),
39  input_->points[j].getVector4fMap (), normals_->points[j].getNormalVector4fMap (), input_->points[j].getRGBVector4i (),
40  p.f1, p.f2, p.f3, p.f4, p.r_ratio, p.g_ratio, p.b_ratio))
41  {
42  // Calculate alpha_m angle
43  Eigen::Vector3f model_reference_point = input_->points[i].getVector3fMap (),
44  model_reference_normal = normals_->points[i].getNormalVector3fMap (),
45  model_point = input_->points[j].getVector3fMap ();
46  Eigen::AngleAxisf rotation_mg (acosf (model_reference_normal.dot (Eigen::Vector3f::UnitX ())),
47  model_reference_normal.cross (Eigen::Vector3f::UnitX ()).normalized ());
48  Eigen::Affine3f transform_mg = Eigen::Translation3f ( rotation_mg * ((-1) * model_reference_point)) * rotation_mg;
49 
50  Eigen::Vector3f model_point_transformed = transform_mg * model_point;
51  float angle = atan2f ( -model_point_transformed(2), model_point_transformed(1));
52  if (sin (angle) * model_point_transformed(2) < 0.0f)
53  angle *= (-1);
54  p.alpha_m = -angle;
55  }
56  else
57  {
58  PCL_ERROR ("[pcl::%s::computeFeature] Computing pair feature vector between points %zu and %zu went wrong.\n", getClassName ().c_str (), i, j);
59  p.f1 = p.f2 = p.f3 = p.f4 = p.alpha_m = p.r_ratio = p.g_ratio = p.b_ratio = 0.f;
60  }
61  }
62  // Do not calculate the feature for identity pairs (i, i) as they are not used
63  // in the following computations
64  else
65  p.f1 = p.f2 = p.f3 = p.f4 = p.alpha_m = p.r_ratio = p.g_ratio = p.b_ratio = 0.f;
66 
67  output.points[index_i*input_->points.size () + j] = p;
68  }
69  }
70 }
71 
72 
73 
76 template <typename PointInT, typename PointNT, typename PointOutT>
78 : FeatureFromNormals <PointInT, PointNT, PointOutT> ()
79 {
80  feature_name_ = "PPFRGBEstimation";
81 }
82 
84 template <typename PointInT, typename PointNT, typename PointOutT> void
86 {
87  PCL_INFO ("before computing output size: %u\n", output.size ());
88  output.resize (indices_->size ());
89  for (int index_i = 0; index_i < static_cast<int> (indices_->size ()); ++index_i)
90  {
91  int i = (*indices_)[index_i];
92  std::vector<int> nn_indices;
93  std::vector<float> nn_distances;
94  tree_->radiusSearch (i, static_cast<float> (search_radius_), nn_indices, nn_distances);
95 
96  PointOutT average_feature_nn;
97  average_feature_nn.alpha_m = 0;
98  average_feature_nn.f1 = average_feature_nn.f2 = average_feature_nn.f3 = average_feature_nn.f4 =
99  average_feature_nn.r_ratio = average_feature_nn.g_ratio = average_feature_nn.b_ratio = 0.0f;
100 
101  for (std::vector<int>::iterator nn_it = nn_indices.begin (); nn_it != nn_indices.end (); ++nn_it)
102  {
103  int j = *nn_it;
104  if (i != j)
105  {
106  float f1, f2, f3, f4, r_ratio, g_ratio, b_ratio;
108  (input_->points[i].getVector4fMap (), normals_->points[i].getNormalVector4fMap (), input_->points[i].getRGBVector4i (),
109  input_->points[j].getVector4fMap (), normals_->points[j].getNormalVector4fMap (), input_->points[j].getRGBVector4i (),
110  f1, f2, f3, f4, r_ratio, g_ratio, b_ratio))
111  {
112  average_feature_nn.f1 += f1;
113  average_feature_nn.f2 += f2;
114  average_feature_nn.f3 += f3;
115  average_feature_nn.f4 += f4;
116  average_feature_nn.r_ratio += r_ratio;
117  average_feature_nn.g_ratio += g_ratio;
118  average_feature_nn.b_ratio += b_ratio;
119  }
120  else
121  {
122  PCL_ERROR ("[pcl::%s::computeFeature] Computing pair feature vector between points %zu and %zu went wrong.\n", getClassName ().c_str (), i, j);
123  }
124  }
125  }
126 
127  float normalization_factor = static_cast<float> (nn_indices.size ());
128  average_feature_nn.f1 /= normalization_factor;
129  average_feature_nn.f2 /= normalization_factor;
130  average_feature_nn.f3 /= normalization_factor;
131  average_feature_nn.f4 /= normalization_factor;
132  average_feature_nn.r_ratio /= normalization_factor;
133  average_feature_nn.g_ratio /= normalization_factor;
134  average_feature_nn.b_ratio /= normalization_factor;
135  output.points[index_i] = average_feature_nn;
136  }
137  PCL_INFO ("Output size: %u\n", output.points.size ());
138 }
139 
140 
141 #define PCL_INSTANTIATE_PPFRGBEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PPFRGBEstimation<T,NT,OutT>;
142 #define PCL_INSTANTIATE_PPFRGBRegionEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PPFRGBRegionEstimation<T,NT,OutT>;
143 
144 
145 
146 #endif // PCL_FEATURES_IMPL_PPFRGB_H_