Go to the documentation of this file.00001 #ifndef _points_from_volume_lib_H_
00002 #define _points_from_volume_lib_H_
00003
00012
00013
00015 #include <ros/ros.h>
00016 #include <stdio.h>
00017 #include <sensor_msgs/PointCloud2.h>
00018 #include <pcl_ros/transforms.h>
00019 #include <pcl/ros/conversions.h>
00020 #include <pcl/point_cloud.h>
00021 #include <pcl/point_types.h>
00022 #include <pcl/segmentation/extract_polygonal_prism_data.h>
00023 #include <pcl/filters/extract_indices.h>
00024 #include <pcl/filters/project_inliers.h>
00025 typedef enum {SUCCESS, FAILURE}t_func_output;
00026
00027 #define _CONVEX_LIB_DEBUG_ 0
00028
00029 using namespace std;
00030
00031 template<class T>
00032 class points_from_volume
00033 {
00034
00035 public:
00036
00037 points_from_volume()
00038 {
00039 flag_convexhull_set=false;
00040 };
00041
00042 ~points_from_volume()
00043 {
00044 #if _CONVEX_LIB_DEBUG_
00045 printf("Destructor...\n");
00046 #endif
00047 };
00048
00049
00056 t_func_output set_convex_hull(pcl::PointCloud<T>& pc_in)
00057 {
00058 convex_hull=pc_in;
00059 convex_hull.header.frame_id = pc_in.header.frame_id;
00060 #if _CONVEX_LIB_DEBUG_
00061 cout<<"pc_in frame id on set_convex_hul -> "<<pc_in.header.frame_id<<endl;
00062 #endif
00063 flag_convexhull_set=true;
00064 return SUCCESS;
00065 };
00066
00073 t_func_output set_convex_hull(const sensor_msgs::PointCloud2ConstPtr& pcmsg_in)
00074 {
00075 pcl::PointCloud<T> pc_in;
00076 pcl::fromROSMsg(*pcmsg_in,pc_in);
00077 return set_convex_hull(pc_in);
00078 };
00079
00085 pcl::PointCloud<T> get_pc_in_volume()
00086 {
00087 return pc_in_volume;
00088 };
00089
00099 t_func_output convexhull_function(pcl::PointCloud<T>& pc_in, double positive_offset, double negative_offset, bool flag_in_out)
00100 {
00101 if(!flag_convexhull_set)
00102 {
00103 ROS_ERROR("Flag not set to TRUE");
00104 return FAILURE;
00105 }
00106
00107 if(pc_in.header.frame_id!=convex_hull.header.frame_id)
00108 {
00109 #if _CONVEX_LIB_DEBUG_
00110 cout<<"convex_hull frame id "<<convex_hull.header.frame_id<<endl;
00111 cout<<"pc_in frame id on convexhull_function"<<pc_in.header.frame_id<<endl;
00112 #endif
00113 ROS_ERROR("Non-matching frame id's");
00114 return FAILURE;
00115 }
00116
00117 pcl::ExtractPolygonalPrismData<T> epp;
00118 typename pcl::PointCloud<T>::ConstPtr input_cloud_constptr;
00119 input_cloud_constptr.reset (new pcl::PointCloud<T> (pc_in));
00120 typename pcl::PointCloud<T>::ConstPtr convex_hull_constptr;
00121 convex_hull_constptr.reset (new pcl::PointCloud<T> (convex_hull));
00122
00123 pcl::ExtractIndices<T> extract;
00124 pcl::PointIndices::Ptr indices;
00125 indices.reset();
00126 indices = pcl::PointIndices::Ptr(new pcl::PointIndices);
00127
00128 pc_in_volume.header.frame_id=pc_in.header.frame_id;
00129
00130
00131 epp.setInputCloud(input_cloud_constptr);
00132 epp.setInputPlanarHull(convex_hull_constptr);
00133 epp.setHeightLimits(negative_offset,positive_offset);
00134 epp.setViewPoint(0,0,0);
00135 epp.segment(*indices);
00136
00137 pc_in_volume.points.clear();
00138 pc_in_volume.height=1;
00139 pc_in_volume.width=pc_in_volume.points.size();
00140 if ((int)indices->indices.size()!=0)
00141 {
00142 extract.setInputCloud(pc_in.makeShared());
00143 extract.setIndices(indices);
00144 extract.setNegative(flag_in_out);
00145 extract.filter(pc_in_volume);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 input_cloud_constptr.reset();
00158 convex_hull_constptr.reset();
00159 indices.reset();
00160 return SUCCESS;
00161 }
00162
00163
00164 private:
00165 pcl::PointCloud<T> pc_in_volume;
00166 bool flag_convexhull_set;
00167 pcl::PointCloud<T> convex_hull;
00168 };
00169
00170
00171 #endif