Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #pragma once
00020
00021 #include <string>
00022 #include <boost/utility.hpp>
00023 #include <boost/scoped_ptr.hpp>
00024 #include <boost/thread.hpp>
00025 #include <boost/circular_buffer.hpp>
00026
00027 #include "ros/ros.h"
00028
00029 #include "pcl16/point_types.h"
00030 #include "pcl16_ros/point_cloud.h"
00031 #include "pcl16/ModelCoefficients.h"
00032 #include "tf/transform_listener.h"
00033 #include "tf/transform_broadcaster.h"
00034 #include "image_transport/image_transport.h"
00035 #include "sensor_msgs/CameraInfo.h"
00036 #include "message_filters/synchronizer.h"
00037 #include "message_filters/sync_policies/approximate_time.h"
00038 #include <pcl16/features/integral_image_normal.h>
00039 #include <pcl16/segmentation/organized_multi_plane_segmentation.h>
00040 #include <pcl16/segmentation/edge_aware_plane_comparator.h>
00041
00042 #include "dynamic_reconfigure/server.h"
00043 #include "semanticmodel/FilterConfig.h"
00044 #include "semanticmodel/Plane.h"
00045 #include <cstddef>
00046
00047 using semanticmodel::FilterConfig;
00048 using std::vector;
00049
00050 namespace semanticmodel
00051 {
00052
00053 class Segmenter : public boost::noncopyable
00054 {
00055
00056 private:
00057
00058 typedef pcl16::PointXYZRGB Point;
00059 typedef pcl16::PointCloud<Point> PointCloud;
00060
00061
00062
00063
00064
00065
00066
00067
00068 typedef message_filters::sync_policies::
00069 ApproximateTime<sensor_msgs::Image,
00070 sensor_msgs::CameraInfo,
00071 sensor_msgs::Image,
00072 sensor_msgs::CameraInfo,
00073 PointCloud> Sync;
00074
00075
00076 public:
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 Segmenter(const std::string& name_space,
00088 const std::string& cloud_input_topic,
00089 const std::string& camera_input_topic,
00090 const std::string& depth_input_topic,
00091 const std::string& planecloud_output_topic,
00092 const std::string& plane_output_topic,
00093 const std::string& object_output_topic,
00094 const std::string& plane_service_topic);
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 void passthrough(PointCloud::Ptr& in, PointCloud::Ptr& out);
00133
00134 void fit_planes(PointCloud::ConstPtr in,
00135 pcl16::PointCloud<pcl16::Normal>::ConstPtr normals,
00136 const tf::Transform& trans,
00137 vector<PointCloud::Ptr>& good_planes,
00138 vector<pcl16::ModelCoefficients>& good_models,
00139 vector<pcl16::ModelCoefficients>& bad_models);
00140
00141
00142
00143 void convex_hulls(const vector<PointCloud::Ptr>& planes,
00144 vector<PointCloud::Ptr>& hulls);
00145
00146
00147 void publish_planes(const vector<PointCloud::Ptr>& planes,
00148 const vector<PointCloud::Ptr>& hulls,
00149 const vector<pcl16::ModelCoefficients>& coeffs,
00150 vector<semanticmodel::Plane>& outputs);
00151
00152
00153 void get_aboves(const vector<PointCloud::Ptr>& hulls,
00154 const vector<pcl16::ModelCoefficients>& coeffs,
00155 const PointCloud::Ptr& densecloud,
00156 PointCloud::Ptr& out);
00157
00158
00159
00160 void lose_bads(const PointCloud::ConstPtr& aboves,
00161 PointCloud::Ptr good_aboves,
00162 const vector<pcl16::ModelCoefficients>& bad_coeffs);
00163
00164
00165 void synchronized_pipeline_callback(
00166 const sensor_msgs::ImageConstPtr& rgb_img,
00167 const sensor_msgs::CameraInfoConstPtr& rgb_info,
00168 const sensor_msgs::ImageConstPtr& depth_image,
00169 const sensor_msgs::CameraInfoConstPtr& depth_info,
00170 const PointCloud::ConstPtr& cloud);
00171
00172
00173 void publishLatestPlanes(const ros::WallTimerEvent& e);
00174
00175 private:
00176
00177 static const int QUEUE_SIZE = 100;
00178
00179
00180 ros::NodeHandle handle;
00181
00182
00183 FilterConfig config;
00184 dynamic_reconfigure::Server<FilterConfig> dynparam_srv;
00185 dynamic_reconfigure::Server<FilterConfig>::CallbackType dynparam_func;
00186 boost::mutex config_mutex;
00187
00188
00189 void dynamic_reconfigure_callback(const FilterConfig& config,
00190 uint32_t level);
00191
00192
00193 bool isHorizontal(const pcl16::ModelCoefficients& coeffs) const;
00194
00195
00196 bool isGroundPlane(const pcl16::ModelCoefficients& coeffs) const;
00197
00198
00199 pcl16::ModelCoefficients transformCoeffs(const btTransform& trans,
00200 const pcl16::ModelCoefficients& in);
00201
00202
00203
00204 boost::scoped_ptr<tf::TransformListener> listener;
00205 boost::scoped_ptr<tf::TransformBroadcaster> broadcaster;
00206
00207
00208
00209 boost::scoped_ptr< message_filters::Synchronizer<Sync> > sync;
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 ros::Subscriber cloud_sub;
00220 image_transport::ImageTransport rgb_transport;
00221 image_transport::CameraSubscriber cam_sub;
00222 image_transport::ImageTransport depth_transport;
00223 image_transport::CameraSubscriber depth_sub;
00224
00225
00226
00227 void cloud_cb(const PointCloud::ConstPtr& cloud);
00228 void camera_cb(const sensor_msgs::ImageConstPtr& img,
00229 const sensor_msgs::CameraInfoConstPtr& info);
00230 void depth_cb(const sensor_msgs::ImageConstPtr& img,
00231 const sensor_msgs::CameraInfoConstPtr& info);
00232
00233
00234 ros::Publisher map_points_pub;
00235 ros::Publisher planecloud_pub;
00236 ros::Publisher plane_pub;
00237 ros::Publisher object_pub;
00238 ros::Publisher latest_plane_pub_;
00239
00240
00241 ros::ServiceClient planetracker_srv;
00242
00243
00244 pcl16::OrganizedMultiPlaneSegmentation<Point, pcl16::Normal, pcl16::Label>
00245 plane_segmenter_;
00246
00247
00248 pcl16::IntegralImageNormalEstimation<Point, pcl16::Normal> normal_estimator_;
00249
00250
00251 boost::shared_ptr<pcl16::EdgeAwarePlaneComparator<Point, pcl16::Normal> >
00252 comp_;
00253
00254
00255 boost::circular_buffer<PointCloud::Ptr> latest_planes_;
00256 ros::WallTimer latest_plane_timer_;
00257
00258
00259
00260
00261 bool short_circuit;
00262
00263
00264 int processed;
00265 int skipped;
00266 };
00267
00268 }