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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef GUINODE_H_
00037 #define GUINODE_H_
00038
00039 #include <ros/ros.h>
00040 #include <QThread>
00041 #include <structureColoring/gui/StructureGL.h>
00042 #include <structureColoring/StructureColoring.h>
00043
00044 class GuiNode : public StructureColoring, public QThread{
00045 public:
00046 GuiNode(int argc, char** argv): StructureColoring(argc, argv), mGlWindow(0){
00047 ros::init(argc, argv, "structureColoring");
00048 ros::Time::init();
00049 initNode(*(new ros::NodeHandle));
00050 }
00051
00052 virtual ~GuiNode(){}
00053
00054 void init(StructureGL* glWindow){
00055 mGlWindow = glWindow;
00056 start();
00057 }
00058
00059 void getUnsegPointCloud (PointCloudPtr unsegPointCloud, const PointCloudPtr pointCloud, const PlanePatchVector& pointMapping){
00060 assert(pointCloud->points.size() == pointMapping.size());
00061 unsegPointCloud->points.reserve(pointCloud->points.size());
00062 for(size_t i = 0; i < pointMapping.size(); i++){
00063 if (pointMapping[i] != 0)
00064 continue;
00065 unsegPointCloud->points.push_back(pointCloud->points[i]);
00066 }
00067 unsegPointCloud->width = unsegPointCloud->points.size();
00068 unsegPointCloud->height = 1;
00069 }
00070
00071 void run(){
00072 ros::Rate loop_rate(10);
00073 if (waitOnKinectMsgs() || waitOnLaserMsgs())
00074 while (mNodeHandle->ok()) {
00075 ros::spinOnce();
00076 if (mGlWindow && mPointCloud){
00077 if (mPointCloudMutex.tryLock(100)){
00078 ROS_INFO("pointcloud(%zu) set.", mPointCloud->points.size());
00079 mGlWindow->setPointCloud(mPointCloud);
00080 PointCloudPtr unsegPoints = PointCloudPtr(new PointCloud());
00081 getUnsegPointCloud(unsegPoints, mPointCloud, mPointMapping);
00082 mGlWindow->setUnsegmentedPointCloud(unsegPoints);
00083 ROS_INFO("unsegmented pointcloud(%zu) set.", unsegPoints->points.size());
00084 mPointCloudMutex.unlock();
00085 }
00086 if (mPlanePatchesMutex.tryLock(100)){
00087 ROS_INFO("plane patches (%zu) set.", mPlanePatches.size());
00088 mGlWindow->setPlanePatches(mPlanePatches);
00089 mPlanePatchesMutex.unlock();
00090 }
00091 if (mCylinderPatchesMutex.tryLock(100)){
00092 ROS_INFO("cylinderPatches (%zu) set.", mCylinderPatches.size());
00093 mGlWindow->setCylinderPatches(mCylinderPatches);
00094 mCylinderPatchesMutex.unlock();
00095 }
00096 }
00097 loop_rate.sleep();
00098 }
00099 else {
00100 getPointsFromFile();
00101 if (mGlWindow && mPointCloud){
00102 if (mPointCloudMutex.tryLock(100)){
00103 ROS_INFO("pointcloud set.");
00104 mGlWindow->setPointCloud(mPointCloud);
00105 mPointCloudMutex.unlock();
00106 }
00107 if (mPlanePatchesMutex.tryLock(100)){
00108 ROS_INFO("plane patches (%zu) set.", mPlanePatches.size());
00109 mGlWindow->setPlanePatches(mPlanePatches);
00110 mPlanePatchesMutex.unlock();
00111 }
00112 }
00113 ros::waitForShutdown();
00114 }
00115 }
00116
00117 void stop(){
00118 ros::shutdown();
00119 }
00120
00121 private:
00122 StructureGL* mGlWindow;
00123 };
00124
00125 #endif