Point Cloud Library (PCL)  1.9.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 #include <pcl/features/pfh.h>
46 
47 //////////////////////////////////////////////////////////////////////////////////////////////
48 template <typename PointInT, typename PointNT, typename PointOutT>
50  : FeatureFromNormals <PointInT, PointNT, PointOutT> ()
51 {
52  feature_name_ = "CPPFEstimation";
53  // Slight hack in order to pass the check for the presence of a search method in Feature::initCompute ()
56 }
57 
58 
59 //////////////////////////////////////////////////////////////////////////////////////////////
60 template <typename PointInT, typename PointNT, typename PointOutT> void
62 {
63  // Initialize output container - overwrite the sizes done by Feature::initCompute ()
64  output.points.resize (indices_->size () * input_->points.size ());
65  output.height = 1;
66  output.width = static_cast<uint32_t> (output.points.size ());
67  output.is_dense = true;
68 
69  // Compute point pair features for every pair of points in the cloud
70  for (size_t index_i = 0; index_i < indices_->size (); ++index_i)
71  {
72  size_t i = (*indices_)[index_i];
73  for (size_t j = 0 ; j < input_->points.size (); ++j)
74  {
75  PointOutT p;
76  if (i != j)
77  {
78  if (
79  pcl::computeCPPFPairFeature (input_->points[i].getVector4fMap (),
80  normals_->points[i].getNormalVector4fMap (),
81  input_->points[i].getRGBVector4i (),
82  input_->points[j].getVector4fMap (),
83  normals_->points[j].getNormalVector4fMap (),
84  input_->points[j].getRGBVector4i (),
85  p.f1, p.f2, p.f3, p.f4, p.f5, p.f6, p.f7, p.f8, p.f9, p.f10))
86  {
87  // Calculate alpha_m angle
88  Eigen::Vector3f model_reference_point = input_->points[i].getVector3fMap (),
89  model_reference_normal = normals_->points[i].getNormalVector3fMap (),
90  model_point = input_->points[j].getVector3fMap ();
91  Eigen::AngleAxisf rotation_mg (std::acos (model_reference_normal.dot (Eigen::Vector3f::UnitX ())),
92  model_reference_normal.cross (Eigen::Vector3f::UnitX ()).normalized ());
93  Eigen::Affine3f transform_mg = Eigen::Translation3f ( rotation_mg * ((-1) * model_reference_point)) * rotation_mg;
94 
95  Eigen::Vector3f model_point_transformed = transform_mg * model_point;
96  float angle = std::atan2 ( -model_point_transformed(2), model_point_transformed(1));
97  if (std::sin (angle) * model_point_transformed(2) < 0.0f)
98  angle *= (-1);
99  p.alpha_m = -angle;
100  }
101  else
102  {
103  PCL_ERROR ("[pcl::%s::computeFeature] Computing pair feature vector between points %lu and %lu went wrong.\n", getClassName ().c_str (), i, j);
104  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 ();
105  output.is_dense = false;
106  }
107  }
108  // Do not calculate the feature for identity pairs (i, i) as they are not used
109  // in the following computations
110  else
111  {
112  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 ();
113  output.is_dense = false;
114  }
115 
116  output.points[index_i*input_->points.size () + j] = p;
117  }
118  }
119 }
120 
121 #define PCL_INSTANTIATE_CPPFEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::CPPFEstimation<T,NT,OutT>;
122 
123 
124 #endif // PCL_FEATURES_IMPL_CPPF_H_
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:61
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:423
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)
Class that calculates the "surflet" features for each pair in the given pointcloud.
Definition: cppf.h:87
std::string feature_name_
The feature name.
Definition: feature.h:222
CPPFEstimation()
Empty Constructor.
Definition: cppf.hpp:49
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:154
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:428
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: feature.h:246
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:426
PointCloudNConstPtr normals_
A pointer to the input dataset that contains the point normals of the XYZ dataset.
Definition: feature.h:354
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields)...
Definition: point_cloud.h:431
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:151
Feature represents the base feature class.
Definition: feature.h:105