Skip to content

Commit 0ca7c45

Browse files
authored
Merge pull request #8 from jkk-research/cluster-outline
Cluster outlining for all working nodes
2 parents ebf9029 + 4bdd560 commit 0ca7c45

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ set(OUTLINE_SOURCES
6161
include/cluster_outline.hpp
6262
)
6363

64-
add_executable(dbscan_spatial src/dbscan_spatial.cpp ${BENCHMARK_SOURCES})
64+
add_executable(dbscan_spatial src/dbscan_spatial.cpp ${BENCHMARK_SOURCES} ${OUTLINE_SOURCES})
6565
target_link_libraries(dbscan_spatial ${PCL_LIBRARIES})
6666
ament_target_dependencies(dbscan_spatial ${ament_dependencies} )
6767
target_compile_features(dbscan_spatial PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
@@ -76,7 +76,7 @@ target_link_libraries(dblane_spatial ${PCL_LIBRARIES})
7676
ament_target_dependencies(dblane_spatial ${ament_dependencies} )
7777
target_compile_features(dblane_spatial PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
7878

79-
add_executable(euclidean_spatial src/euclidean_spatial.cpp)
79+
add_executable(euclidean_spatial src/euclidean_spatial.cpp ${OUTLINE_SOURCES})
8080
target_link_libraries(euclidean_spatial ${PCL_LIBRARIES})
8181
ament_target_dependencies(euclidean_spatial ${ament_dependencies} )
8282
target_compile_features(euclidean_spatial PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17

src/dbscan_spatial.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
// TBB
2525
#include <tbb/tbb.h>
2626

27+
#include "cluster_outline.hpp"
28+
2729
// Point class, which stores the x and y coordinates of a point, the number of neighbors, whether it is a core point, and the cluster ID
2830
class Point {
2931
public:
@@ -429,6 +431,18 @@ class DbscanSpatial : public rclcpp::Node
429431
}
430432
}
431433

434+
// Add markers for clusters that are not present in the current frame to avoid ghost markers
435+
for(int i = num_of_clusters + 1; i <= max_clust_reached; i++) {
436+
visualization_msgs::msg::Marker center_marker;
437+
init_center_marker(center_marker, 0, 0, i);
438+
center_marker.header.frame_id = input_msg->header.frame_id;
439+
center_marker.header.stamp = this->now();
440+
center_marker.color.a = 0.0;
441+
mark_array.markers.push_back(center_marker);
442+
}
443+
444+
cluster_outline.computeOutline(cloud_filtered, mark_array, 20, max_clust_reached, input_msg->header.frame_id);
445+
432446
// Convert to ROS data type
433447
sensor_msgs::msg::PointCloud2 output_msg;
434448
pcl::toROSMsg(*cloud_filtered, output_msg);
@@ -438,6 +452,7 @@ class DbscanSpatial : public rclcpp::Node
438452
pub_lidar_->publish(output_msg);
439453
pub_marker_->publish(mark_array);
440454

455+
441456
bench4.finish();
442457

443458
fullbenchmark.finish();
@@ -448,12 +463,14 @@ class DbscanSpatial : public rclcpp::Node
448463
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr pub_marker_;
449464
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sub_lidar_;
450465
OnSetParametersCallbackHandle::SharedPtr callback_handle_;
466+
outline::ClusterOutline cluster_outline;
451467
float minX = -80.0, minY = -25.0, minZ = -2.0;
452468
float maxX = +80.0, maxY = +25.0, maxZ = -0.15;
453469
double eps = 3.5;
454470
bool verbose1 = false, verbose2 = false, pub_undecided = false;
455471
std::string points_in_topic, points_out_topic, marker_out_topic;
456472
size_t count_;
473+
int max_clust_reached = 0;
457474
};
458475

459476
int main(int argc, char *argv[])

src/euclidean_spatial.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
// ROS package
3131
#include "lidar_cluster/marker.hpp"
3232

33+
#include "cluster_outline.hpp"
34+
3335
using namespace std::chrono_literals;
3436
using std::placeholders::_1;
3537

@@ -260,6 +262,20 @@ class EuclideanSpatial : public rclcpp::Node
260262
mark_array.markers.push_back(center_marker);
261263
}
262264

265+
int num_of_clusters = clusters.size();
266+
267+
// Add markers for clusters that are not present in the current frame to avoid ghost markers
268+
for(int i = num_of_clusters + 1; i <= max_clust_reached; i++) {
269+
visualization_msgs::msg::Marker center_marker;
270+
init_center_marker(center_marker, 0, 0, i);
271+
center_marker.header.frame_id = input_msg->header.frame_id;
272+
center_marker.header.stamp = this->now();
273+
center_marker.color.a = 0.0;
274+
mark_array.markers.push_back(center_marker);
275+
}
276+
277+
cluster_outline.computeOutline(cloud_cluster, mark_array, 20, max_clust_reached, input_msg->header.frame_id);
278+
263279
// Convert to ROS data type
264280
sensor_msgs::msg::PointCloud2 output_msg;
265281
pcl::toROSMsg(*cloud_cluster, output_msg);
@@ -274,10 +290,12 @@ class EuclideanSpatial : public rclcpp::Node
274290
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr pub_marker_;
275291
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sub_lidar_;
276292
OnSetParametersCallbackHandle::SharedPtr callback_handle_;
293+
outline::ClusterOutline cluster_outline;
294+
277295
float minX = -80.0, minY = -25.0, minZ = -2.0;
278296
float maxX = 80.0, maxY = +25.0, maxZ = -0.15;
279297
float tolerance_ = 0.02;
280-
int min_cluster_size_ = 10;
298+
int min_cluster_size_ = 10, max_clust_reached = 0;
281299
int max_cluster_size_ = 500;
282300
bool use_height_ = false;
283301
bool verbose1 = false, verbose2 = false;

0 commit comments

Comments
 (0)