-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
141 lines (109 loc) · 5.05 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* executable->PointCloudProcessing
*
* written by cyz on 20181223
*/
#include <iostream>
#include <vector>
#include <pcl-1.8/pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/pcd_io.h>
#include "smoothing.h"
#include "pcaAnalysis.h"
#include "buildingFacadeExtraction.h"
using namespace pcl;
int main()
{
PointCloud<PointXYZI>::Ptr pc(new PointCloud<PointXYZI>()) ;
PointCloud<PointXYZI>::Ptr pcSacn(new PointCloud<PointXYZI>()) ;
std::string xyzfileFolder = "./scans";
std::string filepath="../data/scans/1514275907-767137.xyz";
preprocess preprocessor;
// preprocessor.readpcfileFromFolder(xyzfileFolder);
preprocessor.xyz2pc(filepath,*pcSacn);
// preprocessor.txt2pc(filepath,*pc);
// pcl::PCDReader pcdReader;
// pcdReader.read(filepath, *pc);
// if(pcl::io::loadPCDFile<pcl::PointXYZI>
// ("/home/cyz/CLionProjects/PointCloudProcessing/bin/pointCloud_filtered.pcd",*pc) == -1)
// return 0;
cout<<"Read point cloud file successfully. "<<endl;
// preprocessor.visualize<pcl::PointXYZI>(pc,1,"point cloud");
PointCloud<PointXYZI>::Ptr pc_filtered(new PointCloud<PointXYZI>()) ;
// PointCloud<PointXYZI>::Ptr pc_filtered_downSample(new PointCloud<PointXYZI>()) ;
PointCloud<PointXYZI>::Ptr pc_filtered_plane(new PointCloud<PointXYZI>()) ;
// preprocessor.statisticalOutlierRemoval(pc,pc_filtered);///statistical outlier remove
// std::cout<<"statistical outlier removal Done"<<endl;
// preprocessor.visualize<pcl::PointXYZI>(pc_filtered,1,"point cloud filtered");
buildingFacadeExtractor bFE;
pcXYZIptr nonGroundCloud(new pcXYZI());
bFE.groundFilter(pc_filtered, nonGroundCloud);
std::cout<<"Ground filtered. "<<endl;
// preprocessor.visualize<pcl::PointXYZI>(nonGroundCloud,1, "non-ground cloud");
// preprocessor.visualize<pcl::PointXYZI>(pc_filtered,2);
bFE.constructVoxels(nonGroundCloud, 3.0);
bFE.meanShiftClustering(nonGroundCloud,3);
std::cout<<"mean shift done. "<<endl;
preprocessor.visualize<pcl::PointXYZI>(nonGroundCloud,2,"mean shifted cloud");
pcXYZIptr projectedCloud(new pcXYZI());
pcl::ModelCoefficients::Ptr planeParas(new pcl::ModelCoefficients());
planeParas->values.resize(4);
planeParas->values[0] = 0;
planeParas->values[1] = 0;
planeParas->values[2] = 1.0;
planeParas->values[3] = 0;
bFE.planeProjection(nonGroundCloud, planeParas, projectedCloud);
preprocessor.visualize<pcl::PointXYZI>(projectedCloud, 3, "projected cloud");
std::cout<<"Cloud projected. "<<endl;
// preprocess1.downSample(pc_filtered, pc_filtered_downSample);///voxel grid downsample
// std::vector<pcXYZI> pc_planes;
// if( preprocessor.planeSeg(pc_filtered, pc_planes) )///extract planes(from large to small)
// {
// for(size_t i=0 ; i<pc_planes.size() ; i++)
// {
// *pc_filtered_plane = pc_planes[i];
// preprocessor.visualize<pcl::PointXYZI>(pc_filtered_plane, i);
// cout << "plane size : " << pc_filtered_plane->points.size() << endl;
// }
//
// }
pcl::PointCloud<pcl::PointXYZRGB>::Ptr bigCurv(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::Normal>::Ptr pcNormals (new pcl::PointCloud<pcl::Normal>);
preprocessor.normalestimate(pc_filtered, pcNormals);///normal estimation
for(int i=0 ; i<pcNormals->points.size() ; i++)
if(pcNormals->points[i].curvature * 100 > 25){
pcl::PointXYZRGB ptRGB ;
ptRGB.x = pc_filtered->points[i].x;
ptRGB.y = pc_filtered->points[i].y;
ptRGB.z = pc_filtered->points[i].z;
ptRGB.r = 255;
ptRGB.g = 0;
ptRGB.b = 0;
bigCurv->push_back(ptRGB);
// cout<<"curvature : "<<pcNormals->points[i].curvature * 100<<endl;
}
///PCA
// pcl::PointCloud<pcl::PointXYZI>::Ptr keyCloud (new pcl::PointCloud<pcl::PointXYZI>);
// pcl::copyPointCloud(*bigCurv, *keyCloud);
//
// pcaAnalysist pcaAnalysistr;
// std::vector<pcaAnalysist::pcaFeature> pcaFeasOfkeyCloud;
// pcaAnalysistr.calculatePCAofPointCloud(keyCloud, 3, pcaFeasOfkeyCloud);
// pcl::PointCloud<pcl::PointXYZRGB>::Ptr pc_rgb (new pcl::PointCloud<pcl::PointXYZRGB>);
// pcl::copyPointCloud(*pc_filtered, *pc_rgb);
// preprocessor.visualize<pcl::PointXYZRGB>(pc_rgb, 2);
//
// *bigCurv = *bigCurv + *pc_rgb ;
preprocessor.visualize<pcl::PointXYZRGB>(bigCurv, 5, "keypoints");
///region growing based on curvature
pcl::PointCloud<pcl::PointXYZRGB>::Ptr clustersCloud (new pcl::PointCloud<pcl::PointXYZRGB>);
preprocessor.regionGrow_flat(pc_filtered, pcNormals, clustersCloud);
// preprocessor.visualize<pcl::PointXYZRGB>(clustersCloud, 2);
// preprocess1.visualize<PointXYZI>(pc_filtered, 3);
// preprocess1.visualize_withNormals(pc_filtered,2,pcNormals);
// cout<<pc_filtered->points.size()<<endl;
// pcl::PCDWriter pcdWriter;
// pcdWriter.write("pcAboveGround_electric.pcd",*pc_filtered_downSample);
// cout<<pc_filtered_downSample->points.size()<<endl;
return 0;
}