Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
narf.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Author: Bastian Steder
35  */
36 
37 #include <iostream>
38 #include <map>
39 
40 namespace pcl {
41 
42 inline float
43 Narf::getDescriptorDistance(const Narf& other) const
44 {
45  float ret = L1_Norm(descriptor_, other.descriptor_, descriptor_size_);
46  //float ret = Sublinear_Norm(descriptor_, other.descriptor_, descriptor_size_);
47  ret /= static_cast<float> (descriptor_size_);
48  return (ret);
49 }
50 
51 inline void Narf::copyToNarf36(Narf36& narf36) const
52 {
53  if (descriptor_size_ != 36)
54  {
55  std::cerr << __PRETTY_FUNCTION__ << ": descriptor size is not 36!\n";
56  return;
57  }
58  getTranslationAndEulerAngles(transformation_.inverse (), narf36.x, narf36.y, narf36.z, narf36.roll, narf36.pitch, narf36.yaw);
59  memcpy(narf36.descriptor, descriptor_, 36*sizeof(*descriptor_));
60 }
61 
62 //inline float Narf::getDescriptorDistance(const Narf& other) const
63 //{
64  //float middle_value = 0.1f;
65  //float normalization_factor1 = 1.0f/middle_value,
66  //normalization_factor2 = 1.0f/(1.0f-middle_value);
67  //const float* descriptor1_ptr = descriptor_;
68  //const float* descriptor2_ptr = other.getDescriptor();
69  //float ret = 0;
70  //for (int i=0; i<descriptor_size_; ++i) {
71  //float diff = fabsf(*(descriptor2_ptr++) - *(descriptor1_ptr++));
72  //if (diff < middle_value)
73  //{
74  //diff = diff*normalization_factor1;
75  //diff = 0.5f*diff*diff;
77  //}
78  //else
79  //{
80  //diff = (diff - middle_value)*normalization_factor2;
81  //diff = 0.5f + 0.5f*diff;
84  //}
85  //ret += diff;
86  //}
87  //ret /= descriptor_size_;
88  //return ret;
89 //}
90 
91 //inline float Narf::getDescriptorDistance(const Narf& other) const
92 //{
93  //float max_diff_between_cells = 0.25;
94 
95  //const float* descriptor1_ptr = descriptor_;
96  //const float* descriptor2_ptr = other.getDescriptor();
97  //float ret = 0;
98  //for (int i=0; i<descriptor_size_; ++i) {
99  //ret += (std::min)(max_diff_between_cells, fabsf(*(descriptor2_ptr++) - *(descriptor1_ptr++)));
100  //}
101  //ret /= descriptor_size_*max_diff_between_cells;
102  //return ret;
103 //}
104 
105 } // namespace end