00001 #include <pcl/point_cloud.h> 00002 #include <pcl/octree/octree.h> 00003 00004 #include <iostream> 00005 #include <vector> 00006 #include <ctime> 00007 00008 int 00009 main (int argc, char** argv) 00010 { 00011 srand ((unsigned int) time (NULL)); 00012 00013 // Octree resolution - side length of octree voxels 00014 float resolution = 32.0f; 00015 00016 // Instantiate octree-based point cloud change detection class 00017 pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree (resolution); 00018 00019 pcl::PointCloud<pcl::PointXYZ>::Ptr cloudA (new pcl::PointCloud<pcl::PointXYZ> ); 00020 00021 // Generate pointcloud data for cloudA 00022 cloudA->width = 128; 00023 cloudA->height = 1; 00024 cloudA->points.resize (cloudA->width * cloudA->height); 00025 00026 for (size_t i = 0; i < cloudA->points.size (); ++i) 00027 { 00028 cloudA->points[i].x = 64.0f * rand () / (RAND_MAX + 1.0f); 00029 cloudA->points[i].y = 64.0f * rand () / (RAND_MAX + 1.0f); 00030 cloudA->points[i].z = 64.0f * rand () / (RAND_MAX + 1.0f); 00031 } 00032 00033 // Add points from cloudA to octree 00034 octree.setInputCloud (cloudA); 00035 octree.addPointsFromInputCloud (); 00036 00037 // Switch octree buffers: This resets octree but keeps previous tree structure in memory. 00038 octree.switchBuffers (); 00039 00040 pcl::PointCloud<pcl::PointXYZ>::Ptr cloudB (new pcl::PointCloud<pcl::PointXYZ> ); 00041 00042 // Generate pointcloud data for cloudB 00043 cloudB->width = 128; 00044 cloudB->height = 1; 00045 cloudB->points.resize (cloudB->width * cloudB->height); 00046 00047 for (size_t i = 0; i < cloudB->points.size (); ++i) 00048 { 00049 cloudB->points[i].x = 64.0f * rand () / (RAND_MAX + 1.0f); 00050 cloudB->points[i].y = 64.0f * rand () / (RAND_MAX + 1.0f); 00051 cloudB->points[i].z = 64.0f * rand () / (RAND_MAX + 1.0f); 00052 } 00053 00054 // Add points from cloudB to octree 00055 octree.setInputCloud (cloudB); 00056 octree.addPointsFromInputCloud (); 00057 00058 std::vector<int> newPointIdxVector; 00059 00060 // Get vector of point indices from octree voxels which did not exist in previous buffer 00061 octree.getPointIndicesFromNewVoxels (newPointIdxVector); 00062 00063 // Output points 00064 std::cout << "Output from getPointIndicesFromNewVoxels:" << std::endl; 00065 for (size_t i = 0; i < newPointIdxVector.size (); ++i) 00066 std::cout << i << "# Index:" << newPointIdxVector[i] 00067 << " Point:" << cloudB->points[newPointIdxVector[i]].x << " " 00068 << cloudB->points[newPointIdxVector[i]].y << " " 00069 << cloudB->points[newPointIdxVector[i]].z << std::endl; 00070 00071 }