#include <pcl/point_cloud.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/octree/octree.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <iostream>
#include <vector>
#include <ctime>
#include <pcl/io/ply_io.h>
#include <pcl/console/print.h>
#include <pcl/console/parse.h>
#include <pcl/console/time.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/io/vtk_io.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
//#include <io.h>
#include <dirent.h>
#include <filesystem>
#include <vector>
#include <sys/stat.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/filters/filter.h>
#include <pcl/common/impl/io.hpp>
#include <pcl/filters/passthrough.h>
#include <thread>
//#include <pcl\filters\radius_outlier_removal.h>
#include <pcl/filters/voxel_grid.h>
using namespace pcl;
using namespace pcl::io;
using namespace pcl::console;
using namespace std;
void getFiles(const std::string& path, std::vector<std::string>& files) {
DIR *dir;
struct dirent *ent;
struct stat st;
dir = opendir(path.c_str());
if (dir != NULL) {
while ((ent = readdir(dir)) != NULL) {
const std::string file_name = ent->d_name;
const std::string full_file_path = path + "/" + file_name;
if (file_name[0] == '.') {
continue; // Skip hidden files
}
if (stat(full_file_path.c_str(), &st) == -1) {
continue; // If unable to get file info, skip
}
if (S_ISDIR(st.st_mode)) {
if (file_name != "." && file_name != "..") {
getFiles(full_file_path, files); // Recursively get files in subdirectories
}
} else {
files.push_back(full_file_path); // Add file to the list
}
}
closedir(dir);
}
}
bool compareFiles(const std::string& file1, const std::string& file2) {
// 提取文件名中的数字部分,并转换为整数进行比较
int num1 = std::stoi(file1.substr((file1.find_last_of('/')+1), file1.find('.')));
int num2 = std::stoi(file2.substr((file2.find_last_of('/')+1), file2.find('.')));
return num1 < num2;
}
int main()
{
vector<string> files;
char * filePath = "/home/noetic/下载/Scans8";
//获取该路径下的所有文件
getFiles(filePath, files);
char str[30];
std::sort(files.begin(), files.end(), compareFiles);
pcl::visualization::PCLVisualizer viewer("PCL Viewer");
viewer.setBackgroundColor(1.0, 1.0, 1.0);
//for (int i = 0; i < size; i++)
for (const auto& file : files)
{
cout << file.c_str() << endl;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile(file, *cloud);
std::string cloud_id = "cloud_" + file;
pcl::visualization::PCLVisualizer viewer("PCL Viewer");
viewer.setBackgroundColor(1.0, 1.0, 1.0);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_source(cloud, 255, 0, 0);
viewer.addPointCloud(cloud,cloud_source,cloud_id);
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, cloud_id);
while (!viewer.wasStopped())
{
viewer.spinOnce(100);
}
viewer.removePointCloud(cloud_id);
}
return(0);
}