8
8
#include < continuous_clustering/evaluation/kitti_loader.hpp>
9
9
#include < continuous_clustering/utils/command_line_parser.hpp>
10
10
11
+ using Path = std::filesystem::path;
12
+
13
+ using namespace continuous_clustering ;
14
+ using namespace std ::chrono_literals;
15
+
11
16
#ifdef WITH_ROS
12
17
#include < ros/ros.h>
13
18
#include < rosgraph_msgs/Clock.h>
14
- #include < visualization_msgs/Marker.h>
15
19
16
20
#include < continuous_clustering/ros/ros_utils.hpp>
17
- #endif
18
21
19
- using Path = std::filesystem::path;
22
+ class ROSInterface
23
+ {
24
+ public:
25
+ void init ()
26
+ {
27
+ pub_clock = nh.advertise <rosgraph_msgs::Clock>(" /clock" , 100 );
28
+ pub_firing =
29
+ nh.advertise <sensor_msgs::PointCloud2>(" /perception/detections/lidar_roof/cluster/raw_firings" , 1000 );
30
+ pub_column_ground = nh.advertise <sensor_msgs::PointCloud2>(
31
+ " /perception/detections/lidar_roof/cluster/continuous_ground_point_segmentation" , 1000 );
32
+ pub_column_cluster = nh.advertise <sensor_msgs::PointCloud2>(
33
+ " /perception/detections/lidar_roof/cluster/continuous_instance_segmentation" , 1000 );
34
+ pub_cluster = nh.advertise <sensor_msgs::PointCloud2>(
35
+ " /perception/detections/lidar_roof/cluster/continuous_clusters" , 1000 );
36
+ pub_evaluation = nh.advertise <sensor_msgs::PointCloud2>(" evaluation" , 1000 );
37
+ }
20
38
21
- using namespace continuous_clustering ;
22
- using namespace std ::chrono_literals;
39
+ void publishEvaluationPointCloud (const std::vector<KittiSegmentationEvaluationPoint>& point_cloud)
40
+ {
41
+ if (pub_evaluation.getNumSubscribers () > 0 )
42
+ pub_evaluation.publish (evaluationToPointCloud (point_cloud));
43
+ }
44
+
45
+ void publishColumn (int64_t from_global_column_index,
46
+ int64_t to_global_column_index,
47
+ bool ground_points_only,
48
+ const ContinuousClustering& clustering)
49
+ {
50
+ // publish column in odom frame
51
+ ros::Publisher* pub = ground_points_only ? &pub_column_ground : &pub_column_cluster;
52
+ ProcessingStage stage = ground_points_only ? GROUND_POINT_SEGMENTATION : CONTINUOUS_CLUSTERING;
53
+ if (pub->getNumSubscribers () > 0 )
54
+ {
55
+ auto msg = columnToPointCloud (clustering, from_global_column_index, to_global_column_index, " odom" , stage);
56
+ if (msg)
57
+ pub->publish (msg);
58
+ }
59
+ };
60
+
61
+ void publishCluster (const std::vector<Point>& cluster_points, int num_rows_in_range_image, uint64_t stamp_cluster)
62
+ {
63
+ if (pub_cluster.getNumSubscribers () == 0 )
64
+ return ;
65
+ pub_cluster.publish (clusterToPointCloud (cluster_points, num_rows_in_range_image, stamp_cluster, " odom" ));
66
+ };
67
+
68
+ void publishFiringAndClockAndTF (const RawPoints::Ptr& firing,
69
+ const Eigen::Isometry3d& odom_from_velodyne,
70
+ bool publish_firing)
71
+ {
72
+ if (pub_firing.getNumSubscribers () > 0 )
73
+ pub_firing.publish (firingToPointCloud (firing, " velo_link" ));
74
+
75
+ // publish clock
76
+ publish_clock (pub_clock, firing->stamp );
77
+
78
+ // publish this pose every X-th column (not too often)
79
+ if (publish_firing)
80
+ publish_tf (pub_tf, odom_from_velodyne, firing->stamp );
81
+ }
82
+
83
+ bool ok ()
84
+ {
85
+ return nh.ok ();
86
+ }
87
+
88
+ private:
89
+ ros::NodeHandle nh;
90
+ tf2_ros::TransformBroadcaster pub_tf;
91
+ ros::Publisher pub_clock;
92
+ ros::Publisher pub_firing;
93
+ ros::Publisher pub_column_ground;
94
+ ros::Publisher pub_column_cluster;
95
+ ros::Publisher pub_cluster;
96
+ ros::Publisher pub_evaluation;
97
+ };
98
+ #else
99
+ class DummyInterface
100
+ {
101
+ public:
102
+ void init (){};
103
+ void publishEvaluationPointCloud (const std::vector<KittiSegmentationEvaluationPoint>& point_cloud){};
104
+ void publishColumn (int64_t from_global_column_index,
105
+ int64_t to_global_column_index,
106
+ bool ground_points_only,
107
+ const ContinuousClustering& clustering){};
108
+ void
109
+ publishCluster (const std::vector<Point>& cluster_points, int num_rows_in_range_image, uint64_t stamp_cluster){};
110
+ void publishFiringAndClockAndTF (const RawPoints::Ptr& firing,
111
+ const Eigen::Isometry3d& odom_from_velodyne,
112
+ bool publish_firing){};
113
+ static bool ok ()
114
+ {
115
+ return true ;
116
+ };
117
+ };
118
+ #endif
23
119
24
120
class KittiDemo
25
121
{
@@ -68,10 +164,8 @@ class KittiDemo
68
164
69
165
auto it = map_frame_to_point_cloud.find ({current_sequence_index, previous_frame_index});
70
166
evaluation.evaluate (it->second , current_sequence_index);
71
- #ifdef WITH_ROS
72
- if (!disable_ros_publishers && pub_evaluation.getNumSubscribers () > 0 )
73
- pub_evaluation.publish (evaluationToPointCloud (it->second ));
74
- #endif
167
+ if (enable_publishers)
168
+ middleware.publishEvaluationPointCloud (it->second );
75
169
map_frame_to_point_cloud.erase (it);
76
170
previous_frame_index++;
77
171
}
@@ -132,21 +226,7 @@ class KittiDemo
132
226
public:
133
227
void run (const Path& root_folder, const std::vector<std::string>& sequences)
134
228
{
135
- #ifdef WITH_ROS
136
- ros::NodeHandle nh;
137
- tf2_ros::TransformBroadcaster pub_tf;
138
- ros::Publisher pub_clock = nh.advertise <rosgraph_msgs::Clock>(" /clock" , 100 );
139
- ros::Publisher pub_ego_robot_bbox = nh.advertise <visualization_msgs::Marker>(" /ego_robot_bounding_box" , 1 );
140
- ros::Publisher pub_firing =
141
- nh.advertise <sensor_msgs::PointCloud2>(" /perception/detections/lidar_roof/cluster/raw_firings" , 1000 );
142
- ros::Publisher pub_column_ground = nh.advertise <sensor_msgs::PointCloud2>(
143
- " /perception/detections/lidar_roof/cluster/continuous_ground_point_segmentation" , 1000 );
144
- ros::Publisher pub_column_cluster = nh.advertise <sensor_msgs::PointCloud2>(
145
- " /perception/detections/lidar_roof/cluster/continuous_instance_segmentation" , 1000 );
146
- ros::Publisher pub_cluster = nh.advertise <sensor_msgs::PointCloud2>(
147
- " /perception/detections/lidar_roof/cluster/continuous_clusters" , 1000 );
148
- pub_evaluation = nh.advertise <sensor_msgs::PointCloud2>(" evaluation" , 1000 );
149
- #endif
229
+ middleware.init ();
150
230
151
231
// iterate over all frames in specified sequences
152
232
KittiLoader kitti_loader;
@@ -212,37 +292,20 @@ class KittiDemo
212
292
clustering.setFinishedColumnCallback (
213
293
[&](int64_t from_global_column_index, int64_t to_global_column_index, bool ground_points_only)
214
294
{
215
- #ifdef WITH_ROS
216
- // publish column in odom frame
217
- ros::Publisher* pub = ground_points_only ? &pub_column_ground : &pub_column_cluster;
218
- ProcessingStage stage = ground_points_only ? GROUND_POINT_SEGMENTATION : CONTINUOUS_CLUSTERING;
219
- if (!disable_ros_publishers && pub->getNumSubscribers () > 0 )
220
- {
221
- auto msg = columnToPointCloud (
222
- clustering, from_global_column_index, to_global_column_index, " odom" , stage);
223
- if (msg)
224
- pub->publish (msg);
225
- }
226
- #endif
227
-
228
- // evaluation
295
+ if (enable_publishers)
296
+ middleware.publishColumn (
297
+ from_global_column_index, to_global_column_index, ground_points_only, clustering);
229
298
if (evaluate && !ground_points_only)
230
299
addColumnAndEvaluateFrameIfCompleted (
231
300
clustering, from_global_column_index, to_global_column_index);
232
301
});
233
302
234
- #ifdef WITH_ROS
235
303
clustering.setFinishedClusterCallback (
236
304
[&](const std::vector<Point>& cluster_points, uint64_t stamp_cluster)
237
305
{
238
- if (disable_ros_publishers || pub_cluster.getNumSubscribers () == 0 )
239
- return ;
240
-
241
- // publish cluster in odom frame
242
- pub_cluster.publish (
243
- clusterToPointCloud (cluster_points, clustering.num_rows_ , stamp_cluster, " odom" ));
306
+ if (enable_publishers)
307
+ middleware.publishCluster (cluster_points, clustering.num_rows_ , stamp_cluster);
244
308
});
245
- #endif
246
309
247
310
// info required for evaluation
248
311
current_sequence_index = sequence_index;
@@ -325,41 +388,25 @@ class KittiDemo
325
388
sequence_index,
326
389
frame_index);
327
390
328
- #ifdef WITH_ROS
329
- if (!disable_ros_publishers && pub_firing.getNumSubscribers () > 0 )
330
- pub_firing.publish (firingToPointCloud (firing, " velo_link" ));
331
- #endif
332
-
333
391
// get pose of sensor in odometry frame at this firing
334
392
Eigen::Isometry3d odom_from_velodyne =
335
393
kitti_loader.interpolate (transforms_odom_from_velodyne, firing->stamp ).pose ;
336
394
337
- #ifdef WITH_ROS
338
- // publish clock
339
- if (!disable_ros_publishers)
340
- publish_clock (pub_clock, firing->stamp );
341
-
342
- // publish this pose every X-th column (not too often)
343
- if (!disable_ros_publishers && column_index % 200 == 0 )
344
- publish_tf (pub_tf, odom_from_velodyne, firing->stamp );
345
- #endif
395
+ if (enable_publishers)
396
+ middleware.publishFiringAndClockAndTF (firing, odom_from_velodyne, column_index % 200 == 0 );
346
397
347
398
clustering.addFiring (firing, odom_from_velodyne);
348
399
349
400
if (delay_between_columns > 0 )
350
401
{
351
- #ifdef WITH_ROS
352
- if (!nh.ok ())
402
+ if (!middleware.ok ())
353
403
return ;
354
- #endif
355
404
std::this_thread::sleep_for (std::chrono::microseconds (delay_between_columns));
356
405
}
357
406
}
358
407
359
- #ifdef WITH_ROS
360
- if (!nh.ok ())
408
+ if (!middleware.ok ())
361
409
return ;
362
- #endif
363
410
}
364
411
365
412
// also evaluate final frame
@@ -378,9 +425,6 @@ class KittiDemo
378
425
379
426
private:
380
427
KittiEvaluation evaluation;
381
- #ifdef WITH_ROS
382
- ros::Publisher pub_evaluation;
383
- #endif
384
428
385
429
// store point cloud (+ ground truth labels)
386
430
std::map<std::pair<uint16_t , uint16_t >, std::vector<KittiSegmentationEvaluationPoint>> map_frame_to_point_cloud;
@@ -391,8 +435,13 @@ class KittiDemo
391
435
392
436
public:
393
437
bool evaluate{};
394
- bool disable_ros_publishers{ };
438
+ bool enable_publishers{ true };
395
439
int delay_between_columns{};
440
+ #ifdef WITH_ROS
441
+ ROSInterface middleware;
442
+ #else
443
+ DummyInterface middleware;
444
+ #endif
396
445
};
397
446
398
447
int main (int argc, char ** argv)
@@ -409,11 +458,13 @@ int main(int argc, char** argv)
409
458
demo.delay_between_columns = std::stoi (parser.getValueForArgument (" --delay-between-columns" , " 2000" ));
410
459
411
460
bool evaluate_fast = parser.argumentExists (" --evaluate-fast" );
461
+ #ifdef WITH_ROS
412
462
if (evaluate_fast)
463
+ #endif
413
464
{
414
465
demo.evaluate = true ;
415
466
demo.delay_between_columns = 0 ;
416
- demo.disable_ros_publishers = true ;
467
+ demo.enable_publishers = false ;
417
468
}
418
469
419
470
// check if there are unknown arguments left
0 commit comments