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 ROSVISUALIZATION_H_
00037 #define ROSVISUALIZATION_H_
00038
00039 #include <structureColoring/OcTree.h>
00040 #include <structureColoring/NodePair.h>
00041 #include <structureColoring/histograms/SphereUniformSampling.h>
00042 #include <structureColoring/structures/PlanePatch.h>
00043 #include <structureColoring/structures/CylinderPatch.h>
00044 #include <structureColoring/NormalEstimationValueClass.h>
00045 #include <octreelib/spatialaggregate/octree.h>
00046 #include <ros/ros.h>
00047 #include <pcl/point_types.h>
00048 #include <pcl/ros/conversions.h>
00049
00050
00051 class RosVisualization{
00052 public:
00053 typedef PlanePatch::PlanePatches PlanePatches;
00054 typedef std::vector<PlanePatch::PlanePatchPtr> PlanePatchVector;
00055 typedef CylinderPatch::CylinderPatches CylinderPatches;
00056 typedef algorithm::OcTreeSamplingMap<float, NormalEstimationValueClass> OctreeSamplingMap;
00057 typedef std::vector<SphereUniformSampling> SphereUniformSamplings;
00058 typedef PlanePatch::PointIndices PointIndices;
00059 typedef Eigen::Vector3f Vec3;
00060 typedef PlanePatch::Points Points;
00061 typedef pcl::PointXYZRGB PointT;
00062 typedef pcl::PointCloud<PointT> PointCloud;
00063 typedef OcTree::NodePointers NodePointers;
00064 typedef OcTree::NodePointerList NodePointerList;
00065
00066 RosVisualization(ros::NodeHandle& nh);
00067
00068 static void getColorByIndex(float *rgb, unsigned int index, unsigned int total);
00069
00070 void setFrame(const std::string& frame_id){mFrameID = frame_id;}
00071
00072 void publishPairMarker(const NodePairs& nodePairs);
00073 void publishPlaneMarker(const PlanePatches& planes, const std::string& namePrefix = "plane ");
00074 void publishCylinderMarker(const CylinderPatches& cylinders, const std::string& namePrefix = "cylinder ");
00075 void publishOctreeNormalMarker(const OcTree& octree);
00076 void publishHistogramMarker(const SphereUniformSampling& HTBins, const float& scale, const Eigen::Vector3f& translation);
00077 void publishHTBinCloud(const SphereUniformSamplings& HTBins);
00078 void publishHTBinCloud(PointCloud histogramCloud);
00079 template<typename PointAssignment, typename StructureContainer>
00080 void publishSegmentedPointcloud(const PointAssignment& segmented, const StructureContainer& planes, const PointCloud& pointCloud);
00081 void publishCylinderPoints(const CylinderPatches& cylinders, const boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> > inputPC);
00082 void publishPointCloud(const PointCloud& pointCloud);
00083 void publishPoints(const Points& points, const std::string& nameAppendix, const Vec3& color);
00084 void publishCylinderPointsNormals(const PointCloud& partCloud, const pcl::PointCloud<pcl::Normal>& normalCloud, const std::string& name = "no identifier");
00085 void printTopics();
00086
00087 private:
00088 ros::Publisher mHistogramPC2Publisher;
00089 ros::Publisher mPC2Publisher;
00090 ros::Publisher mSegmentedCloudPublisher;
00091 ros::Publisher mCylinderPointCloudPublisher;
00092 ros::Publisher mMarkerPublisher;
00093 ros::Publisher mCylinderMarkerPublisher;
00094 std::string mFrameID;
00095 std::string mLaserTopic;
00096 };
00097
00098 template<typename PointAssignment, typename StructureContainer>
00099 void RosVisualization::publishSegmentedPointcloud(const PointAssignment& segmented, const StructureContainer& planes, const PointCloud& pointCloud)
00100 {
00101 if (mSegmentedCloudPublisher.getNumSubscribers() == 0)return;
00102
00103 pcl::PointCloud<pcl::PointXYZRGB> segCloud;
00104 for (unsigned int i=0; i<segmented.size(); i++){
00105
00106
00107
00108 if (!segmented[i]){
00109 unsigned int rgb = 0x000000;
00110 pcl::PointXYZRGB p;
00111 p.x = pointCloud.points[i].x;
00112 p.y = pointCloud.points[i].y;
00113 p.z = pointCloud.points[i].z;
00114 p.rgb = *(float*)&rgb;
00115 segCloud.points.push_back(p);
00116 }
00117 }
00118
00119 unsigned int i=0;
00120 for (typename StructureContainer::const_iterator pit = planes.begin(); pit != planes.end() ; pit++){
00121 float rgb[3]={0.f,0.2f,0.5f};
00122 getColorByIndex(rgb, i, planes.size());
00123 unsigned int red = rgb[0] * 255.f + 0.5f;
00124 unsigned int green = rgb[1] * 255.f + 0.5f;
00125 unsigned int blue = rgb[2] * 255.f + 0.5f;
00126 unsigned int color = blue + (green<<8) + (red<<16);
00127 PointIndices inlierIndices = (*pit)->getInliers();
00128 for (PointIndices::iterator it=inlierIndices.begin(); it != inlierIndices.end(); it++){
00129 pcl::PointXYZRGB p;
00130 p.x = pointCloud.points[*it].x;
00131 p.y = pointCloud.points[*it].y;
00132 p.z = pointCloud.points[*it].z;
00133 p.rgb = *(float*)&color;
00134 segCloud.points.push_back(p);
00135
00136 }
00137 i++;
00138 }
00139
00140 sensor_msgs::PointCloud2 segMsg;
00141 pcl::toROSMsg<pcl::PointXYZRGB>(segCloud, segMsg);
00142 segMsg.header.frame_id=mFrameID;
00143 segMsg.header.stamp=ros::Time::now();
00144 mSegmentedCloudPublisher.publish(segMsg);
00145 }
00146
00147 #endif