Point Cloud Library (PCL)  1.14.1-dev
cppf.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011, Alexandru-Eugen Ichim
6  * Copyright (c) 2012-, Open Perception, Inc.
7  * Copyright (c) 2013, Martin Szarski
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of the copyright holder(s) nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  * $Id$
39  */
40 
41 #ifndef PCL_FEATURES_IMPL_CPPF_H_
42 #define PCL_FEATURES_IMPL_CPPF_H_
43 
44 #include <pcl/features/cppf.h>
45 
46 //////////////////////////////////////////////////////////////////////////////////////////////
47 template <typename PointInT, typename PointNT, typename PointOutT>
49  : FeatureFromNormals <PointInT, PointNT, PointOutT> ()
50 {
51  feature_name_ = "CPPFEstimation";
52  // Slight hack in order to pass the check for the presence of a search method in Feature::initCompute ()
55 }
56 
57 
58 //////////////////////////////////////////////////////////////////////////////////////////////
59 template <typename PointInT, typename PointNT, typename PointOutT> void
61 {
62  // Initialize output container
63  output.points.clear ();
64  output.points.reserve (indices_->size () * input_->size ());
65  output.is_dense = true;
66  // Compute point pair features for every pair of points in the cloud
67  for (const auto& i: *indices_)
68  {
69  for (std::size_t j = 0 ; j < input_->size (); ++j)
70  {
71  PointOutT p;
72  // No need to calculate feature for identity pair (i, j) as they aren't used in future calculations
73  // @TODO: resolve issue with comparison in a better manner
74  if (static_cast<std::size_t>(i) != j)
75  {
76  if (
77  pcl::computeCPPFPairFeature ((*input_)[i].getVector4fMap (),
78  (*normals_)[i].getNormalVector4fMap (),
79  (*input_)[i].getRGBVector4i (),
80  (*input_)[j].getVector4fMap (),
81  (*normals_)[j].getNormalVector4fMap (),
82  (*input_)[j].getRGBVector4i (),
83  p.f1, p.f2, p.f3, p.f4, p.f5, p.f6, p.f7, p.f8, p.f9, p.f10))
84  {
85  // Calculate alpha_m angle
86  Eigen::Vector3f model_reference_point = (*input_)[i].getVector3fMap (),
87  model_reference_normal = (*normals_)[i].getNormalVector3fMap (),
88  model_point = (*input_)[j].getVector3fMap ();
89  Eigen::AngleAxisf rotation_mg (std::acos (model_reference_normal.dot (Eigen::Vector3f::UnitX ())),
90  model_reference_normal.cross (Eigen::Vector3f::UnitX ()).normalized ());
91  Eigen::Affine3f transform_mg = Eigen::Translation3f ( rotation_mg * ((-1) * model_reference_point)) * rotation_mg;
92 
93  Eigen::Vector3f model_point_transformed = transform_mg * model_point;
94  float angle = std::atan2 ( -model_point_transformed(2), model_point_transformed(1));
95  if (std::sin (angle) * model_point_transformed(2) < 0.0f)
96  angle *= (-1);
97  p.alpha_m = -angle;
98  }
99  else
100  {
101  PCL_ERROR ("[pcl::%s::computeFeature] Computing pair feature vector between points %lu and %lu went wrong.\n", getClassName ().c_str (), i, j);
102  p.f1 = p.f2 = p.f3 = p.f4 = p.f5 = p.f6 = p.f7 = p.f8 = p.f9 = p.f10 = p.alpha_m = std::numeric_limits<float>::quiet_NaN ();
103  output.is_dense = false;
104  }
105  }
106  else
107  {
108  p.f1 = p.f2 = p.f3 = p.f4 = p.f5 = p.f6 = p.f7 = p.f8 = p.f9 = p.f10 = p.alpha_m = std::numeric_limits<float>::quiet_NaN ();
109  output.is_dense = false;
110  }
111 
112  output.push_back (p);
113  }
114  }
115  // overwrite the sizes done by Feature::initCompute ()
116  output.height = 1;
117  output.width = output.size ();
118 }
119 
120 #define PCL_INSTANTIATE_CPPFEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::CPPFEstimation<T,NT,OutT>;
121 
122 
123 #endif // PCL_FEATURES_IMPL_CPPF_H_
Class that calculates the "surflet" features for each pair in the given pointcloud.
Definition: cppf.h:87
CPPFEstimation()
Empty Constructor.
Definition: cppf.hpp:48
Feature represents the base feature class.
Definition: feature.h:107
std::string feature_name_
The feature name.
Definition: feature.h:220
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:62
PCL_EXPORTS bool computeCPPFPairFeature(const Eigen::Vector4f &p1, const Eigen::Vector4f &n1, const Eigen::Vector4i &c1, const Eigen::Vector4f &p2, const Eigen::Vector4f &n2, const Eigen::Vector4i &c2, float &f1, float &f2, float &f3, float &f4, float &f5, float &f6, float &f7, float &f8, float &f9, float &f10)