GuiNode.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Fraunhofer FKIE
00003  *
00004  * Authors: Bastian Gaspers
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * * Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * * Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * * Neither the name of the Fraunhofer FKIE nor the names of its
00015  *   contributors may be used to endorse or promote products derived from
00016  *   this software without specific prior written permission.
00017  *
00018  * This file is part of the StructureColoring ROS package.
00019  *
00020  * The StructureColoring ROS package is free software:
00021  * you can redistribute it and/or modify it under the terms of the
00022  * GNU Lesser General Public License as published by the Free
00023  * Software Foundation, either version 3 of the License, or
00024  * (at your option) any later version.
00025  *
00026  * The StructureColoring ROS package is distributed in the hope that it will be useful,
00027  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00028  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029  * GNU Lesser General Public License for more details.
00030  *
00031  * You should have received a copy of the GNU Lesser General Public License
00032  * along with The StructureColoring ROS package.
00033  * If not, see <http://www.gnu.org/licenses/>.
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 /* GUINODE_H_ */


structure_coloring_fkie
Author(s): Bastian Gaspers
autogenerated on Sun Jan 5 2014 11:38:09