mesh.cpp
2.05 KB
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
#include "common.h"
#include "cv_func.h"
#include "pcl_func.h"
/*
[input]
argc = 3
argv[0] = program
argv[1] = original pointcloud
argv[2] = filtered pointcloud
[output]
original mesh -> vtk format
filtered mesh -> vtk format
*/
int main(int argc, char** argv)
{
if(argc != 3)
{
std::cout << "[Error] Program Usage: [./mesh] [original_cloud.pcd] [filtered_cloud.pcd]" << std::endl;
return -1;
}
//save path
std::string inputPath = argv[1];
std::size_t div = inputPath.find_last_of("/\\");
std::string outputPath = inputPath.substr(0, div + 1);
//load pointcloud data
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_original(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile(argv[1], *cloud_original);
pcl::io::loadPCDFile(argv[2], *cloud_filtered);
std::cout << "[Processing] reading pointcloud done..." << std::endl;
//origianl cloud needs upsampling
//(triangulation process impossible for noisy normal estimation)
//upsampling(cloud_original);
//std::cout << "original cloud upsampling done..." << std::endl;
//normal estimation
pcl::PointCloud<pcl::PointNormal>::Ptr original_with_normals(new pcl::PointCloud<pcl::PointNormal>);
normal_estimation(cloud_original, original_with_normals);
pcl::PointCloud<pcl::PointNormal>::Ptr filtered_with_normals(new pcl::PointCloud<pcl::PointNormal>);
normal_estimation(cloud_filtered, filtered_with_normals);
std::cout << "[Processing] normal estimation done..." << std::endl;
//triangulation
pcl::PolygonMesh triangles_original, triangles_filtered;
triangulation(original_with_normals, triangles_original);
triangulation(filtered_with_normals, triangles_filtered);
std::cout << "[Processing] triangulation done..." << std::endl;
//save output
pcl::io::saveVTKFile(outputPath + "original_mesh.vtk", triangles_original);
pcl::io::saveVTKFile(outputPath + "filtered_mesh.vtk", triangles_filtered);
return 0;
}