Skip to content

Commit 8e872f3

Browse files
committed
Fix CMake
1 parent 09515be commit 8e872f3

File tree

9 files changed

+652
-78
lines changed

9 files changed

+652
-78
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/Utility.hh

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@
3535

3636
/// \file Utility.hh
3737
/// \brief Utility functions that support conversion between message type
38-
/// and ignition math types.
39-
40-
namespace ignition
38+
/// and gz math types.
39+
namespace gz
4140
{
4241
namespace msgs
4342
{
@@ -68,11 +67,11 @@ namespace ignition
6867
IGNITION_MSGS_VISIBLE
6968
ignition::math::Pose3d Convert(const msgs::Pose &_p);
7069

71-
/// \brief Convert a msgs::Color to a math::Color
70+
/// \brief Convert a msgs::Color to a ignition::math::Color
7271
/// \param[in] _c The color to convert
73-
/// \return A math::Color object
72+
/// \return A ignition::math::Color object
7473
IGNITION_MSGS_VISIBLE
75-
math::Color Convert(const msgs::Color &_c);
74+
ignition::math::Color Convert(const msgs::Color &_c);
7675

7776
/// \brief Convert a msgs::PlaneGeom to an ignition::math::Planed
7877
/// \param[in] _p The plane to convert
@@ -84,29 +83,29 @@ namespace ignition
8483
/// \param[in] _i The inertial to convert
8584
/// \return An ignition::math::Inertiald object
8685
IGNITION_MSGS_VISIBLE
87-
math::Inertiald Convert(const msgs::Inertial &_i);
86+
ignition::math::Inertiald Convert(const msgs::Inertial &_i);
8887

8988
/// \brief Convert a msgs::SphericalCoordinates to an
9089
/// ignition::math::SphericalCoordinates
9190
/// \param[in] _coord The spherical coordinates to convert
9291
/// \return An ignition::math::SphericalCoordinates object
9392
IGNITION_MSGS_VISIBLE
94-
math::SphericalCoordinates Convert(
93+
ignition::math::SphericalCoordinates Convert(
9594
const msgs::SphericalCoordinates &_coord);
9695

9796
/// \brief Convert a msgs::AxisAlignedBox to an
9897
/// ignition::math::AxisAlignedBox
9998
/// \param[in] _b The axis aligned box to convert
10099
/// \return An ignition::math::AxisAlignedBox object
101100
IGNITION_MSGS_VISIBLE
102-
math::AxisAlignedBox Convert(const msgs::AxisAlignedBox &_b);
101+
ignition::math::AxisAlignedBox Convert(const msgs::AxisAlignedBox &_b);
103102

104103
/// \brief Convert ignition::math::AxisAlignedBox to
105104
/// msgs::AxisAlignedBox.
106105
/// \param[in] _b The axis aligned box to convert
107106
/// \return An ignition::math::AxisAlignedBox object
108107
IGNITION_MSGS_VISIBLE
109-
msgs::AxisAlignedBox Convert(const math::AxisAlignedBox &_b);
108+
msgs::AxisAlignedBox Convert(const ignition::math::AxisAlignedBox &_b);
110109

111110
/// \brief Convert a msgs::StringMsg to an std::string
112111
/// \param[in] _m The message to convert
@@ -186,31 +185,31 @@ namespace ignition
186185
IGNITION_MSGS_VISIBLE
187186
msgs::Pose Convert(const ignition::math::Pose3d &_p);
188187

189-
/// \brief Convert a math::Color to a msgs::Color
188+
/// \brief Convert a ignition::math::Color to a msgs::Color
190189
/// \param[in] _c The color to convert
191190
/// \return A msgs::Color object
192191
IGNITION_MSGS_VISIBLE
193-
msgs::Color Convert(const math::Color &_c);
192+
msgs::Color Convert(const ignition::math::Color &_c);
194193

195-
/// \brief Convert an math::Inertiald to a msgs::Inertial
194+
/// \brief Convert an ignition::math::Inertiald to a msgs::Inertial
196195
/// \param[in] _i The Inertiald to convert
197196
/// \return A msgs::Inertial object
198197
IGNITION_MSGS_VISIBLE
199-
msgs::Inertial Convert(const math::Inertiald &_i);
198+
msgs::Inertial Convert(const ignition::math::Inertiald &_i);
200199

201-
/// \brief Convert an math::MassMatrix3d to a msgs::Inertial
200+
/// \brief Convert an ignition::math::MassMatrix3d to a msgs::Inertial
202201
/// \param[in] _m The MassMatrix3d to convert
203202
/// \return A msgs::Inertial object
204203
IGNITION_MSGS_VISIBLE
205-
msgs::Inertial Convert(const math::MassMatrix3d &_m);
204+
msgs::Inertial Convert(const ignition::math::MassMatrix3d &_m);
206205

207-
/// \brief Convert an math::SphericalCoordinates to a
206+
/// \brief Convert an ignition::math::SphericalCoordinates to a
208207
/// msgs::SphericalCoordinates
209208
/// \param[in] _coord The SphericalCoordinates to convert
210209
/// \return A msgs::SphericalCoordinates object
211210
IGNITION_MSGS_VISIBLE
212211
msgs::SphericalCoordinates Convert(
213-
const math::SphericalCoordinates &_coord);
212+
const ignition::math::SphericalCoordinates &_coord);
214213

215214
/// \brief Convert a ignition::math::Planed to a msgs::PlaneGeom
216215
/// \param[in] _p The plane to convert
@@ -351,31 +350,31 @@ namespace ignition
351350
IGNITION_MSGS_VISIBLE
352351
void Set(msgs::Pose *_p, const ignition::math::Pose3d &_v);
353352

354-
/// \brief Set a msgs::Color from a math::Color
353+
/// \brief Set a msgs::Color from a ignition::math::Color
355354
/// \param[out] _c A msgs::Color pointer
356-
/// \param[in] _v A math::Color reference
355+
/// \param[in] _v A ignition::math::Color reference
357356
IGNITION_MSGS_VISIBLE
358-
void Set(msgs::Color *_c, const math::Color &_v);
357+
void Set(msgs::Color *_c, const ignition::math::Color &_v);
359358

360-
/// \brief Set a msgs::Inertial from an math::Inertiald
359+
/// \brief Set a msgs::Inertial from an ignition::math::Inertiald
361360
/// \param[out] _i A msgs::Inertial pointer
362-
/// \param[in] _m An math::Inertiald reference
361+
/// \param[in] _m An ignition::math::Inertiald reference
363362
IGNITION_MSGS_VISIBLE
364-
void Set(msgs::Inertial *_i, const math::Inertiald &_m);
363+
void Set(msgs::Inertial *_i, const ignition::math::Inertiald &_m);
365364

366-
/// \brief Set a msgs::Inertial from an math::MassMatrix3d
365+
/// \brief Set a msgs::Inertial from an ignition::math::MassMatrix3d
367366
/// \param[out] _i A msgs::Inertial pointer
368-
/// \param[in] _m An math::MassMatrix3d reference
367+
/// \param[in] _m An ignition::math::MassMatrix3d reference
369368
IGNITION_MSGS_VISIBLE
370-
void Set(msgs::Inertial *_i, const math::MassMatrix3d &_m);
369+
void Set(msgs::Inertial *_i, const ignition::math::MassMatrix3d &_m);
371370

372371
/// \brief Set a msgs::SphericalCoordinates from a
373-
/// math::SphericalCoordinates
372+
/// ignition::math::SphericalCoordinates
374373
/// \param[out] _sc A msgs::SphericalCoordinates pointer
375-
/// \param[in] _m An math::SphericalCoordinates reference
374+
/// \param[in] _m An ignition::math::SphericalCoordinates reference
376375
IGNITION_MSGS_VISIBLE
377376
void Set(msgs::SphericalCoordinates *_sc,
378-
const math::SphericalCoordinates &_m);
377+
const ignition::math::SphericalCoordinates &_m);
379378

380379
/// \brief Set a msgs::Plane from an ignition::math::Planed
381380
/// \param[out] _p A msgs::Plane pointer
@@ -431,11 +430,11 @@ namespace ignition
431430
IGNITION_MSGS_VISIBLE
432431
void Set(msgs::Float *_p, const float &_v);
433432

434-
/// \brief Set a msgs::AxisAlignedBox from a math::AxisAlignedBox
433+
/// \brief Set a msgs::AxisAlignedBox from a ignition::math::AxisAlignedBox
435434
/// \param[out] _b A msgs::AxisAlignedBox pointer
436-
/// \param[in] _v An math::AxisAlignedBox reference
435+
/// \param[in] _v An ignition::math::AxisAlignedBox reference
437436
IGNITION_MSGS_VISIBLE
438-
void Set(msgs::AxisAlignedBox *_b, const math::AxisAlignedBox &_v);
437+
void Set(msgs::AxisAlignedBox *_b, const ignition::math::AxisAlignedBox &_v);
439438

440439
/// \brief This function will set the header and field members of
441440
/// a PointCloudPacked message. This will clear existing values in the

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)