Go to the documentation of this file.00001 #include <ui_organized_segmentation_demo.h>
00002
00003 #include <QMainWindow>
00004 #include <QMutex>
00005 #include <QTimer>
00006
00007 #include <boost/thread/thread.hpp>
00008
00009 #include <pcl/point_cloud.h>
00010 #include <pcl/point_types.h>
00011 #include <pcl/io/openni_grabber.h>
00012 #include <pcl/io/oni_grabber.h>
00013 #include <pcl/io/pcd_grabber.h>
00014 #include <pcl/io/pcd_io.h>
00015 #include <pcl/common/time.h>
00016 #include <pcl/visualization/pcl_visualizer.h>
00017 #include <pcl/filters/voxel_grid.h>
00018 #include <pcl/features/integral_image_normal.h>
00019 #include <pcl/segmentation/organized_multi_plane_segmentation.h>
00020 #include <pcl/segmentation/planar_polygon_fusion.h>
00021 #include <pcl/common/transforms.h>
00022 #include <pcl/segmentation/plane_coefficient_comparator.h>
00023 #include <pcl/segmentation/euclidean_plane_coefficient_comparator.h>
00024 #include <pcl/segmentation/rgb_plane_coefficient_comparator.h>
00025 #include <pcl/segmentation/edge_aware_plane_comparator.h>
00026 #include <pcl/segmentation/euclidean_cluster_comparator.h>
00027 #include <pcl/segmentation/organized_connected_component_segmentation.h>
00028
00029 typedef pcl::PointXYZRGBA PointT;
00030
00031
00032 #define FPS_CALC(_WHAT_) \
00033 do \
00034 { \
00035 static unsigned count = 0;\
00036 static double last = pcl::getTime ();\
00037 double now = pcl::getTime (); \
00038 ++count; \
00039 if (now - last >= 1.0) \
00040 { \
00041 std::cout << "Average framerate("<< _WHAT_ << "): " << double(count)/double(now - last) << " Hz" << std::endl; \
00042 count = 0; \
00043 last = now; \
00044 } \
00045 }while(false)
00046
00047 namespace Ui
00048 {
00049 class MainWindow;
00050 }
00051
00052 class OrganizedSegmentationDemo : public QMainWindow
00053 {
00054 Q_OBJECT
00055 public:
00056 typedef pcl::PointCloud<PointT> Cloud;
00057 typedef Cloud::Ptr CloudPtr;
00058 typedef Cloud::ConstPtr CloudConstPtr;
00059
00060
00061 OrganizedSegmentationDemo(pcl::Grabber& grabber);
00062
00063 ~OrganizedSegmentationDemo ()
00064 {
00065 if(grabber_.isRunning())
00066 grabber_.stop();
00067 }
00068
00069 void cloud_cb (const CloudConstPtr& cloud);
00070
00071 protected:
00072 boost::shared_ptr<pcl::visualization::PCLVisualizer> vis_;
00073 pcl::Grabber& grabber_;
00074
00075 QMutex mtx_;
00076 QMutex vis_mtx_;
00077 Ui::MainWindow *ui_;
00078 QTimer *vis_timer_;
00079 pcl::PointCloud<PointT> prev_cloud_;
00080 pcl::PointCloud<pcl::Normal> prev_normals_;
00081 std::vector<pcl::PlanarRegion<PointT>, Eigen::aligned_allocator<pcl::PlanarRegion<PointT> > > prev_regions_;
00082 float* prev_distance_map_;
00083
00084 pcl::PointCloud<PointT>::CloudVectorType prev_clusters_;
00085
00086 pcl::IntegralImageNormalEstimation<PointT, pcl::Normal> ne;
00087 pcl::OrganizedMultiPlaneSegmentation<PointT, pcl::Normal, pcl::Label> mps;
00088
00089 bool capture_;
00090 bool data_modified_;
00091 size_t previous_data_size_;
00092 size_t previous_clusters_size_;
00093
00094 bool display_normals_;
00095 bool display_curvature_;
00096 bool display_distance_map_;
00097
00098 bool use_planar_refinement_;
00099 bool use_clustering_;
00100
00101 pcl::PlaneCoefficientComparator<PointT, pcl::Normal>::Ptr plane_comparator_;
00102 pcl::EuclideanPlaneCoefficientComparator<PointT, pcl::Normal>::Ptr euclidean_comparator_;
00103 pcl::RGBPlaneCoefficientComparator<PointT, pcl::Normal>::Ptr rgb_comparator_;
00104 pcl::RGBPlaneCoefficientComparator<PointT, pcl::Normal> rgb_comp_;
00105 pcl::EdgeAwarePlaneComparator<PointT, pcl::Normal>::Ptr edge_aware_comparator_;
00106 pcl::EuclideanClusterComparator<PointT, pcl::Normal, pcl::Label>::Ptr euclidean_cluster_comparator_;
00107
00108 public slots:
00109 void toggleCapturePressed()
00110 {
00111 capture_ = !capture_;
00112 }
00113
00114 void usePlaneComparatorPressed ();
00115 void useEuclideanComparatorPressed ();
00116 void useRGBComparatorPressed ();
00117 void useEdgeAwareComparatorPressed ();
00118
00119 void displayCurvaturePressed ();
00120 void displayDistanceMapPressed ();
00121 void displayNormalsPressed ();
00122
00123 void disableRefinementPressed ()
00124 {
00125 use_planar_refinement_ = false;
00126 }
00127
00128 void usePlanarRefinementPressed ()
00129 {
00130 use_planar_refinement_ = true;
00131 }
00132
00133 void disableClusteringPressed ()
00134 {
00135 use_clustering_ = false;
00136 }
00137
00138 void useEuclideanClusteringPressed ()
00139 {
00140 use_clustering_ = true;
00141 }
00142
00143
00144 private slots:
00145 void
00146 timeoutSlot();
00147
00148
00149 };