point_field_conversion.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Robot Operating System code by the University of Osnabrück
5  * Copyright (c) 2015, University of Osnabrück
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer.
15  *
16  * 2. 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  *
21  * 3. Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  *
39  *
40  * point_field_conversion.h
41  *
42  * Created on: 16.07.2015
43  * Authors: Sebastian Pütz <spuetz@uni-osnabrueck.de>
44  */
45 
46 #ifndef SENSOR_MSGS_POINT_FIELD_CONVERSION_H
47 #define SENSOR_MSGS_POINT_FIELD_CONVERSION_H
48 
55 namespace sensor_msgs{
59  template<int> struct pointFieldTypeAsType {};
60  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::INT8> { typedef int8_t type; };
66  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::FLOAT32> { typedef float type; };
67  template<> struct pointFieldTypeAsType<sensor_msgs::PointField::FLOAT64> { typedef double type; };
68 
72  template<typename T> struct typeAsPointFieldType {};
73  template<> struct typeAsPointFieldType<int8_t> { static const uint8_t value = sensor_msgs::PointField::INT8; };
79  template<> struct typeAsPointFieldType<float> { static const uint8_t value = sensor_msgs::PointField::FLOAT32; };
80  template<> struct typeAsPointFieldType<double> { static const uint8_t value = sensor_msgs::PointField::FLOAT64; };
81 
90  template<int point_field_type, typename T>
91  inline T readPointCloud2BufferValue(const unsigned char* data_ptr){
93  return static_cast<T>(*(reinterpret_cast<type const *>(data_ptr)));
94  }
95 
103  template<typename T>
104  inline T readPointCloud2BufferValue(const unsigned char* data_ptr, const unsigned char datatype){
105  switch(datatype){
107  return readPointCloud2BufferValue<sensor_msgs::PointField::INT8, T>(data_ptr);
109  return readPointCloud2BufferValue<sensor_msgs::PointField::UINT8, T>(data_ptr);
111  return readPointCloud2BufferValue<sensor_msgs::PointField::INT16, T>(data_ptr);
113  return readPointCloud2BufferValue<sensor_msgs::PointField::UINT16, T>(data_ptr);
115  return readPointCloud2BufferValue<sensor_msgs::PointField::INT32, T>(data_ptr);
117  return readPointCloud2BufferValue<sensor_msgs::PointField::UINT32, T>(data_ptr);
119  return readPointCloud2BufferValue<sensor_msgs::PointField::FLOAT32, T>(data_ptr);
121  return readPointCloud2BufferValue<sensor_msgs::PointField::FLOAT64, T>(data_ptr);
122  }
123  }
124 
133  template<int point_field_type, typename T>
134  inline void writePointCloud2BufferValue(unsigned char* data_ptr, T value){
136  *(reinterpret_cast<type*>(data_ptr)) = static_cast<type>(value);
137  }
138 
147  template<typename T>
148  inline void writePointCloud2BufferValue(unsigned char* data_ptr, const unsigned char datatype, T value){
149  switch(datatype){
151  writePointCloud2BufferValue<sensor_msgs::PointField::INT8, T>(data_ptr, value);
152  break;
154  writePointCloud2BufferValue<sensor_msgs::PointField::UINT8, T>(data_ptr, value);
155  break;
157  writePointCloud2BufferValue<sensor_msgs::PointField::INT16, T>(data_ptr, value);
158  break;
160  writePointCloud2BufferValue<sensor_msgs::PointField::UINT16, T>(data_ptr, value);
161  break;
163  writePointCloud2BufferValue<sensor_msgs::PointField::INT32, T>(data_ptr, value);
164  break;
166  writePointCloud2BufferValue<sensor_msgs::PointField::UINT32, T>(data_ptr, value);
167  break;
169  writePointCloud2BufferValue<sensor_msgs::PointField::FLOAT32, T>(data_ptr, value);
170  break;
172  writePointCloud2BufferValue<sensor_msgs::PointField::FLOAT64, T>(data_ptr, value);
173  break;
174  }
175  }
176 }
177 
178 #endif /* point_field_conversion.h */
GLfloat value
unsigned short uint16_t
Definition: stdint.h:79
void writePointCloud2BufferValue(unsigned char *data_ptr, T value)
unsigned char uint8_t
Definition: stdint.h:78
const char * datatype()
returns DataType<M>::value();
unsigned int uint32_t
Definition: stdint.h:80
Tools for manipulating sensor_msgs.
Definition: BatteryState.h:20
signed short int16_t
Definition: stdint.h:76
signed char int8_t
Definition: stdint.h:75
GLenum type
T readPointCloud2BufferValue(const unsigned char *data_ptr)
signed int int32_t
Definition: stdint.h:77


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39