@@ -121,6 +121,10 @@ PointCloud2Iterators prepareMessageAndCreateIterators(sensor_msgs::PointCloud2&
121
121
else if (fill_fields_up_to_stage == CONTINUOUS_CLUSTERING)
122
122
up_to_field = 25 ;
123
123
124
+ // Some point fields below should be actually UINT64. Unfortunately, this type is not available for a PointCloud2
125
+ // message: http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/PointField.html. Therefore, we use FLOAT64 which
126
+ // is able to store higher integers than UINT32 (2^52 vs 2^32); these fields are marked with (*)
127
+
124
128
sensor_msgs::PointCloud2Modifier output_modifier (msg);
125
129
output_modifier.setPointCloud2Fields (up_to_field,
126
130
" x" ,
@@ -134,13 +138,13 @@ PointCloud2Iterators prepareMessageAndCreateIterators(sensor_msgs::PointCloud2&
134
138
sensor_msgs::PointField::FLOAT32,
135
139
" firing_index" ,
136
140
1 ,
137
- sensor_msgs::PointField::UINT32,
141
+ sensor_msgs::PointField::FLOAT64, // (*)
138
142
" intensity" ,
139
143
1 ,
140
144
sensor_msgs::PointField::UINT8,
141
145
" globally_unique_point_index" ,
142
146
1 ,
143
- sensor_msgs::PointField::FLOAT64,
147
+ sensor_msgs::PointField::FLOAT64, // (*)
144
148
" time_sec" ,
145
149
1 ,
146
150
sensor_msgs::PointField::UINT32,
@@ -161,7 +165,7 @@ PointCloud2Iterators prepareMessageAndCreateIterators(sensor_msgs::PointCloud2&
161
165
sensor_msgs::PointField::FLOAT64,
162
166
" global_column_index" ,
163
167
1 ,
164
- sensor_msgs::PointField::UINT32,
168
+ sensor_msgs::PointField::FLOAT64, // (*)
165
169
" local_column_index" ,
166
170
1 ,
167
171
sensor_msgs::PointField::UINT16,
@@ -188,16 +192,16 @@ PointCloud2Iterators prepareMessageAndCreateIterators(sensor_msgs::PointCloud2&
188
192
sensor_msgs::PointField::UINT16,
189
193
" tree_root_column_index" ,
190
194
1 ,
191
- sensor_msgs::PointField::UINT8,
195
+ sensor_msgs::PointField::FLOAT64, // (*)
192
196
" number_of_visited_neighbors" ,
193
197
1 ,
194
198
sensor_msgs::PointField::UINT32,
195
199
" tree_id" ,
196
200
1 ,
197
- sensor_msgs::PointField::UINT32,
201
+ sensor_msgs::PointField::FLOAT64, // (*)
198
202
" id" ,
199
203
1 ,
200
- sensor_msgs::PointField::UINT32);
204
+ sensor_msgs::PointField::FLOAT64); // (*)
201
205
202
206
PointCloud2Iterators iterators;
203
207
iterators.iter_x_out = {msg, " x" };
@@ -243,14 +247,17 @@ void addPointToMessage(PointCloud2Iterators& container,
243
247
ros::Time stamp;
244
248
stamp.fromNSec (point.stamp );
245
249
250
+ // Some point fields below should be actually UINT64. Unfortunately, this type is not available for a PointCloud2
251
+ // message: http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/PointField.html. Therefore, we use FLOAT64 which
252
+ // is able to store higher integers than UINT32 (2^52 vs 2^32); these fields are marked with (*)
253
+
246
254
// raw point
247
255
*(*container.iter_x_out + data_index_message) = point.xyz .x ;
248
256
*(*container.iter_y_out + data_index_message) = point.xyz .y ;
249
257
*(*container.iter_z_out + data_index_message) = point.xyz .z ;
250
- *(*container.iter_f_out + data_index_message) = static_cast <uint32_t >(point.firing_index );
258
+ *(*container.iter_f_out + data_index_message) = static_cast <double >(point.firing_index ); // (*)
251
259
*(*container.iter_i_out + data_index_message) = point.intensity ;
252
- *(*container.iter_gpi_out + data_index_message) =
253
- *reinterpret_cast <const double *>(&point.globally_unique_point_index ); // PointCloud2 does not support UINT64
260
+ *(*container.iter_gpi_out + data_index_message) = static_cast <double >(point.globally_unique_point_index ); // (*)
254
261
*(*container.iter_time_sec_out + data_index_message) = stamp.sec ;
255
262
*(*container.iter_time_nsec_out + data_index_message) = stamp.nsec ;
256
263
if (fill_fields_up_to_stage == RAW_POINT)
@@ -261,7 +268,7 @@ void addPointToMessage(PointCloud2Iterators& container,
261
268
*(*container.iter_a_out + data_index_message) = point.azimuth_angle ;
262
269
*(*container.iter_ia_out + data_index_message) = point.inclination_angle ;
263
270
*(*container.iter_ca_out + data_index_message) = point.continuous_azimuth_angle ;
264
- *(*container.iter_gc_out + data_index_message) = point.global_column_index ;
271
+ *(*container.iter_gc_out + data_index_message) = static_cast < double >( point.global_column_index ); // (*)
265
272
*(*container.iter_lc_out + data_index_message) = point.local_column_index ;
266
273
*(*container.iter_r_out + data_index_message) = point.row_index ;
267
274
if (fill_fields_up_to_stage == RANGE_IMAGE_GENERATION)
@@ -278,22 +285,26 @@ void addPointToMessage(PointCloud2Iterators& container,
278
285
*(*container.iter_finished_at_azimuth_angle + data_index_message) = point.finished_at_continuous_azimuth_angle ;
279
286
*(*container.iter_num_child_points + data_index_message) = point.child_points .size ();
280
287
*(*container.iter_tree_root_row_index + data_index_message) = point.tree_root_ .row_index ;
281
- *(*container.iter_tree_root_column_index + data_index_message) = point.tree_root_ .column_index ;
288
+ *(*container.iter_tree_root_column_index + data_index_message) =
289
+ static_cast <double >(point.tree_root_ .column_index ); // (*)
282
290
*(*container.iter_number_of_visited_neighbors + data_index_message) = point.number_of_visited_neighbors ;
283
291
*(*container.iter_tree_id + data_index_message) =
284
- static_cast <uint32_t >(point.tree_root_ .column_index * num_rows + point.tree_root_ .row_index );
285
- *(*container.iter_id + data_index_message) = point.id ;
292
+ static_cast <double >(point.tree_root_ .column_index * num_rows + point.tree_root_ .row_index ); // (*)
293
+ *(*container.iter_id + data_index_message) = static_cast < double >( point.id ); // (*)
286
294
}
287
295
288
296
void addRawPointToMessage (PointCloud2Iterators& container, int data_index_message, const RawPoint& point)
289
297
{
298
+ // Some point fields below should be actually UINT64. Unfortunately, this type is not available for a PointCloud2
299
+ // message: http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/PointField.html. Therefore, we use FLOAT64 which
300
+ // is able to store higher integers than UINT32 (2^52 vs 2^32); these fields are marked with (*)
301
+
290
302
*(*container.iter_x_out + data_index_message) = point.x ;
291
303
*(*container.iter_y_out + data_index_message) = point.y ;
292
304
*(*container.iter_z_out + data_index_message) = point.z ;
293
- *(*container.iter_f_out + data_index_message) = static_cast <uint32_t >(point.firing_index );
305
+ *(*container.iter_f_out + data_index_message) = static_cast <double >(point.firing_index ); // (*)
294
306
*(*container.iter_i_out + data_index_message) = point.intensity ;
295
- *(*container.iter_gpi_out + data_index_message) =
296
- *reinterpret_cast <const double *>(&point.globally_unique_point_index ); // PointCloud2 does not support UINT64
307
+ *(*container.iter_gpi_out + data_index_message) = static_cast <double >(point.globally_unique_point_index ); // (*)
297
308
298
309
ros::Time t;
299
310
t.fromNSec (point.stamp );
0 commit comments