Point Cloud Library (PCL)  1.11.1
narf.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #include <iostream>
40 #include <map>
41 #include <pcl/common/norms.h> // for L1_Norm
42 #include <pcl/common/eigen.h>
43 
44 namespace pcl {
45 
46 inline float
47 Narf::getDescriptorDistance(const Narf& other) const
48 {
49  float ret = L1_Norm(descriptor_, other.descriptor_, descriptor_size_);
50  //float ret = Sublinear_Norm(descriptor_, other.descriptor_, descriptor_size_);
51  ret /= static_cast<float> (descriptor_size_);
52  return (ret);
53 }
54 
55 inline void Narf::copyToNarf36(Narf36& narf36) const
56 {
57  if (descriptor_size_ != 36)
58  {
59  std::cerr << __PRETTY_FUNCTION__ << ": descriptor size is not 36!\n";
60  return;
61  }
62  getTranslationAndEulerAngles(transformation_.inverse (), narf36.x, narf36.y, narf36.z, narf36.roll, narf36.pitch, narf36.yaw);
63  memcpy(narf36.descriptor, descriptor_, 36*sizeof(*descriptor_));
64 }
65 
66 //inline float Narf::getDescriptorDistance(const Narf& other) const
67 //{
68  //float middle_value = 0.1f;
69  //float normalization_factor1 = 1.0f/middle_value,
70  //normalization_factor2 = 1.0f/(1.0f-middle_value);
71  //const float* descriptor1_ptr = descriptor_;
72  //const float* descriptor2_ptr = other.getDescriptor();
73  //float ret = 0;
74  //for (int i=0; i<descriptor_size_; ++i) {
75  //float diff = std::abs(*(descriptor2_ptr++) - *(descriptor1_ptr++));
76  //if (diff < middle_value)
77  //{
78  //diff = diff*normalization_factor1;
79  //diff = 0.5f*diff*diff;
80  ////diff = 0.5f*powf(diff, 2);
81  //}
82  //else
83  //{
84  //diff = (diff - middle_value)*normalization_factor2;
85  //diff = 0.5f + 0.5f*diff;
86  ////diff = 0.5f + 0.5f*std::sqrt(diff);
87  ////diff = 0.5f + 0.5f*powf(diff, 0.3f);
88  //}
89  //ret += diff;
90  //}
91  //ret /= descriptor_size_;
92  //return ret;
93 //}
94 
95 //inline float Narf::getDescriptorDistance(const Narf& other) const
96 //{
97  //float max_diff_between_cells = 0.25;
98 
99  //const float* descriptor1_ptr = descriptor_;
100  //const float* descriptor2_ptr = other.getDescriptor();
101  //float ret = 0;
102  //for (int i=0; i<descriptor_size_; ++i) {
103  //ret += (std::min)(max_diff_between_cells, std::abs(*(descriptor2_ptr++) - *(descriptor1_ptr++)));
104  //}
105  //ret /= descriptor_size_*max_diff_between_cells;
106  //return ret;
107 //}
108 
109 } // namespace end
Eigen::Affine3f transformation_
Definition: narf.h:275
float getDescriptorDistance(const Narf &other) const
Calculate descriptor distance, value in [0,1] with 0 meaning identical and 1 every cell above maximum...
Definition: narf.hpp:47
NARF (Normal Aligned Radial Features) is a point feature descriptor type for 3D data.
Definition: narf.h:64
void getTranslationAndEulerAngles(const Eigen::Transform< Scalar, 3, Eigen::Affine > &t, Scalar &x, Scalar &y, Scalar &z, Scalar &roll, Scalar &pitch, Scalar &yaw)
Extract x,y,z and the Euler angles (XYZ-convention) from the given transformation.
Definition: eigen.hpp:594
Define standard C methods to calculate different norms.
void copyToNarf36(Narf36 &narf36) const
Copy the descriptor and pose to the point struct Narf36.
Definition: narf.hpp:55
float L1_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the L1 norm of the vector between two points.
Definition: norms.hpp:88
A point structure representing the Narf descriptor.
float descriptor[36]
float * descriptor_
Definition: narf.h:280
int descriptor_size_
Definition: narf.h:281