Skip to content

Commit 4827cfd

Browse files
committed
Address reviewer feedback, expand test.
Signed-off-by: Michael Carroll <[email protected]>
1 parent 9da35fc commit 4827cfd

File tree

3 files changed

+43
-64
lines changed

3 files changed

+43
-64
lines changed

sensor_msgs/include/sensor_msgs/point_cloud_conversion.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ static inline bool convertPointCloud2ToPointCloud(
133133
int y_idx = getPointCloud2FieldIndex(input, "y");
134134
int z_idx = getPointCloud2FieldIndex(input, "z");
135135
if (x_idx == -1 || y_idx == -1 || z_idx == -1) {
136-
std::cerr << "x/y/z coordinates not found! Cannot convert to sensor_msgs::msg::PointCloud!" <<
137-
std::endl;
138136
return false;
139137
}
140138
int x_offset = input.fields[x_idx].offset;

sensor_msgs/include/sensor_msgs/point_field_conversion.hpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -147,61 +147,5 @@ inline T readPointCloud2BufferValue(const unsigned char * data_ptr, const unsign
147147
// This should never be reached, but return statement added to avoid compiler warning. (#84)
148148
return T();
149149
}
150-
151-
/*!
152-
* \Inserts a given value at the given point position interpreted as the datatype
153-
* specified by the template argument point_field_type.
154-
* \param data_ptr pointer into the point cloud 2 buffer
155-
* \param value the value to insert
156-
* \tparam point_field_type sensor_msgs::PointField datatype value
157-
* \tparam T type of the value to insert
158-
*/
159-
template<int point_field_type, typename T>
160-
inline void writePointCloud2BufferValue(unsigned char * data_ptr, T value)
161-
{
162-
typedef typename pointFieldTypeAsType<point_field_type>::type type;
163-
*(reinterpret_cast<type *>(data_ptr)) = static_cast<type>(value);
164-
}
165-
166-
/*!
167-
* \Inserts a given value at the given point position interpreted as the datatype
168-
* specified by the given datatype parameter.
169-
* \param data_ptr pointer into the point cloud 2 buffer
170-
* \param datatype sensor_msgs::PointField datatype value
171-
* \param value the value to insert
172-
* \tparam T type of the value to insert
173-
*/
174-
template<typename T>
175-
inline void writePointCloud2BufferValue(
176-
unsigned char * data_ptr, const unsigned char datatype,
177-
T value)
178-
{
179-
switch (datatype) {
180-
case sensor_msgs::msg::PointField::INT8:
181-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::INT8, T>(data_ptr, value);
182-
break;
183-
case sensor_msgs::msg::PointField::UINT8:
184-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::UINT8, T>(data_ptr, value);
185-
break;
186-
case sensor_msgs::msg::PointField::INT16:
187-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::INT16, T>(data_ptr, value);
188-
break;
189-
case sensor_msgs::msg::PointField::UINT16:
190-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::UINT16, T>(data_ptr, value);
191-
break;
192-
case sensor_msgs::msg::PointField::INT32:
193-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::INT32, T>(data_ptr, value);
194-
break;
195-
case sensor_msgs::msg::PointField::UINT32:
196-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::UINT32, T>(data_ptr, value);
197-
break;
198-
case sensor_msgs::msg::PointField::FLOAT32:
199-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::FLOAT32, T>(data_ptr, value);
200-
break;
201-
case sensor_msgs::msg::PointField::FLOAT64:
202-
writePointCloud2BufferValue<sensor_msgs::msg::PointField::FLOAT64, T>(data_ptr, value);
203-
break;
204-
}
205-
}
206150
} // namespace sensor_msgs
207151
#endif // SENSOR_MSGS__POINT_FIELD_CONVERSION_HPP_

sensor_msgs/test/test_pointcloud.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,63 @@
2323

2424
TEST(PointCloudConversions, CloudToCloud2)
2525
{
26+
// Build a PointCloud
2627
sensor_msgs::msg::PointCloud cloud;
2728

29+
cloud.header.stamp.sec = 100;
30+
cloud.header.stamp.nanosec = 500;
31+
cloud.header.frame_id = "cloud_frame";
32+
33+
sensor_msgs::msg::ChannelFloat32 intensity, range;
34+
intensity.name = "intensity";
35+
range.name = "range";
36+
2837
for (size_t ii = 0; ii < 100; ++ii) {
2938
auto pt = geometry_msgs::msg::Point32();
3039
pt.x = ii;
31-
pt.y = ii;
32-
pt.z = ii;
40+
pt.y = 2 * ii;
41+
pt.z = 3 * ii;
3342
cloud.points.push_back(pt);
43+
44+
intensity.values.push_back(4 * ii);
45+
range.values.push_back(5* ii);
3446
}
47+
cloud.channels.push_back(intensity);
48+
cloud.channels.push_back(range);
3549

50+
// Convert to PointCloud2
3651
sensor_msgs::msg::PointCloud2 cloud2;
37-
38-
auto ret = sensor_msgs::convertPointCloudToPointCloud2(cloud, cloud2);
39-
EXPECT_TRUE(ret);
52+
auto ret_cc2 = sensor_msgs::convertPointCloudToPointCloud2(cloud, cloud2);
53+
ASSERT_TRUE(ret_cc2);
4054

4155
EXPECT_EQ(1u, cloud2.height);
4256
EXPECT_EQ(100u, cloud2.width);
4357

4458
EXPECT_EQ(cloud2.fields[0].name, "x");
4559
EXPECT_EQ(cloud2.fields[1].name, "y");
4660
EXPECT_EQ(cloud2.fields[2].name, "z");
47-
}
61+
EXPECT_EQ(cloud2.fields[3].name, "intensity");
62+
EXPECT_EQ(cloud2.fields[4].name, "range");
4863

64+
EXPECT_EQ(cloud2.fields.size(), 5u);
65+
EXPECT_EQ(cloud2.header.frame_id, "cloud_frame");
66+
EXPECT_EQ(cloud2.header.stamp.sec, 100);
67+
EXPECT_EQ(cloud2.header.stamp.nanosec, 500u);
68+
69+
// Convert back to PointCloud
70+
sensor_msgs::msg::PointCloud cloud3;
71+
auto ret_c2c = sensor_msgs::convertPointCloud2ToPointCloud(cloud2, cloud3);
72+
ASSERT_TRUE(ret_c2c);
73+
EXPECT_EQ(cloud3.points.size(), 100u);
74+
EXPECT_EQ(cloud3.channels.size(), 2u);
75+
76+
EXPECT_EQ(cloud3.channels[0].name, "intensity");
77+
EXPECT_EQ(cloud3.channels[0].values.size(), 100u);
78+
EXPECT_FLOAT_EQ(cloud3.channels[0].values[0], 0.0);
79+
EXPECT_FLOAT_EQ(cloud3.channels[0].values[10], 40.0);
80+
81+
EXPECT_EQ(cloud3.channels[1].name, "range");
82+
EXPECT_EQ(cloud3.channels[1].values.size(), 100u);
83+
EXPECT_FLOAT_EQ(cloud3.channels[1].values[0], 0.0);
84+
EXPECT_FLOAT_EQ(cloud3.channels[1].values[10], 50.0);
85+
}

0 commit comments

Comments
 (0)