Point Cloud Library (PCL)  1.9.1-dev
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 
42 namespace pcl {
43 
44 inline float
45 Narf::getDescriptorDistance(const Narf& other) const
46 {
47  float ret = L1_Norm(descriptor_, other.descriptor_, descriptor_size_);
48  //float ret = Sublinear_Norm(descriptor_, other.descriptor_, descriptor_size_);
49  ret /= static_cast<float> (descriptor_size_);
50  return (ret);
51 }
52 
53 inline void Narf::copyToNarf36(Narf36& narf36) const
54 {
55  if (descriptor_size_ != 36)
56  {
57  std::cerr << __PRETTY_FUNCTION__ << ": descriptor size is not 36!\n";
58  return;
59  }
60  getTranslationAndEulerAngles(transformation_.inverse (), narf36.x, narf36.y, narf36.z, narf36.roll, narf36.pitch, narf36.yaw);
61  memcpy(narf36.descriptor, descriptor_, 36*sizeof(*descriptor_));
62 }
63 
64 //inline float Narf::getDescriptorDistance(const Narf& other) const
65 //{
66  //float middle_value = 0.1f;
67  //float normalization_factor1 = 1.0f/middle_value,
68  //normalization_factor2 = 1.0f/(1.0f-middle_value);
69  //const float* descriptor1_ptr = descriptor_;
70  //const float* descriptor2_ptr = other.getDescriptor();
71  //float ret = 0;
72  //for (int i=0; i<descriptor_size_; ++i) {
73  //float diff = fabsf(*(descriptor2_ptr++) - *(descriptor1_ptr++));
74  //if (diff < middle_value)
75  //{
76  //diff = diff*normalization_factor1;
77  //diff = 0.5f*diff*diff;
78  ////diff = 0.5f*powf(diff, 2);
79  //}
80  //else
81  //{
82  //diff = (diff - middle_value)*normalization_factor2;
83  //diff = 0.5f + 0.5f*diff;
84  ////diff = 0.5f + 0.5f*std::sqrt(diff);
85  ////diff = 0.5f + 0.5f*powf(diff, 0.3f);
86  //}
87  //ret += diff;
88  //}
89  //ret /= descriptor_size_;
90  //return ret;
91 //}
92 
93 //inline float Narf::getDescriptorDistance(const Narf& other) const
94 //{
95  //float max_diff_between_cells = 0.25;
96 
97  //const float* descriptor1_ptr = descriptor_;
98  //const float* descriptor2_ptr = other.getDescriptor();
99  //float ret = 0;
100  //for (int i=0; i<descriptor_size_; ++i) {
101  //ret += (std::min)(max_diff_between_cells, fabsf(*(descriptor2_ptr++) - *(descriptor1_ptr++)));
102  //}
103  //ret /= descriptor_size_*max_diff_between_cells;
104  //return ret;
105 //}
106 
107 } // namespace end
Eigen::Affine3f transformation_
Definition: narf.h:273
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
NARF (Normal Aligned Radial Features) is a point feature descriptor type for 3D data.
Definition: narf.h:62
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:673
void copyToNarf36(Narf36 &narf36) const
Copy the descriptor and pose to the point struct Narf36.
Definition: narf.hpp:53
float L1_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the L1 norm of the vector between two points.
Definition: norms.hpp:87
A point structure representing the Narf descriptor.
float descriptor[36]
float * descriptor_
Definition: narf.h:278
int descriptor_size_
Definition: narf.h:279
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:45