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 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
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
00087 ros::NodeHandle mNH;
00088
00089 RoSe::SID mPointcloudBlackboardSenderSID;
00090 RoSe::SID mSegmentedPlanesAndPointsRecieverSID;
00091
00092 RoSe::Mutex mMutex;
00093 RoSe::Condition mCondition;
00094 RoSe::Blackboard mPCBlackboard;
00095 MyThreadPtr mBBThread;
00096
00097 PointCloudPtr mLastPointCloud;
00098
00099
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