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