point_field_conversion.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * Software License Agreement (BSD License)
4  *
5  * Robot Operating System code by the University of Osnabrueck
6  * Copyright (c) 2015, University of Osnabrueck
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  * 1. Redistributions of source code must retain the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  *
22  * 3. Neither the name of the copyright holder nor the names of its
23  * contributors may be used to endorse or promote products derived
24  * from this software without specific prior written permission.
25  *
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
31  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  *
40  *
41  * point_field_conversion.h
42  *
43  * Created on: 16.07.2015
44  * Authors: Sebastian Pütz <spuetz@uni-osnabrueck.de>
45  */
46 
47 #ifndef SENSOR_MSGS_POINT_FIELD_CONVERSION_H
48 #define SENSOR_MSGS_POINT_FIELD_CONVERSION_H
49 
56 namespace sensor_msgs{
60  template<int> struct pointFieldTypeAsType {};
61  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::INT8> { typedef int8_t type; };
62  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::UINT8> { typedef uint8_t type; };
63  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::INT16> { typedef int16_t type; };
64  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::UINT16> { typedef uint16_t type; };
65  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::INT32> { typedef int32_t type; };
66  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::UINT32> { typedef uint32_t type; };
67  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::FLOAT32> { typedef float type; };
68  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::FLOAT64> { typedef double type; };
69 
73  template<typename T> struct typeAsPointFieldType {};
74  template<> struct typeAsPointFieldType<int8_t> { static const uint8_t value = sensor_msgs::PointField::INT8; };
75  template<> struct typeAsPointFieldType<uint8_t> { static const uint8_t value = sensor_msgs::PointField::UINT8; };
76  template<> struct typeAsPointFieldType<int16_t> { static const uint8_t value = sensor_msgs::PointField::INT16; };
77  template<> struct typeAsPointFieldType<uint16_t> { static const uint8_t value = sensor_msgs::PointField::UINT16; };
78  template<> struct typeAsPointFieldType<int32_t> { static const uint8_t value = sensor_msgs::PointField::INT32; };
79  template<> struct typeAsPointFieldType<uint32_t> { static const uint8_t value = sensor_msgs::PointField::UINT32; };
80  template<> struct typeAsPointFieldType<float> { static const uint8_t value = sensor_msgs::PointField::FLOAT32; };
81  template<> struct typeAsPointFieldType<double> { static const uint8_t value = sensor_msgs::PointField::FLOAT64; };
82 
91  template<int point_field_type, typename T>
92  inline T readPointCloud2BufferValue(const unsigned char* data_ptr){
94  return static_cast<T>(*(reinterpret_cast<type const *>(data_ptr)));
95  }
96 
104  template<typename T>
105  inline T readPointCloud2BufferValue(const unsigned char* data_ptr, const unsigned char datatype){
106  switch(datatype){
108  return readPointCloud2BufferValue<sensor_msgs::PointField::INT8, T>(data_ptr);
110  return readPointCloud2BufferValue<sensor_msgs::PointField::UINT8, T>(data_ptr);
112  return readPointCloud2BufferValue<sensor_msgs::PointField::INT16, T>(data_ptr);
114  return readPointCloud2BufferValue<sensor_msgs::PointField::UINT16, T>(data_ptr);
116  return readPointCloud2BufferValue<sensor_msgs::PointField::INT32, T>(data_ptr);
118  return readPointCloud2BufferValue<sensor_msgs::PointField::UINT32, T>(data_ptr);
120  return readPointCloud2BufferValue<sensor_msgs::PointField::FLOAT32, T>(data_ptr);
122  return readPointCloud2BufferValue<sensor_msgs::PointField::FLOAT64, T>(data_ptr);
123  }
124  }
125 
134  template<int point_field_type, typename T>
135  inline void writePointCloud2BufferValue(unsigned char* data_ptr, T value){
137  *(reinterpret_cast<type*>(data_ptr)) = static_cast<type>(value);
138  }
139 
148  template<typename T>
149  inline void writePointCloud2BufferValue(unsigned char* data_ptr, const unsigned char datatype, T value){
150  switch(datatype){
152  writePointCloud2BufferValue<sensor_msgs::PointField::INT8, T>(data_ptr, value);
153  break;
155  writePointCloud2BufferValue<sensor_msgs::PointField::UINT8, T>(data_ptr, value);
156  break;
158  writePointCloud2BufferValue<sensor_msgs::PointField::INT16, T>(data_ptr, value);
159  break;
161  writePointCloud2BufferValue<sensor_msgs::PointField::UINT16, T>(data_ptr, value);
162  break;
164  writePointCloud2BufferValue<sensor_msgs::PointField::INT32, T>(data_ptr, value);
165  break;
167  writePointCloud2BufferValue<sensor_msgs::PointField::UINT32, T>(data_ptr, value);
168  break;
170  writePointCloud2BufferValue<sensor_msgs::PointField::FLOAT32, T>(data_ptr, value);
171  break;
173  writePointCloud2BufferValue<sensor_msgs::PointField::FLOAT64, T>(data_ptr, value);
174  break;
175  }
176  }
177 }
178 
179 #endif /* point_field_conversion.h */
sensor_msgs::PointField_::UINT8
@ UINT8
Definition: PointField.h:57
sensor_msgs::PointField_::INT16
@ INT16
Definition: PointField.h:58
roswrap::message_traits::datatype
const char * datatype()
returns DataType<M>::value();
Definition: message_traits.h:236
test_server.type
type
Definition: test_server.py:210
sensor_msgs::PointField_::FLOAT64
@ FLOAT64
Definition: PointField.h:63
sensor_msgs::PointField_::UINT32
@ UINT32
Definition: PointField.h:61
sensor_msgs::writePointCloud2BufferValue
void writePointCloud2BufferValue(unsigned char *data_ptr, const unsigned char datatype, T value)
Definition: point_field_conversion.h:149
sensor_msgs::PointField_::INT8
@ INT8
Definition: PointField.h:56
sensor_msgs::PointField_::FLOAT32
@ FLOAT32
Definition: PointField.h:62
sensor_msgs::PointField_::INT32
@ INT32
Definition: PointField.h:60
sick_scan_base.h
sensor_msgs
Tools for manipulating sensor_msgs.
sensor_msgs::PointField_::UINT16
@ UINT16
Definition: PointField.h:59
sensor_msgs::readPointCloud2BufferValue
T readPointCloud2BufferValue(const unsigned char *data_ptr)
Definition: point_field_conversion.h:92


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:09