Ignition Msgs

API Reference

7.2.0
PointCloudPackedUtils.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 // Inspired by
19 // https://github.com/ros/common_msgs/blob/275b09a/sensor_msgs/include/sensor_msgs/point_cloud2_iterator.h
20 
21 #ifndef IGNITION_MSGS_POINTCLOUDPACKEDUTILS_HH_
22 #define IGNITION_MSGS_POINTCLOUDPACKEDUTILS_HH_
23 
25 
26 #include <cstdarg>
27 #include <sstream>
28 #include <string>
29 #include <vector>
30 
31 #include "ignition/msgs/config.hh"
32 #include "ignition/msgs/detail/PointCloudPackedUtils.hh"
33 
34 namespace ignition
35 {
36 namespace msgs
37 {
66 template<typename FieldType>
68  : public PointCloudPackedIteratorBase<
69  FieldType, FieldType, char, PointCloudPacked, PointCloudPackedIterator>
70 {
71  // Documentation inherited
73  const std::string &_fieldName)
74  : PointCloudPackedIteratorBase<FieldType, FieldType, char,
76  ::PointCloudPackedIteratorBase(_cloudMsg, _fieldName)
77  {
78  }
79 };
80 
83 template<typename FieldType>
85  : public PointCloudPackedIteratorBase<
86  FieldType, const FieldType, const char, const PointCloudPacked,
87  PointCloudPackedConstIterator>
88 {
90  const PointCloudPacked &_cloudMsg,
91  const std::string &_fieldName)
92  : PointCloudPackedIteratorBase<FieldType, const FieldType, const char,
93  const PointCloudPacked,
95  >::PointCloudPackedIteratorBase(_cloudMsg, _fieldName)
96  {
97  }
98 };
99 
105 inline int sizeOfPointField(
107 {
108  if ((_dataType == PointCloudPacked::Field::INT8) ||
109  (_dataType == PointCloudPacked::Field::UINT8))
110  {
111  return 1;
112  }
113  else if ((_dataType == PointCloudPacked::Field::INT16) ||
114  (_dataType == PointCloudPacked::Field::UINT16))
115  {
116  return 2;
117  }
118  else if ((_dataType == PointCloudPacked::Field::INT32) ||
119  (_dataType == PointCloudPacked::Field::UINT32) ||
120  (_dataType == PointCloudPacked::Field::FLOAT32))
121  {
122  return 4;
123  }
124  else if (_dataType == PointCloudPacked::Field::FLOAT64)
125  {
126  return 8;
127  }
128  else
129  {
130  std::cerr << "PointCloudPacked::Field of type [" << _dataType
131  << "] does not exist" << std::endl;
132  }
133  return -1;
134 }
135 }
136 }
137 
138 #endif
static const DataType UINT16
Definition: pointcloud_packed.pb.h:150
static const DataType UINT32
Definition: pointcloud_packed.pb.h:154
T endl(T... args)
PointCloudPackedConstIterator(const PointCloudPacked &_cloudMsg, const std::string &_fieldName)
Definition: PointCloudPackedUtils.hh:89
PointCloudPackedIterator(PointCloudPacked &_cloudMsg, const std::string &_fieldName)
Definition: PointCloudPackedUtils.hh:72
STL class.
static const DataType FLOAT64
Definition: pointcloud_packed.pb.h:158
static const DataType INT8
Definition: pointcloud_packed.pb.h:144
static const DataType INT16
Definition: pointcloud_packed.pb.h:148
PointCloudPacked_Field_DataType
Definition: pointcloud_packed.pb.h:56
Class that can iterate over a PointCloudPacked message.
Definition: PointCloudPackedUtils.hh:67
Definition: pointcloud_packed.pb.h:231
static const DataType FLOAT32
Definition: pointcloud_packed.pb.h:156
int sizeOfPointField(PointCloudPacked::Field::DataType _dataType)
Return the size of a datatype (which is an enum of PointCloudPacked::Field) in bytes.
Definition: PointCloudPackedUtils.hh:105
Same as a PointCloudPackedIterator but for const data.
Definition: PointCloudPackedUtils.hh:84
static const DataType INT32
Definition: pointcloud_packed.pb.h:152
static const DataType UINT8
Definition: pointcloud_packed.pb.h:146