Go to the documentation of this file.00001 #include "height_from_plane_map.h"
00002
00003 using namespace Eigen;
00004
00005
00006 HeightFromPlaneMap::HeightFromPlaneMap(){
00007
00008
00009
00010
00011
00012
00013 coefficients_sub_.subscribe(nh_,ros::names::append(ros::this_node::getName(),"ModelCoefficients/input"), 1);
00014 pcl2_sub_.subscribe(nh_, ros::names::append(ros::this_node::getName(),"pcl2/input"), 1);
00015 sync_ = new message_filters::TimeSynchronizer<pcl::ModelCoefficients, sensor_msgs::PointCloud2>(coefficients_sub_, pcl2_sub_, 10);
00016 sync_->registerCallback(boost::bind(&HeightFromPlaneMap::height_map_callback, this, _1, _2));
00017
00018
00019 pcl2_pub_ = nh_.advertise<sensor_msgs::PointCloud2>( ros::names::append(ros::this_node::getName(),"pcl2/output"), 1);
00020
00021
00022 dynamic_reconfigure::Server<iri_pcl_filters::IriPclFiltersParametersConfig>::CallbackType reconfig_callback_type = boost::bind(&HeightFromPlaneMap::reconfigureCallback, this, _1, _2);
00023
00024 dyn_reconfig_srv.setCallback(reconfig_callback_type);
00025
00026
00027
00028
00029
00030
00031
00032 ROS_INFO("starting height_from_plane_map");
00033
00034 }
00035
00036 void HeightFromPlaneMap::reconfigureCallback(iri_pcl_filters::IriPclFiltersParametersConfig &config, uint32_t level)
00037 {
00038 ROS_INFO("Reconfigure request : distance th: %f lasting_cloud: %f #planes: %d ",
00039 config.distance_threshold, config.cloud_remaining_proportion_threshold, config.max_num_of_planes_removed);
00040
00041 mutex.enter();
00042 mutex.exit();
00043
00044 }
00045
00046
00047 void HeightFromPlaneMap::height_map_callback(const pcl::ModelCoefficients::ConstPtr& coefficients_msg, const sensor_msgs::PointCloud2::ConstPtr& pcl2_msg) {
00048
00049 pcl::fromROSMsg(*pcl2_msg, pcl_xyzrgb_);
00050
00051
00052 std::vector<float> coefficients = coefficients_msg->values;
00053
00054
00055 pcl::PointCloud<pcl::PointXYZRGB>::iterator pt_iter_xyzrgb = pcl_xyzrgb_.begin();
00056
00057 for (int rr = 0; rr < pcl_xyzrgb_.height; ++rr) {
00058 for (int cc = 0; cc < pcl_xyzrgb_.width; ++cc, ++pt_iter_xyzrgb) {
00059 if(!(isnan(pt_iter_xyzrgb->x) && isnan(pt_iter_xyzrgb->y) && isnan(pt_iter_xyzrgb->z))){
00060
00061 pt_iter_xyzrgb->rgb = distance_from_plane(pt_iter_xyzrgb->x, pt_iter_xyzrgb->y, pt_iter_xyzrgb->z, coefficients);
00062 }else{
00063
00064 pt_iter_xyzrgb->rgb = 0;
00065 }
00066 }
00067 }
00068
00069 pcl::toROSMsg(pcl_xyzrgb_, pcl2_score_map_msg_);
00070
00071 pcl2_pub_.publish(pcl2_score_map_msg_);
00072 ROS_INFO("Height score map published ");
00073
00074 }
00075
00076 float HeightFromPlaneMap::distance_from_plane(double x, double y, double z, std::vector<float> coefs){
00077
00078 float distance = 0;
00079 float mod = sqrt(coefs[0]*coefs[0] + coefs[1]*coefs[1] + coefs[2]*coefs[2] + coefs[3]*coefs[3]);
00080 distance = coefs[0]*x + coefs[1]*y + coefs[2]*z + coefs[3];
00081 distance = distance/mod;
00082
00083 distance = distance*-1000;
00084 if(distance < 0)
00085 return -distance;
00086 return distance;
00087 }
00088
00089 int main(int argc, char** argv)
00090 {
00091 ros::init(argc, argv, "height_from_plane_map");
00092 HeightFromPlaneMap height_from_plane_map;
00093 ros::spin();
00094 return 0;
00095 }
00096