mesh.cpp 2.05 KB
#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;
}