-
Notifications
You must be signed in to change notification settings - Fork 0
/
004_基于Octree点云变化检测.cpp
53 lines (46 loc) · 1.63 KB
/
004_基于Octree点云变化检测.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<pcl/point_cloud.h>
#include<pcl/io/io.h>
#include<pcl/point_types.h>
#include<pcl/octree/octree_search.h>
#include <pcl/octree/octree_pointcloud_changedetector.h>
#include<vector>
using namespace std;
int main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->height = 1000;
cloud->width = 1;
cloud->is_dense = true;
cloud->resize(cloud->width*cloud->height);
for (size_t i = 0; i < cloud->size(); i++) {
cloud->points[i].x = 1024.0f*rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024.0f*rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024.0f*rand() / (RAND_MAX + 1.0f);
}
float resolution = 200.0f;
pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree(resolution);
octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud1(new pcl::PointCloud < pcl::PointXYZ>);
cloud1->height = 1000;
cloud1->width = 1;
cloud1->is_dense = true;
cloud1->resize(cloud1->height*cloud1->width);
for (size_t j = 0; j < cloud1->size(); j++) {
cloud1->points[j].x = 1024.0f*rand() / (RAND_MAX + 1.0f);
cloud1->points[j].y = 1024.0f*rand() / (RAND_MAX + 1.0f);
cloud1->points[j].z = 1024.0f*rand() / (RAND_MAX + 1.0f);
}
octree.switchBuffers();
octree.setInputCloud(cloud1);
octree.addPointsFromInputCloud();
vector<int> Idx;
octree.getPointIndicesFromNewVoxels(Idx);
cout << "There are " << Idx.size() << " new voxels" << endl;;
for (size_t k = 0; k < Idx.size(); k++) {
cout << "#" << k << ": " << cloud1->points[Idx[k]].x << " "
<< cloud1->points[Idx[k]].y << " "
<< cloud1->points[Idx[k]].z << endl;
}
}