Point Cloud Library (PCL)  1.7.0
intensity.hpp
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  * 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  * $Id$
38  *
39  */
40 
41 #ifndef PCL_COMMON_INTENSITY_FIELD_ACCESSOR_IMPL_HPP
42 #define PCL_COMMON_INTENSITY_FIELD_ACCESSOR_IMPL_HPP
43 
44 #include <pcl/point_types.h>
45 namespace pcl
46 {
47  namespace common
48  {
49  template<>
51  {
52  inline float
54  {
55  return (p.curvature);
56  }
57 
58  inline void
59  get (const pcl::PointNormal &p, float &intensity) const
60  {
61  intensity = p.curvature;
62  }
63 
64  inline void
65  set (pcl::PointNormal &p, float intensity) const
66  {
67  p.curvature = intensity;
68  }
69 
70  inline void
71  demean (pcl::PointNormal& p, float value) const
72  {
73  p.curvature -= value;
74  }
75 
76  inline void
77  add (pcl::PointNormal& p, float value) const
78  {
79  p.curvature += value;
80  }
81  };
82 
83  template<>
85  {
86  inline float
87  operator () (const pcl::PointXYZ &p) const
88  {
89  return (p.z);
90  }
91 
92  inline void
93  get (const pcl::PointXYZ &p, float &intensity) const
94  {
95  intensity = p.z;
96  }
97 
98  inline void
99  set (pcl::PointXYZ &p, float intensity) const
100  {
101  p.z = intensity;
102  }
103 
104  inline void
105  demean (pcl::PointXYZ& p, float value) const
106  {
107  p.z -= value;
108  }
109 
110  inline void
111  add (pcl::PointXYZ& p, float value) const
112  {
113  p.z += value;
114  }
115  };
116 
117  template<>
119  {
120  inline float
122  {
123  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f);
124  }
125 
126  inline void
127  get (const pcl::PointXYZRGB &p, float& intensity) const
128  {
129  intensity = static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f;
130  }
131 
132  inline void
133  set (pcl::PointXYZRGB &p, float intensity) const
134  {
135  p.r = static_cast<uint8_t> (intensity * 3.34448160535f); // 1000 / 299
136  p.g = static_cast<uint8_t> (intensity * 1.70357751278f); // 1000 / 587
137  p.b = static_cast<uint8_t> (intensity * 8.77192982456f); // 1000 / 114
138  }
139 
140  inline void
141  demean (pcl::PointXYZRGB& p, float value) const
142  {
143  float intensity = this->operator () (p);
144  intensity -= value;
145  set (p, intensity);
146  }
147 
148  inline void
149  add (pcl::PointXYZRGB& p, float value) const
150  {
151  float intensity = this->operator () (p);
152  intensity += value;
153  set (p, intensity);
154  }
155  };
156 
157  template<>
159  {
160  inline float
162  {
163  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f);
164  }
165 
166  inline void
167  get (const pcl::PointXYZRGBA &p, float& intensity) const
168  {
169  intensity = static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f;
170  }
171 
172  inline void
173  set (pcl::PointXYZRGBA &p, float intensity) const
174  {
175  p.r = static_cast<uint8_t> (intensity * 3.34448160535f); // 1000 / 299
176  p.g = static_cast<uint8_t> (intensity * 1.70357751278f); // 1000 / 587
177  p.b = static_cast<uint8_t> (intensity * 8.77192982456f); // 1000 / 114
178  }
179 
180  inline void
181  demean (pcl::PointXYZRGBA& p, float value) const
182  {
183  float intensity = this->operator () (p);
184  intensity -= value;
185  set (p, intensity);
186  }
187 
188  inline void
189  add (pcl::PointXYZRGBA& p, float value) const
190  {
191  float intensity = this->operator () (p);
192  intensity += value;
193  set (p, intensity);
194  }
195  };
196 
197  template<>
199  {
200  inline float
202  {
203  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f);
204  }
205 
206  inline void
207  get (const pcl::PointXYZRGBNormal &p, float& intensity) const
208  {
209  intensity = static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f;
210  }
211 
212  inline void
213  set (pcl::PointXYZRGBNormal &p, float intensity) const
214  {
215  p.r = static_cast<uint8_t> (intensity * 3.34448160535f); // 1000 / 299
216  p.g = static_cast<uint8_t> (intensity * 1.70357751278f); // 1000 / 587
217  p.b = static_cast<uint8_t> (intensity * 8.77192982456f); // 1000 / 114
218  }
219 
220  inline void
221  demean (pcl::PointXYZRGBNormal &p, float value) const
222  {
223  float intensity = this->operator () (p);
224  intensity -= value;
225  set (p, intensity);
226  }
227 
228  inline void
229  add (pcl::PointXYZRGBNormal &p, float value) const
230  {
231  float intensity = this->operator () (p);
232  intensity += value;
233  set (p, intensity);
234  }
235  };
236 
237  template<>
239  {
240  inline float
242  {
243  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f);
244  }
245 
246  inline void
247  get (const pcl::PointXYZRGBL &p, float& intensity) const
248  {
249  intensity = static_cast<float> (299*p.r + 587*p.g + 114*p.b) * 0.001f;
250  }
251 
252  inline void
253  set (pcl::PointXYZRGBL &p, float intensity) const
254  {
255  p.r = static_cast<uint8_t> (intensity * 3.34448160535f); // 1000 / 299
256  p.g = static_cast<uint8_t> (intensity * 1.70357751278f); // 1000 / 587
257  p.b = static_cast<uint8_t> (intensity * 8.77192982456f); // 1000 / 114
258  }
259 
260  inline void
261  demean (pcl::PointXYZRGBL& p, float value) const
262  {
263  float intensity = this->operator () (p);
264  intensity -= value;
265  set (p, intensity);
266  }
267 
268  inline void
269  add (pcl::PointXYZRGBL& p, float value) const
270  {
271  float intensity = this->operator () (p);
272  intensity += value;
273  set (p, intensity);
274  }
275  };
276  }
277 }
278 
279 #endif