#include <pcl/io/pcd_io.h>
#include <boost/filesystem.hpp>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
std::string str = "D:/repo/CompoundGrinding/x64/Release/GlobalRubber_defect.pcd";
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile(str, *cloud);
//D:\repo\CompoundGrinding\Windows\CompoundGrinding\CompoundGrinding .vcxproj同级目录
/*创建文件夹*/
//boost::filesystem::exists、create_directory无法识别相对路径
const std::string save_directory = "../../../x64/Release/Data";
boost::filesystem::path directoryPath = boost::filesystem::system_complete(save_directory);
if (!boost::filesystem::exists(directoryPath)) //推断文件存在性
{
//文件夹不存在;
boost::filesystem::create_directory(directoryPath); //文件夹不存在。创建
}
std::string dirSaveRubber = save_directory + "/" + "GlobalRubber_defect.pcd";
pcl::io::savePCDFileBinaryCompressed(dirSaveRubber, *cloud);
/*path转换为string*/
boost::filesystem::exists、create_directory无法识别相对路径
//const std::string directory = "../../../x64/Release/Data";
//boost::filesystem::path directoryPath = boost::filesystem::system_complete(directory);
也可以不用将path转换为string,pcl::io::savePCDFile可以识别相对路径
//string save_directory=boost::filesystem::absolute(directoryPath).string();
//cout << "path:" << save_directory << endl;
//if (!boost::filesystem::exists(save_directory)) //推断文件存在性
//{
// //文件夹不存在;
// boost::filesystem::create_directory(save_directory); //文件夹不存在。创建
//}
//std::string dirSaveRubber = save_directory + "/" + "GlobalRubber_defect.pcd";
//pcl::io::savePCDFileBinaryCompressed(dirSaveRubber, *cloud);
}
|