Segmenter.h
Go to the documentation of this file.
1 
13 #ifndef RAIL_SEGMENTATION_SEGMENTER_H_
14 #define RAIL_SEGMENTATION_SEGMENTER_H_
15 
16 // RAIL Segmentation
17 #include "SegmentationZone.h"
19 
20 // ROS
21 #include <pcl_ros/point_cloud.h>
22 #include <pcl_ros/transforms.h>
23 #include <rail_manipulation_msgs/ProcessSegmentedObjects.h>
24 #include <rail_manipulation_msgs/SegmentedObjectList.h>
25 #include <rail_manipulation_msgs/SegmentObjects.h>
26 #include <rail_manipulation_msgs/SegmentObjectsFromPointCloud.h>
27 #include <rail_segmentation/RemoveObject.h>
28 #include <ros/package.h>
29 #include <ros/ros.h>
30 #include <sensor_msgs/Image.h>
32 #include <sensor_msgs/PointCloud2.h>
34 #include <std_srvs/Empty.h>
35 #include <tf/transform_listener.h>
38 #include <visualization_msgs/Marker.h>
39 #include <visualization_msgs/MarkerArray.h>
40 
41 // PCL
42 #include <pcl/common/common.h>
43 #include <pcl/filters/conditional_removal.h>
44 #include <pcl/filters/extract_indices.h>
45 #include <pcl/filters/passthrough.h>
46 #include <pcl/filters/project_inliers.h>
47 #include <pcl/filters/voxel_grid.h>
48 #include <pcl/ModelCoefficients.h>
49 #include <pcl/point_types.h>
50 #include <pcl/point_cloud.h>
51 #include <pcl/segmentation/extract_clusters.h>
52 #include <pcl/segmentation/region_growing_rgb.h>
53 #include <pcl/segmentation/sac_segmentation.h>
54 
55 
56 // YAML
57 #include <yaml-cpp/yaml.h>
58 
59 // BOOST
60 #include <boost/thread/mutex.hpp>
61 
62 // C++ Standard Library
63 #include <fstream>
64 #include <string>
65 
66 namespace rail
67 {
68 namespace segmentation
69 {
70 
78 class Segmenter
79 {
80 public:
81 #if __cplusplus >= 201103L
82 
83  static constexpr bool DEFAULT_DEBUG = false;
85  static constexpr double SAC_EPS_ANGLE = 0.15;
87  static constexpr double SAC_DISTANCE_THRESHOLD = 0.01;
89  static constexpr int SAC_MAX_ITERATIONS = 100;
91  static constexpr double SURFACE_REMOVAL_PADDING = 0.005;
93  static constexpr int DEFAULT_MIN_CLUSTER_SIZE = 200;
95  static constexpr int DEFAULT_MAX_CLUSTER_SIZE = 10000;
97  static constexpr double CLUSTER_TOLERANCE = 0.02;
99  static constexpr double POINT_COLOR_THRESHOLD = 10;
101  static constexpr double REGION_COLOR_THRESHOLD = 10;
103  static constexpr float DOWNSAMPLE_LEAF_SIZE = 0.01;
105  static constexpr double MARKER_SCALE = 0.01;
106 #else
107 
108  static const bool DEFAULT_DEBUG = false;
110  static const double SAC_EPS_ANGLE = 0.15;
112  static const double SAC_DISTANCE_THRESHOLD = 0.01;
114  static const int SAC_MAX_ITERATIONS = 100;
116  static const double SURFACE_REMOVAL_PADDING = 0.005;
118  static const int DEFAULT_MIN_CLUSTER_SIZE = 200;
120  static const int DEFAULT_MAX_CLUSTER_SIZE = 10000;
122  static const double CLUSTER_TOLERANCE = 0.02;
124  static const double POINT_COLOR_THRESHOLD = 10;
126  static const double REGION_COLOR_THRESHOLD = 10;
128  static const float DOWNSAMPLE_LEAF_SIZE = 0.01;
130  static const double MARKER_SCALE = 0.01;
131 #endif
132 
138  Segmenter();
139 
147  bool okay() const;
148 
149 private:
159  const SegmentationZone &getCurrentZone() const;
160 
171  bool removeObjectCallback(rail_segmentation::RemoveObject::Request &req,
172  rail_segmentation::RemoveObject::Response &res);
173 
184  bool clearCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res);
185 
196  bool segmentCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res);
197 
198  bool calculateFeaturesCallback(rail_manipulation_msgs::ProcessSegmentedObjects::Request &req,
199  rail_manipulation_msgs::ProcessSegmentedObjects::Response &res);
200 
211  bool segmentObjectsCallback(rail_manipulation_msgs::SegmentObjects::Request &req, rail_manipulation_msgs::SegmentObjects::Response &res);
212 
223  bool segmentObjectsFromPointCloudCallback(rail_manipulation_msgs::SegmentObjectsFromPointCloud::Request &req, rail_manipulation_msgs::SegmentObjectsFromPointCloud::Response &res);
224 
233  bool segmentObjects(rail_manipulation_msgs::SegmentedObjectList &objects);
234 
240  bool executeSegmentation(pcl::PointCloud<pcl::PointXYZRGB>::Ptr pc,
241  rail_manipulation_msgs::SegmentedObjectList &objects);
242 
258  bool findSurface(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in, const pcl::IndicesConstPtr &indices_in,
259  const SegmentationZone &zone, const pcl::IndicesPtr &indices_out,
260  rail_manipulation_msgs::SegmentedObject &table_out) const;
261 
271  void extractClustersEuclidean(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in, const pcl::IndicesConstPtr &indices_in,
272  std::vector<pcl::PointIndices> &clusters) const;
273 
274 
284  void extractClustersRGB(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in, const pcl::IndicesConstPtr &indices_in,
285  std::vector<pcl::PointIndices> &clusters) const;
286 
297  void inverseBound(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in, const pcl::IndicesConstPtr &indices_in,
298  const pcl::ConditionBase<pcl::PointXYZRGB>::Ptr &conditions, const pcl::IndicesPtr &indices_out) const;
299 
309  void extract(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in, const pcl::IndicesConstPtr &indices_in,
310  const pcl::PointCloud<pcl::PointXYZRGB>::Ptr &out) const;
311 
320  double averageZ(const std::vector<pcl::PointXYZRGB, Eigen::aligned_allocator<pcl::PointXYZRGB> > &v) const;
321 
330  visualization_msgs::Marker createMarker(const pcl::PCLPointCloud2::ConstPtr &pc) const;
331 
341  sensor_msgs::Image createImage(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
342  const pcl::PointIndices &cluster) const;
343 
349  boost::mutex msg_mutex_;
351  std::vector<SegmentationZone> zones_;
358 
366 // ros::Subscriber point_cloud_sub_;
373 
374  std::string point_cloud_topic_;
375 
377  rail_manipulation_msgs::SegmentedObjectList object_list_;
379  rail_manipulation_msgs::SegmentedObject table_;
381  visualization_msgs::MarkerArray markers_;
383  visualization_msgs::MarkerArray text_markers_;
385  visualization_msgs::Marker table_marker_;
386 
387 };
388 
389 }
390 }
391 
392 Eigen::Vector3f RGB2Lab (const Eigen::Vector3f& colorRGB);
393 
394 #endif
bool segmentObjectsCallback(rail_manipulation_msgs::SegmentObjects::Request &req, rail_manipulation_msgs::SegmentObjects::Response &res)
Callback for the main segmentation request.
Definition: Segmenter.cpp:410
static const double POINT_COLOR_THRESHOLD
Definition: Segmenter.h:124
ros::ServiceServer remove_object_srv_
Definition: Segmenter.h:362
bool executeSegmentation(pcl::PointCloud< pcl::PointXYZRGB >::Ptr pc, rail_manipulation_msgs::SegmentedObjectList &objects)
Main segmentation routine.
Definition: Segmenter.cpp:453
void inverseBound(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, const pcl::ConditionBase< pcl::PointXYZRGB >::Ptr &conditions, const pcl::IndicesPtr &indices_out) const
Bound a point cloud based on the inverse of a set of conditions.
Definition: Segmenter.cpp:1318
visualization_msgs::Marker table_marker_
Definition: Segmenter.h:385
rail_manipulation_msgs::SegmentedObjectList object_list_
Definition: Segmenter.h:377
void extractClustersEuclidean(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, std::vector< pcl::PointIndices > &clusters) const
Find clusters in a point cloud.
Definition: Segmenter.cpp:1132
ros::Publisher debug_img_pub_
Definition: Segmenter.h:364
static const double SAC_EPS_ANGLE
Definition: Segmenter.h:110
visualization_msgs::Marker createMarker(const pcl::PCLPointCloud2::ConstPtr &pc) const
Create a Marker from the given point cloud.
Definition: Segmenter.cpp:1247
ros::ServiceServer segment_objects_srv_
Definition: Segmenter.h:362
bool segmentCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Callback for the main segmentation request.
Definition: Segmenter.cpp:404
static const int DEFAULT_MAX_CLUSTER_SIZE
Definition: Segmenter.h:120
tf::TransformListener tf_
Definition: Segmenter.h:368
ros::NodeHandle private_node_
Definition: Segmenter.h:360
void extract(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &out) const
Extract a new point cloud based on the given indices.
Definition: Segmenter.cpp:1309
The main grasp collector node object.
Definition: Segmenter.h:78
bool clearCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Callback for the clear request.
Definition: Segmenter.cpp:355
static const float DOWNSAMPLE_LEAF_SIZE
Definition: Segmenter.h:128
bool okay() const
A check for a valid Segmenter.
Definition: Segmenter.cpp:274
static const bool DEFAULT_DEBUG
Definition: Segmenter.h:108
bool segmentObjects(rail_manipulation_msgs::SegmentedObjectList &objects)
Callback for the main segmentation request.
Definition: Segmenter.cpp:427
visualization_msgs::MarkerArray markers_
Definition: Segmenter.h:381
static const double SURFACE_REMOVAL_PADDING
Definition: Segmenter.h:116
Segmenter()
Create a Segmenter and associated ROS information.
Definition: Segmenter.cpp:32
const SegmentationZone & getCurrentZone() const
Determine the current zone based on the latest state of the TF tree.
Definition: Segmenter.cpp:279
std::vector< SegmentationZone > zones_
Definition: Segmenter.h:351
double averageZ(const std::vector< pcl::PointXYZRGB, Eigen::aligned_allocator< pcl::PointXYZRGB > > &v) const
Find the average Z value of the point vector.
Definition: Segmenter.cpp:1334
bool removeObjectCallback(rail_segmentation::RemoveObject::Request &req, rail_segmentation::RemoveObject::Response &res)
Callback for the remove object request.
Definition: Segmenter.cpp:306
static const int SAC_MAX_ITERATIONS
Definition: Segmenter.h:114
ros::Publisher markers_pub_
Definition: Segmenter.h:364
ros::Publisher segmented_objects_pub_
Definition: Segmenter.h:364
static const int DEFAULT_MIN_CLUSTER_SIZE
Definition: Segmenter.h:118
visualization_msgs::MarkerArray text_markers_
Definition: Segmenter.h:383
bool calculateFeaturesCallback(rail_manipulation_msgs::ProcessSegmentedObjects::Request &req, rail_manipulation_msgs::ProcessSegmentedObjects::Response &res)
Definition: Segmenter.cpp:843
tf2_ros::TransformListener tf2_
Definition: Segmenter.h:372
The criteria for a segmentation zone.
ros::ServiceServer calculate_features_srv_
Definition: Segmenter.h:362
static const double REGION_COLOR_THRESHOLD
Definition: Segmenter.h:126
static const double MARKER_SCALE
Definition: Segmenter.h:130
bool segmentObjectsFromPointCloudCallback(rail_manipulation_msgs::SegmentObjectsFromPointCloud::Request &req, rail_manipulation_msgs::SegmentObjectsFromPointCloud::Response &res)
Callback for the main segmentation request.
Definition: Segmenter.cpp:416
ros::ServiceServer segment_objects_from_point_cloud_srv_
Definition: Segmenter.h:362
static const double CLUSTER_TOLERANCE
Definition: Segmenter.h:122
ros::Publisher table_marker_pub_
Definition: Segmenter.h:364
static const double SAC_DISTANCE_THRESHOLD
Definition: Segmenter.h:112
void extractClustersRGB(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, std::vector< pcl::PointIndices > &clusters) const
Find clusters in a point cloud.
Definition: Segmenter.cpp:1158
Eigen::Vector3f RGB2Lab(const Eigen::Vector3f &colorRGB)
Definition: Segmenter.cpp:1345
sensor_msgs::Image createImage(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::PointIndices &cluster) const
Create a cropped image of the segmented object.
Definition: Segmenter.cpp:1185
ros::Publisher debug_pc_pub_
Definition: Segmenter.h:364
rail_manipulation_msgs::SegmentedObject table_
Definition: Segmenter.h:379
bool findSurface(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, const SegmentationZone &zone, const pcl::IndicesPtr &indices_out, rail_manipulation_msgs::SegmentedObject &table_out) const
Find and remove a surface from the given point cloud.
Definition: Segmenter.cpp:959
ros::ServiceServer segment_srv_
Definition: Segmenter.h:362
The criteria for a segmentation zone.
ros::ServiceServer clear_srv_
Definition: Segmenter.h:362
tf2_ros::Buffer tf_buffer_
Definition: Segmenter.h:370


rail_segmentation
Author(s): Russell Toris , David Kent
autogenerated on Mon Feb 28 2022 23:23:51