Point Cloud Libraryを使って、今回はPLY形式のファイルから点群データを読み込んでみたいと思います。
方法としてはひじょうに簡単で、下記のようにpcl::PLYReaderクラスを使って読み込むことが出来ます。
#include #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/io/ply_io.h> const char filename[] = "Table.ply"; int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); pcl::PLYReader reader; if (reader.read<pcl::PointXYZ>(filename, *cloud) == -1) { PCL_ERROR("Couldn't read file Table.ply\n"); return (-1); } std::cout << "Loaded " << cloud->width * cloud->height << " data points from Table.ply with the following fields: " << std::endl; for (const auto& point: *cloud) std::cout << " " << point.x << " " << point.y << " " << point.z << std::endl; return (0); }
読み込むファイル名は適宜修正してください。うまく実行できると前回PCD形式のファイルを読み込んだときと同様に点群座標が表示されます。