Go to the documentation of this file.00001 #include "bounding_box.h"
00002
00003 using namespace Eigen;
00004
00005
00006 FilterBB::FilterBB() {
00007
00008
00009
00010
00011 if (!this->nh.getParam("/bounding_box/x_s", this->x_s)){
00012 this->x_s = -0.5;
00013 this->nh.setParam("/bounding_box/x_s", this->x_s);
00014 }
00015 if (!this->nh.getParam("/bounding_box/y_s", this->y_s)){
00016 this->y_s = -0.5;
00017 this->nh.setParam("/bounding_box/y_s", this->y_s);
00018 }
00019 if (!this->nh.getParam("/bounding_box/z_s", this->z_s)){
00020 this->z_s = 0.1;
00021 this->nh.setParam("/bounding_box/z_s", this->z_s);
00022 }
00023 if (!this->nh.getParam("/bounding_box/x_e", this->x_e)){
00024 this->x_e = 0.5;
00025 this->nh.setParam("/bounding_box/x_e", this->x_e);
00026 }
00027 if (!this->nh.getParam("/bounding_box/y_e", this->y_e)){
00028 this->y_e = 0.5;
00029 this->nh.setParam("/bounding_box/y_e", this->y_e);
00030 }
00031 if (!this->nh.getParam("/bounding_box/z_e", this->z_e)){
00032 this->z_e = 0.3;
00033 this->nh.setParam("/bounding_box/z_e", this->z_e);
00034 }
00035
00036
00037
00038 std::string pcl2_sub_name;
00039 std::string pcl2_pub_name;
00040
00041
00042 pcl2_sub_name = "input";
00043 this->pcl2_sub = this->nh.subscribe<sensor_msgs::PointCloud2>(pcl2_sub_name, 1, &FilterBB::pcl2_sub_callback, this);
00044
00045
00046 pcl2_pub_name = "/bounding_box/pcl2_bbf";
00047 this->pcl2_pub = this->nh.advertise<sensor_msgs::PointCloud2>(pcl2_pub_name, 15);
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 ROS_INFO("starting bounding_box_filter_node with limts = (%f, %f, %f) - (%f, %f, %f)", this->x_s, this->y_s, this->z_s, this->x_e, this->y_e, this->z_e);
00058 ROS_INFO("Use [ rosparam set /bounding_box/x_s 2.0 ] to change the current X coord start limit");
00059 }
00060
00061 FilterBB::~FilterBB(){
00062
00063 }
00064
00065
00066 void FilterBB::pcl2_sub_callback(const sensor_msgs::PointCloud2::ConstPtr& pcl2_msg_) {
00067 sensor_msgs::PointCloud2 PointCloud2_msg_;
00068
00069
00070
00071 PointCloud2_msg_.header.frame_id = pcl2_msg_->header.frame_id;
00072 PointCloud2_msg_.header.stamp = pcl2_msg_->header.stamp;
00073 PointCloud2_msg_.height = pcl2_msg_->height;
00074 PointCloud2_msg_.width = pcl2_msg_->width;
00075 PointCloud2_msg_.fields.resize (4);
00076 PointCloud2_msg_.fields[0].name = "x";
00077 PointCloud2_msg_.fields[1].name = "y";
00078 PointCloud2_msg_.fields[2].name = "z";
00079 PointCloud2_msg_.fields[3].name = "intensity";
00080
00081
00082 int offset = 0;
00083 for (size_t s = 0; s < PointCloud2_msg_.fields.size (); ++s, offset += 4)
00084 {
00085 PointCloud2_msg_.fields[s].offset = offset;
00086 PointCloud2_msg_.fields[s].count = 1;
00087 PointCloud2_msg_.fields[s].datatype = sensor_msgs::PointField::FLOAT32;
00088 }
00089
00090 PointCloud2_msg_.point_step = offset;
00091 PointCloud2_msg_.row_step = PointCloud2_msg_.point_step * PointCloud2_msg_.width;
00092 PointCloud2_msg_.data.resize (PointCloud2_msg_.row_step * PointCloud2_msg_.height);
00093 PointCloud2_msg_.is_dense = true;
00094
00095
00096
00097 this->nh.getParam("/bounding_box/x_s", this->x_s);
00098 this->nh.getParam("/bounding_box/y_s", this->y_s);
00099 this->nh.getParam("/bounding_box/z_s", this->z_s);
00100 this->nh.getParam("/bounding_box/x_e", this->x_e);
00101 this->nh.getParam("/bounding_box/y_e", this->y_e);
00102 this->nh.getParam("/bounding_box/z_e", this->z_e);
00103
00104 for (unsigned int rr=0; rr<pcl2_msg_->height; rr++){
00105 for (unsigned int cc=0; cc<pcl2_msg_->width; cc++){
00106 int idx0 = rr*pcl2_msg_->width + cc;
00107 float *pstep = (float*)&pcl2_msg_->data[idx0 * pcl2_msg_->point_step];
00108 float *nstep = (float*)&PointCloud2_msg_.data[idx0 * PointCloud2_msg_.point_step];
00109
00110 float x_ = nstep[0] = pstep[0];
00111 float y_ = nstep[1] = pstep[1];
00112 float z_ = nstep[2] = pstep[2];
00113 nstep[3] = pstep[3];
00114
00115
00116 if ( x_ < this->x_s || y_ < this->y_s || z_ < this->z_s || x_ > this->x_e || y_ > this->y_e || z_ > this->z_e)
00117 nstep[0] = nstep[1] = nstep[2] = nstep[3] = NAN;
00118 }
00119 }
00120
00121
00122 this->pcl2_pub.publish(PointCloud2_msg_);
00123
00124 }
00125
00126 int main(int argc, char** argv)
00127 {
00128 ros::init(argc, argv, "bounding_box");
00129 FilterBB filter_bb;
00130 ros::spin();
00131 return 0;
00132 }
00133