2015-04-22 11:33:11 +00:00
|
|
|
#include <ros/ros.h>
|
|
|
|
#include <pcl_ros/point_cloud.h>
|
|
|
|
#include <pcl/point_types.h>
|
2015-04-22 19:38:54 +00:00
|
|
|
#include <pcl/filters/passthrough.h>
|
2015-04-22 11:33:11 +00:00
|
|
|
|
2015-04-22 15:22:16 +00:00
|
|
|
typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloud;
|
2015-04-22 12:02:53 +00:00
|
|
|
|
2015-04-22 14:53:52 +00:00
|
|
|
class Callback {
|
2015-04-22 11:33:11 +00:00
|
|
|
public:
|
2015-04-22 19:38:54 +00:00
|
|
|
void
|
|
|
|
operator()(const PointCloud::ConstPtr& msg)
|
|
|
|
{
|
|
|
|
PointCloud::Ptr pcl(new PointCloud());
|
2015-04-30 15:23:17 +00:00
|
|
|
for (int i = 0; i < msg->points.size(); ++i)
|
|
|
|
{
|
2015-04-30 15:30:53 +00:00
|
|
|
if (msg->points[i].z < zmax)
|
2015-04-30 15:23:17 +00:00
|
|
|
pcl->points.push_back(msg->points[i]);
|
|
|
|
}
|
2015-04-22 19:38:54 +00:00
|
|
|
publisher.publish(pcl);
|
|
|
|
}
|
|
|
|
|
2015-04-30 15:30:53 +00:00
|
|
|
Callback(ros::Publisher& pub, float z)
|
|
|
|
: publisher(pub), zmax(z) {}
|
2015-04-22 16:31:16 +00:00
|
|
|
|
2015-04-22 12:02:53 +00:00
|
|
|
private:
|
2015-04-22 14:53:52 +00:00
|
|
|
ros::Publisher publisher;
|
2015-04-30 15:30:53 +00:00
|
|
|
float zmax;
|
2015-04-22 11:33:11 +00:00
|
|
|
};
|
|
|
|
|
2015-04-22 19:38:54 +00:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2015-04-22 11:33:11 +00:00
|
|
|
{
|
2015-04-22 12:02:53 +00:00
|
|
|
ros::init(argc, argv, "filtre");
|
2015-04-23 10:29:04 +00:00
|
|
|
ros::NodeHandle node("filtre");
|
2015-04-22 19:38:54 +00:00
|
|
|
|
|
|
|
// récupération des paramètres
|
|
|
|
double zmax(0);
|
|
|
|
if (node.getParam("zmax", zmax))
|
|
|
|
{
|
|
|
|
ROS_INFO("zmax : %f" , zmax);
|
|
|
|
} else {
|
|
|
|
node.setParam("zmax", 50.0);
|
|
|
|
node.getParam("zmax", zmax);
|
|
|
|
ROS_INFO("zmax : %f (default value)", zmax);
|
|
|
|
}
|
|
|
|
|
2015-04-30 15:30:53 +00:00
|
|
|
// initialisatio
|
2015-04-23 10:29:04 +00:00
|
|
|
ros::Publisher publisher = node.advertise<PointCloud>("output", 1);
|
2015-04-30 15:30:53 +00:00
|
|
|
Callback callback(publisher, (float) zmax);
|
2015-04-23 10:29:04 +00:00
|
|
|
ros::Subscriber subscriber = node.subscribe<PointCloud>("input", 1, callback);
|
2015-04-22 19:38:54 +00:00
|
|
|
|
|
|
|
// démarrage
|
2015-04-22 16:31:16 +00:00
|
|
|
ROS_INFO("node started");
|
2015-04-22 12:02:53 +00:00
|
|
|
ros::spin();
|
2015-04-22 16:31:16 +00:00
|
|
|
ROS_INFO("exit");
|
2015-04-22 12:02:53 +00:00
|
|
|
return 0;
|
2015-04-22 11:33:11 +00:00
|
|
|
}
|