Go to the documentation of this file.00001
00060
00061 #include <ros/ros.h>
00062 #include <pluginlib/class_list_macros.h>
00063 #include <nodelet/nodelet.h>
00064 #include <pcl/point_types.h>
00065 #include <pcl_ros/point_cloud.h>
00066 #include <pcl/point_cloud.h>
00067
00068 #include <cob_3d_segmentation/general_segmentation.h>
00069 #include <cob_3d_segmentation/quad_regression/quad_regression.h>
00070
00071
00072 class As_Node
00073 {
00074 protected:
00075 ros::NodeHandle n_;
00076 public:
00077 As_Node() {
00078 }
00079
00080 virtual ~As_Node() {}
00081
00082 virtual void onInit()=0;
00083
00084 void start() {
00085
00086 }
00087 };
00088
00089 class As_Nodelet : public nodelet::Nodelet
00090 {
00091 protected:
00092 ros::NodeHandle n_;
00093 public:
00094 As_Nodelet() {
00095 }
00096
00097 virtual ~As_Nodelet() {}
00098
00099 void start() {
00100
00101 n_ = getNodeHandle();
00102 }
00103 };
00104
00105 template <typename Point, typename PointLabel, typename Parent>
00106 class Segmentation_Node : public Parent
00107 {
00108 typedef pcl::PointCloud<Point> PointCloud;
00109 typedef Segmentation::Segmentation_QuadRegression<Point, PointLabel, Segmentation::QPPF::QuadRegression<2, Point, Segmentation::QPPF::CameraModel_Kinect<Point> > > TYPE_QPPF;
00110
00111 ros::Subscriber point_cloud_sub_;
00112 ros::Publisher point_cloud_pub_;
00113
00114 GeneralSegmentation<Point, PointLabel> *seg_;
00115
00116 std::string algo_;
00117 public:
00118
00119 Segmentation_Node()
00120 {
00121 }
00122
00123 virtual ~Segmentation_Node()
00124 {}
00125
00126 void onInit() {
00127 this->start();
00128
00129 ros::NodeHandle *n=&(this->n_);
00130 point_cloud_sub_ = this->n_.subscribe("/camera/rgb/points", 1, &Segmentation_Node<Point, PointLabel, Parent>::pointCloudSubCallback, this);
00131 point_cloud_pub_ = n->advertise<PointCloud>("point_cloud_labeled", 1);
00132
00133
00134 seg_ = NULL;
00135
00136 if(n->getParam("algorithm",algo_))
00137 {
00138 if(algo_=="quad regression")
00139 {
00140 TYPE_QPPF *seg = new TYPE_QPPF();
00141 seg_ = seg;
00142
00143 double filter;
00144 if(this->n_.getParam("filter",filter))
00145 seg->setFilter((float)filter);
00146
00147 bool only_planes;
00148 if(this->n_.getParam("only_planes",only_planes))
00149 seg->setOnlyPlanes(only_planes);
00150 }
00151 else
00152 ROS_ERROR("%s is no valid segmentation algorithm", algo_.c_str());
00153 }
00154 else
00155 {
00156 ROS_ERROR("no valid segmentation algorithm selected");
00157 }
00158 }
00159
00160 void
00161 pointCloudSubCallback(const boost::shared_ptr<const PointCloud>& pc_in)
00162 {
00163 ROS_DEBUG("segmentation: point cloud callback");
00164
00165 if(!seg_)
00166 return;
00167
00168 seg_->setInputCloud(pc_in);
00169 seg_->compute();
00170 if(point_cloud_pub_.getNumSubscribers()>0)
00171 {
00172 pcl::PointCloud<PointLabel> pc_out = *seg_->getOutputCloud();
00173 pc_out.header = pc_in->header;
00174 point_cloud_pub_.publish(pc_out);
00175 }
00176 }
00177 };
00178
00179 #ifdef COMPILE_NODELET
00180
00181 typedef Segmentation_Node<pcl::PointXYZ,pcl::PointXYZRGB,As_Nodelet> Segmentation_Node_XYZ;
00182
00183 PLUGINLIB_DECLARE_CLASS(cob_3d_segmentation, Segmentation_Node_XYZ, Segmentation_Node_XYZ, nodelet::Nodelet)
00184
00185 #else
00186
00187 int main(int argc, char **argv) {
00188 ros::init(argc, argv, "segmentation");
00189
00190 Segmentation_Node<pcl::PointXYZ,pcl::PointXYZRGB,As_Node> sn;
00191 sn.onInit();
00192
00193 ros::spin();
00194
00195 return 0;
00196 }
00197
00198 #endif