Skip to content

Commit 48a8297

Browse files
committed
Test
1 parent 09515be commit 48a8297

File tree

7 files changed

+573
-6
lines changed

7 files changed

+573
-6
lines changed

include/gz/msgs/PointCloudPackedUtils.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "gz/msgs/config.hh"
3232
#include "gz/msgs/detail/PointCloudPackedUtils.hh"
3333

34-
namespace ignition
34+
namespace gz
3535
{
3636
namespace msgs
3737
{

include/gz/msgs/detail/PointCloudPackedUtils.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include "gz/msgs/config.hh"
3030

31-
namespace ignition
31+
namespace gz
3232
{
3333
namespace msgs
3434
{
@@ -437,4 +437,5 @@ int PointCloudPackedIteratorBase<
437437
}
438438
}
439439
}
440+
440441
#endif

include/ignition/msgs/PointCloudPackedUtils.hh

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,127 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*
16-
*/
16+
*/
1717

18-
#include <gz/msgs/PointCloudPackedUtils.hh>
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+
24+
#include <ignition/msgs/pointcloud_packed.pb.h>
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+
{
38+
/// \brief Class that can iterate over a PointCloudPacked message.
39+
///
40+
/// E.g, you create your message and reserve space for data as follows:
41+
///
42+
/// \code{.cpp}
43+
/// ignition::msgs::PointCloudPacked pcMsg;
44+
/// ignition::msgs::InitPointCloudPacked(pcMsg, "my_new_frame", false,
45+
/// {{"a", PointCloudPacked::Field::FLOAT32}});
46+
/// pcMsg.mutable_data()->resize(numPts * pcMsg.point_step());
47+
/// \endcode
48+
///
49+
/// For iterating over "a", you do :
50+
///
51+
/// \code{.cpp}
52+
/// ignition::msgs::PointCloudPackedIterator<float> iterA(pcMsg, "a");
53+
/// \endcode
54+
///
55+
/// And then access it through iterA[0] or *iterA.
56+
///
57+
/// For iterating over RGBA, you can access each element as uint8_t:
58+
///
59+
/// \code{.cpp}
60+
/// ignition::msgs::PointCloudPackedIterator<uint8_t> iterR(pcMsg, "r");
61+
/// ignition::msgs::PointCloudPackedIterator<uint8_t> iterG(pcMsg, "g");
62+
/// ignition::msgs::PointCloudPackedIterator<uint8_t> iterB(pcMsg, "b");
63+
/// ignition::msgs::PointCloudPackedIterator<uint8_t> iterA(pcMsg, "a");
64+
/// \endcode
65+
///
66+
/// \tparam FieldType Type of the element being iterated upon
67+
template<typename FieldType>
68+
class PointCloudPackedIterator
69+
: public PointCloudPackedIteratorBase<
70+
FieldType, FieldType, char, PointCloudPacked, PointCloudPackedIterator>
71+
{
72+
// Documentation inherited
73+
public: PointCloudPackedIterator(PointCloudPacked &_cloudMsg,
74+
const std::string &_fieldName)
75+
: PointCloudPackedIteratorBase<FieldType, FieldType, char,
76+
PointCloudPacked, PointCloudPackedIterator>
77+
::PointCloudPackedIteratorBase(_cloudMsg, _fieldName)
78+
{
79+
}
80+
};
81+
82+
/// \brief Same as a PointCloudPackedIterator but for const data
83+
/// \tparam FieldType Type of the element being iterated upon
84+
template<typename FieldType>
85+
class PointCloudPackedConstIterator
86+
: public PointCloudPackedIteratorBase<
87+
FieldType, const FieldType, const char, const PointCloudPacked,
88+
PointCloudPackedConstIterator>
89+
{
90+
public: PointCloudPackedConstIterator(
91+
const PointCloudPacked &_cloudMsg,
92+
const std::string &_fieldName)
93+
: PointCloudPackedIteratorBase<FieldType, const FieldType, const char,
94+
const PointCloudPacked,
95+
PointCloudPackedConstIterator
96+
>::PointCloudPackedIteratorBase(_cloudMsg, _fieldName)
97+
{
98+
}
99+
};
100+
101+
/// \brief Return the size of a datatype (which is an enum of
102+
/// ignition::msgs::PointCloudPacked::Field) in bytes.
103+
/// \param[in] _dataType One of the enums of
104+
/// ignition::msgs::PointCloudPacked::Field
105+
/// \return Size in bytes. Returns -1 if the type is unknown.
106+
inline int sizeOfPointField(
107+
PointCloudPacked::Field::DataType _dataType)
108+
{
109+
if ((_dataType == PointCloudPacked::Field::INT8) ||
110+
(_dataType == PointCloudPacked::Field::UINT8))
111+
{
112+
return 1;
113+
}
114+
else if ((_dataType == PointCloudPacked::Field::INT16) ||
115+
(_dataType == PointCloudPacked::Field::UINT16))
116+
{
117+
return 2;
118+
}
119+
else if ((_dataType == PointCloudPacked::Field::INT32) ||
120+
(_dataType == PointCloudPacked::Field::UINT32) ||
121+
(_dataType == PointCloudPacked::Field::FLOAT32))
122+
{
123+
return 4;
124+
}
125+
else if (_dataType == PointCloudPacked::Field::FLOAT64)
126+
{
127+
return 8;
128+
}
129+
else
130+
{
131+
std::cerr << "PointCloudPacked::Field of type [" << _dataType
132+
<< "] does not exist" << std::endl;
133+
}
134+
return -1;
135+
}
136+
}
137+
}
138+
139+
#endif

0 commit comments

Comments
 (0)