Академический Документы
Профессиональный Документы
Культура Документы
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
Point Cloud Library About News Blog Downloads Media Documentation Jobs Contact Tutorials Advanced
Documentation
The code
First, create a file, lets say, passthrough.cpp in your favorite editor, and place the following inside it:
1 trong 7 3/19/2013 7:08 AM
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include <iostream> #include <pcl/point_types.h> #include <pcl/filters/passthrough.h> int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>); // Fill in the cloud data cloud->width = 5; cloud->height = 1; cloud->points.resize (cloud->width * cloud->height); for (size_t i = 0; i { cloud->points[i].x cloud->points[i].y cloud->points[i].z } < cloud->points.size (); ++i) = 1024 * rand () / (RAND_MAX + 1.0f); = 1024 * rand () / (RAND_MAX + 1.0f); = 1024 * rand () / (RAND_MAX + 1.0f);
std::cerr << "Cloud before filtering: " << std::endl; for (size_t i = 0; i < cloud->points.size (); ++i) std::cerr << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << std::endl; // Create the filtering object pcl::PassThrough<pcl::PointXYZ> pass;
2 trong 7
3/19/2013 7:08 AM
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
33 34 35 36 37 38 39 40 41 42 43 44 }
pass.setInputCloud (cloud); pass.setFilterFieldName ("z"); pass.setFilterLimits (0.0, 1.0); //pass.setFilterLimitsNegative (true); pass.filter (*cloud_filtered); std::cerr << "Cloud after filtering: " << std::endl; for (size_t i = 0; i < cloud_filtered->points.size (); ++i) std::cerr << " " << cloud_filtered->points[i].x << " " << cloud_filtered->points[i].y << " " << cloud_filtered->points[i].z << std::endl; return (0);
The explanation
Now, lets break down the code piece by piece. In the following lines, we define the Point Clouds structures, fill in the input cloud, and display its content to screen.
// Fill in the cloud data cloud->width = 5; cloud->height = 1; cloud->points.resize (cloud->width * cloud->height); for (size_t i = 0; i < cloud->points.size (); ++i) { cloud->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
3 trong 7
3/19/2013 7:08 AM
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
cloud->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); cloud->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); } std::cerr << "Cloud before filtering: " << std::endl; for (size_t i = 0; i < cloud->points.size (); ++i) std::cerr << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << std::endl;
Then, we create the PassThrough filter object, and set its parameters. The filter field name is set to the z coordinate, and the accepted interval values are set to (0.0;1.0).
pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud (cloud); pass.setFilterFieldName ("z"); pass.setFilterLimits (0.0, 1.0); //pass.setFilterLimitsNegative (true); pass.filter (*cloud_filtered);
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
After you have made the executable, you can run it. Simply do:
$ ./passthrough
5 trong 7
3/19/2013 7:08 AM
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
Note that the coordinate axis are represented as red (x), green (y), and blue (z). The five points are represented with green as the points remaining after filtering and red as the points that have been removed by the filter. As an exercise, try uncommenting this line
//pass.setFilterLimitsNegative (true);
6 trong 7
3/19/2013 7:08 AM
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
and run the program again. Our Youtube channel Google+ Facebook Follow us on Twitter Site map Except where otherwise noted, the PointClouds.org web pages are licensed under Creative Commons Attribution 3.0.
7 trong 7
3/19/2013 7:08 AM