RosVisualization.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 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 //TODO make topics and frame configurable
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 //              segCloud.points.push_back( pointCloud.points[i] );
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 /* ROSVISUALIZATION_H_ */


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