StrColRoSeService.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 STRCOLROSESERVICE_H_
00037 #define STRCOLROSESERVICE_H_
00038 
00039 #include <boost/shared_ptr.hpp>
00040 #include <boost/scoped_ptr.hpp>
00041 #include <boost/thread.hpp>
00042 #include <Eigen/Dense>
00043 #include <Eigen/StdVector>
00044 #include <ros/ros.h>
00045 #include <RoSe/Blackboard.h>
00046 #include <RoSe/Color8.h>
00047 #include <RoSe/Condition.h>
00048 #include <RoSe/Config.h>
00049 #include <RoSe/ConfigService.h>
00050 #include <RoSe/Message.h>
00051 #include <RoSe/MsgPointCloud3fc.h>
00052 #include <RoSe/Mutex.h>
00053 #include <RoSe/PointCloud.h>
00054 #include <RoSe/Quaternion.h>
00055 #include <RoSe/Service.h>
00056 #include <RoSe/SID.h>
00057 #include <RoSe/MsgTexturedPlaneSegment.h>
00058 #include <structureColoring/StructureColoring.h>
00059 
00060 class StrColRoSeService : public RoSe::Service {
00061 private:
00062 //typedefs
00063         typedef Eigen::Vector3f Vec3;
00064         typedef std::vector<Vec3, Eigen::aligned_allocator<Vec3> > EigenPoints;
00065 
00066         typedef pcl::PointXYZRGB PointT;
00067         typedef pcl::PointCloud<PointT> PointCloud;
00068         typedef boost::shared_ptr<PointCloud> PointCloudPtr;
00069         typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
00070 
00071     typedef RoSe::PointT<float, 3, RoSe::Color8> Point3fc;
00072         typedef RoSe::PointCloud<Point3fc, RoSe::Quaternion> RosePointcloud;
00073         typedef RoSe::PointCloud<Point3fc, RoSe::Quaternion>::Points RoSePointCloudPoints;
00074         typedef boost::shared_ptr<RosePointcloud> RosePointcloudPtr;
00075 
00076         typedef RoSe::PointT<float, 3> Point3f;
00077         typedef std::vector<Point3f> Points3f;
00078 
00079         typedef StructureColoring::PlanePatchVector PlanePtrs;
00080         typedef StructureColoring::PlanePatches Planes;
00081         typedef StructureColoring::CylinderPatchVector CylinderPtrs;
00082         typedef StructureColoring::CylinderPatches Cylinders;
00083 
00084         typedef boost::scoped_ptr<boost::thread> MyThreadPtr;
00085 
00086 //ros communication
00087         ros::NodeHandle mNH;
00088 //RoSe communication
00089         RoSe::SID mPointcloudBlackboardSenderSID;
00090         RoSe::SID mSegmentedPlanesAndPointsRecieverSID;
00091 //thread and inter-thread communication
00092     RoSe::Mutex mMutex;
00093     RoSe::Condition mCondition;
00094         RoSe::Blackboard mPCBlackboard;
00095     MyThreadPtr mBBThread;
00096 //data
00097     PointCloudPtr mLastPointCloud;
00098 
00099 //computing object
00100     StructureColoring mStrCol;
00101 protected:
00102         void initialize();
00103         void execute();
00104         void terminate();
00105         void stop();
00106 
00107         void receiveMsg(const RoSe::SID&, const RoSe::Message::Ptr);
00108 
00109     static void convertPoint(Point3f& outPointRoSe, const Vec3& inPointEigen);
00110     static void convertPoints(Points3f& brVertices, const EigenPoints& points);
00111     static void extractUnmappedPointsToRosePC(RosePointcloudPtr unsegmentedPoints, PointCloudPtr mLastPointCloud, PlanePtrs pointMapping);
00112     static void generateAlphamap(std::vector<bool>& alphamap, const cv::Mat& tempMat);
00113     static void encodeHeightmap(std::vector<unsigned char>& encodedHeightmap, const cv::Mat& heightmap,
00114                 float widthRatio, float heightRatio);
00115     static void encodeTexturemap(std::vector<unsigned char>& encodedTexturemap, std::vector<bool>& alphamap,
00116                 const cv::Mat& texturemap, float widthRatio, float heightRatio);
00117     void sendPlanes(const Planes& planes);
00118     void sendPoints(RosePointcloudPtr pointCloud);
00119 
00120     void blackboardReadRun();
00121         bool connectBlackboard();
00122         void readBlackboard();
00123 
00124 public:
00125 
00133         StrColRoSeService(const RoSe::SID &sid);
00134 
00135         virtual ~StrColRoSeService();
00136         virtual void finish();
00137 
00141         static Service::Ptr create(const RoSe::SID &sid);
00142 };
00143 
00144 /*****************************************************************************/
00145 
00146 inline void StrColRoSeService::convertPoint(Point3f& outPointRoSe, const Vec3& inPointEigen){
00147         outPointRoSe[0] = inPointEigen.x();
00148         outPointRoSe[1] = inPointEigen.y();
00149         outPointRoSe[2] = inPointEigen.z();
00150 }
00151 
00152 /*****************************************************************************/
00153 
00154 inline void StrColRoSeService::convertPoints(Points3f& brVertices, const EigenPoints& points){
00155         brVertices.reserve(4);
00156         for(EigenPoints::const_iterator pit = points.begin(); pit != points.end(); ++pit){
00157                 Point3f p;
00158                 convertPoint(p, *pit);
00159                 brVertices.push_back(p);
00160         }
00161 }
00162 
00163 /*****************************************************************************/
00164 
00165 #endif /* STRCOLROSESERVICE_H_ */


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