41 #include <boost/thread.hpp> 42 #include <boost/thread/mutex.hpp> 88 dynamic_recfg_ =
new dynamic_reconfigure::Server<CostmapToLinesDBSMCCHConfig>(nh);
93 if (nh.
hasParam(
"support_pts_min_dist_") || nh.
hasParam(
"support_pts_min_dist"))
94 ROS_WARN(
"CostmapToLinesDBSMCCH: Parameter 'support_pts_min_dist' is deprecated and not included anymore.");
96 ROS_WARN(
"CostmapToLinesDBSMCCH: Parameter 'min_support_pts_' is not found. Remove the underscore.");
101 std::vector< std::vector<KeyPoint> > clusters;
109 for (
int i = 1; i <clusters.size(); ++i)
111 geometry_msgs::Polygon polygon;
120 if (!clusters.empty())
122 for (
int i=0; i < clusters.front().size(); ++i)
124 polygons->push_back( geometry_msgs::Polygon() );
134 bool sort_keypoint_x(
const std::size_t& i,
const std::size_t& j,
const std::vector<CL::KeyPoint>& cluster)
135 {
return (cluster[i].
x<cluster[j].
x) || (cluster[i].x == cluster[j].x && cluster[i].y < cluster[j].y); }
136 bool sort_keypoint_y(
const std::size_t& i,
const std::size_t& j,
const std::vector<CL::KeyPoint>& cluster)
137 {
return (cluster[i].
y<cluster[j].
y) || (cluster[i].y == cluster[j].y && cluster[i].x < cluster[j].x); }
140 std::back_insert_iterator< std::vector<geometry_msgs::Polygon> > lines)
142 if (polygon.points.empty())
145 if (polygon.points.size() < 2)
150 int n = (int)polygon.points.size();
152 for (
int i=1; i<n; ++i)
154 const geometry_msgs::Point32* vertex1 = &polygon.points[i-1];
155 const geometry_msgs::Point32* vertex2 = &polygon.points[i];
159 double dx = vertex2->x - vertex1->x;
160 double dy = vertex2->y - vertex1->y;
181 std::vector<std::size_t> support_points;
183 for (std::size_t k = 0; k < cluster.size(); ++k)
185 bool is_inbetween =
false;
190 support_points.push_back(k);
203 if (std::abs(dx) >= std::abs(dy))
204 std::sort(support_points.begin(), support_points.end(), boost::bind(
sort_keypoint_x, _1, _2, boost::cref(cluster)));
206 std::sort(support_points.begin(), support_points.end(), boost::bind(
sort_keypoint_y, _1, _2, boost::cref(cluster)));
209 for (
int k = 1; k < int(support_points.size()); ++k)
211 double dist_x = cluster[support_points[k]].x - cluster[support_points[k-1]].x;
212 double dist_y = cluster[support_points[k]].y - cluster[support_points[k-1]].y;
213 double dist = std::sqrt( dist_x*dist_x + dist_y*dist_y);
229 geometry_msgs::Polygon line;
230 line.points.push_back(*vertex1);
231 line.points.push_back(*vertex2);
236 std::vector<std::size_t>::reverse_iterator support_it = support_points.rbegin();
237 for (; support_it != support_points.rend(); ++support_it)
239 cluster.erase(cluster.begin() + *support_it);
262 std::vector<std::size_t>::reverse_iterator support_it = support_points.rbegin();
263 for (; support_it != support_points.rend(); ++support_it)
265 geometry_msgs::Polygon polygon;
269 cluster.erase(cluster.begin() + *support_it);
275 for (
int i=0; i<(int)cluster.size();++i)
277 geometry_msgs::Polygon polygon;
virtual void compute()
This method performs the actual work (conversion of the costmap to polygons)
double support_pts_max_dist_
std::vector< KeyPoint > occupied_cells_
List of occupied cells in the current map (updated by updateCostmap2D())
virtual void initialize(ros::NodeHandle nh)
Initialize the plugin.
int max_pts_
Parameter for DB_Scan: maximum number of points that define a cluster (to avoid large L- and U-shapes...
static void convertPointToPolygon(const Point &point, geometry_msgs::Polygon &polygon)
Convert a generi point type to a geometry_msgs::Polygon.
This class converts the costmap_2d into a set of lines (and points)
bool sort_keypoint_x(const std::size_t &i, const std::size_t &j, const std::vector< CL::KeyPoint > &cluster)
double max_distance_
Parameter for DB_Scan, maximum distance to neighbors [m].
double computeDistanceToLineSegment(const Point &point, const LinePoint &line_start, const LinePoint &line_end, bool *is_inbetween=NULL)
Calculate the distance between a point and a straight line segment.
double min_keypoint_separation_
Clear keypoints of the convex polygon that are close to each other [distance in meters] (0: keep all)...
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
TFSIMD_FORCE_INLINE const tfScalar & y() const
virtual ~CostmapToLinesDBSMCCH()
Destructor.
dynamic_reconfigure::Server< CostmapToLinesDBSMCCHConfig > * dynamic_recfg_
Dynamic reconfigure server to allow config modifications at runtime.
double support_pts_max_dist_inbetween_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool sort_keypoint_y(const std::size_t &i, const std::size_t &j, const std::vector< CL::KeyPoint > &cluster)
This abstract class defines the interface for plugins that convert the costmap into polygon types...
TFSIMD_FORCE_INLINE const tfScalar & x() const
int min_pts_
Parameter for DB_Scan: minimum number of points that define a cluster.
This class converts the costmap_2d into a set of convex polygons (and points)
void dbScan(const std::vector< KeyPoint > &occupied_cells, std::vector< std::vector< KeyPoint > > &clusters)
DBSCAN algorithm for clustering.
void convexHull2(std::vector< KeyPoint > &cluster, geometry_msgs::Polygon &polygon)
Compute the convex hull for a single cluster.
void reconfigureCB(CostmapToLinesDBSMCCHConfig &config, uint32_t level)
Callback for the dynamic_reconfigure node.
void extractPointsAndLines(std::vector< KeyPoint > &cluster, const geometry_msgs::Polygon &polygon, std::back_insert_iterator< std::vector< geometry_msgs::Polygon > > lines)
Extract points and lines from a given cluster by checking all keypoint pairs of the convex hull for a...
bool hasParam(const std::string &key) const
void updatePolygonContainer(PolygonContainerPtr polygons)
Thread-safe update of the internal polygon container (that is shared using getPolygons() from outside...