DetectChanges-PCL-Cpp (50%)
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/octree/octree_pointcloud_changedetector.h>
#include <iostream>
#include <vector>
#include <ctime>
//Spatial change detection on unorganized point cloud data
//http://pointclouds.org/documentation/tutorials/octree_change.php#octree-change-detection
//Commnets : Hunjung, Lim (hunjung.lim@hotmail.com)
int
main (int argc, char** argv)
{
//๋ณต์
ํฌ๊ธฐ ์ค์ (Set octree voxel resolution)
float resolution = 0.01f; //side length of octree voxels
// Class ์ด๊ธฐํ (Instantiate octree-based point cloud change detection class)
pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZRGB> octree (resolution);
// *.PCD ํ์ผ ์ฝ๊ธฐ (https://raw.githubusercontent.com/adioshun/gitBook_Tutorial_PCL/master/Intermediate/sample/RANSAC_plane_false.pcd)
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudA (new pcl::PointCloud<pcl::PointXYZRGB> );
pcl::io::loadPCDFile<pcl::PointXYZRGB>("RANSAC_plane_false.pcd", *cloudA);
// ํฌ์ธํธ ํด๋ผ์ฐ๋๋ฅผ Octree ์ ์ฉ (Add points from cloudA to octree)
octree.setInputCloud (cloudA);
octree.addPointsFromInputCloud ();
// ๊ธฐ์กด ํธ๋ฆฌ ๊ตฌ์กฐ๋ ์ ์งํ์ํ๋ก Octree ์ด๊ธฐํ (Switch octree buffers: This resets octree but keeps previous tree structure in memory.)
octree.switchBuffers ();
// *.PCD ํ์ผ ์ฝ๊ธฐ (https://raw.githubusercontent.com/adioshun/gitBook_Tutorial_PCL/master/Intermediate/sample/tabletop_passthrough.pcd)
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudB (new pcl::PointCloud<pcl::PointXYZRGB> );
pcl::io::loadPCDFile<pcl::PointXYZRGB>("tabletop_passthrough.pcd", *cloudB);
// ํฌ์ธํธ ํด๋ผ์ฐ๋๋ฅผ Octree ์ ์ฉ(Add points from cloudB to octree)
octree.setInputCloud (cloudB);
octree.addPointsFromInputCloud ();
// ์ด์ ํฌ์ธํธํด๋ผ์ฐ๋์ ์กด์ฌ ํ์ง ์๋ ์ ์ ๊ตฐ์ Index ์ ์ฅ (Get vector of point indices from octree voxels which did not exist in previous buffer)
std::vector<int> newPointIdxVector;
octree.getPointIndicesFromNewVoxels (newPointIdxVector);
// ์ ๋ณด ์ถ๋ ฅ
std::cout << "Output from getPointIndicesFromNewVoxels:" << std::endl;
for (size_t i = 0; i < newPointIdxVector.size (); ++i)
std::cout << i << "# Index:" << newPointIdxVector[i]
<< " Point:" << cloudB->points[newPointIdxVector[i]].x << " "
<< cloudB->points[newPointIdxVector[i]].y << " "
<< cloudB->points[newPointIdxVector[i]].z << std::endl;
}
Last updated