虽然之前装好了环境,也测试过了。但是记性真的差,没几个礼拜没搞就忘了……
重新创建了一个文件夹(PCL_Learning)专门用于学习pcl了,现在写第一个程序,创建了一个工程(Test_environment),开始吧。
KDevelop创建工程时会自动生成CMakeLists.txt文件。我们需要在里面添加pcl的内容。
CMakeLists.txt内容如下:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR) project(test_environment) find_package(PCL 1.8 REQUIRED COMPONENTS common io) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable(test_environment main.cpp) target_link_libraries(test_environment ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})
完成后需要编译,编译完成后继续主程序的编写。
2、main.cpp
程序来自于官方例子:http://pointclouds.org/documentation/tutorials/using_pcl_pcl_config.php#using-pcl-pcl-config
#include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ> cloud; // Fill in the cloud data cloud.width = 5; cloud.height = 1; cloud.is_dense = false; 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); cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); } pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud); std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << 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; return (0); }
最后main.cpp build->execute
测试结果如下:
Saved 5 data points to test_pcd.pcd. 0.352222 -0.151883 -0.106395 -0.397406 -0.473106 0.292602 -0.731898 0.667105 0.441304 -0.734766 0.854581 -0.0361733 -0.4607 -0.277468 -0.916762
回顾结束,继续看书学。
文章来源: PCL环境测试程序