Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
intensity.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: intensity.hpp 5299 2012-03-26 03:27:10Z svn $
37  *
38  */
39 
40 #ifndef PCL_COMMON_INTENSITY_FIELD_ACCESSOR_IMPL_HPP
41 #define PCL_COMMON_INTENSITY_FIELD_ACCESSOR_IMPL_HPP
42 
43 #include <pcl/point_types.h>
44 namespace pcl
45 {
46  namespace common
47  {
48  template<>
50  {
51  inline float
53  {
54  return p.curvature;
55  }
56 
57  inline void
58  get (const pcl::PointNormal &p, float &intensity) const
59  {
60  intensity = p.curvature;
61  }
62 
63  inline void
64  set (pcl::PointNormal &p, float intensity) const
65  {
66  p.curvature = intensity;
67  }
68 
69  inline void
70  demean (pcl::PointNormal& p, float value) const
71  {
72  p.curvature -= value;
73  }
74 
75  inline void
76  add (pcl::PointNormal& p, float value) const
77  {
78  p.curvature += value;
79  }
80  };
81 
82  template<>
84  {
85  inline float
87  {
88  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f);
89  }
90 
91  inline void
92  get (const pcl::PointXYZRGB &p, float& intensity) const
93  {
94  intensity = static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f;
95  }
96 
97  inline void
98  set (pcl::PointXYZRGB &p, float intensity) const
99  {
100  p.r = static_cast<uint8_t> (1000 * intensity / 299);
101  p.g = static_cast<uint8_t> (1000 * intensity / 587);
102  p.b = static_cast<uint8_t> (1000 * intensity / 114);
103  }
104 
105  inline void
106  demean (pcl::PointXYZRGB& p, float value) const
107  {
108  float intensity = this->operator () (p);
109  intensity -= value;
110  set (p, intensity);
111  }
112 
113  inline void
114  add (pcl::PointXYZRGB& p, float value) const
115  {
116  float intensity = this->operator () (p);
117  intensity += value;
118  set (p, intensity);
119  }
120  };
121 
122  template<>
124  {
125  inline float
127  {
128  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f);
129  }
130 
131  inline void
132  get (const pcl::PointXYZRGBA &p, float& intensity) const
133  {
134  intensity = static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f;
135  }
136 
137  inline void
138  set (pcl::PointXYZRGBA &p, float intensity) const
139  {
140  p.r = static_cast<uint8_t> (1000 * intensity / 299);
141  p.g = static_cast<uint8_t> (1000 * intensity / 587);
142  p.b = static_cast<uint8_t> (1000 * intensity / 114);
143  }
144 
145  inline void
146  demean (pcl::PointXYZRGBA& p, float value) const
147  {
148  float intensity = this->operator () (p);
149  intensity -= value;
150  set (p, intensity);
151  }
152 
153  inline void
154  add (pcl::PointXYZRGBA& p, float value) const
155  {
156  float intensity = this->operator () (p);
157  intensity += value;
158  set (p, intensity);
159  }
160  };
161  }
162 }
163 
164 #endif