Qt工程中c++实现wrl到pcd格式转换
2017-01-05 09:34
288 查看
pcl1.8.0+QT5.7.0+vs2013 win7 x64环境配置
//读取文本型和二进制型点云数据
void onOpen()
{
//打开文件
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open PointCloud"), ".",
tr("Open PCD files(*.pcd);;Open WRL files(*.wrl)"));
//filename类型转换
std::string file_name = fileName.toStdString();
//获取文件名称以及扩展名
vector<string> tokens;
boost::char_separator<char> sep(".");
boost::tokenizer<boost::char_separator<char> > tok(file_name, sep);
tokens.clear();
std::copy(tok.begin(), tok.end(), std::back_inserter(tokens));
if (!fileName.isEmpty())
{
//若是其他类型
if (tokens[1] != "pcd")
{
//查找特定位置(所需点坐标)l为所在行数;l-35为点云个数
string fout_name = tokens[0] + ".pcd";
int linenum = 0;
int l;
ifstream in(file_name);
string line;
string s;
int i = 0;
string key = "texCoord DEF texcoord0 TextureCoordinate";
while (getline(in, line))
{
if (line.find(key) != string::npos)
{
// cout << linenum << " ";
l = linenum;
}
linenum++;
}
//写入
ofstream outfile(fout_name, ios::out | ios::trunc);
outfile << "# .PCD v.5 - Point Cloud Data file format" << endl;
outfile << "VERSION .5" << endl;
outfile << "FIELDS x y z" << endl;
outfile << "SIZE 4 4 4" << endl;
outfile << "TYPE F F F" << endl;
outfile << "COUNT 1 1 1" << endl;
outfile << "WIDTH " << l - 35 << endl;
outfile << "HEIGHT 1" << endl;
outfile << "POINTS " << l - 35 << endl;
outfile << "DATA ascii" << endl;
//添加点
ifstream inFile;
inFile.open(file_name);
while (getline(inFile, s, '\n'))
{
if (i > 32 && i < l - 2)
outfile << s << endl;
i++;
}
inFile.close();
outfile.close();
//显示
pcl::PCLPointCloud2 cloud2;
//pcl::PointCloud<Eigen::MatrixXf> cloud2;
Eigen::Vector4f origin;
Eigen::Quaternionf orientation;
int pcd_version;
int data_type;
unsigned int data_idx;
int offset = 0;
pcl::PCDReader rd;
rd.readHeader(fout_name, cloud2, origin, orientation, pcd_version, data_type, data_idx);
if (data_type == 0)
{
pcl::io::loadPCDFile(fout_name, *cloud);
}
else if (data_type == 2)
{
pcl::PCDReader reader;
reader.read<pcl::PointXYZ>(fout_name, *cloud);
}
viewer->updatePointCloud(cloud, "cloud");
viewer->resetCamera();
ui.qvtkWidget->update();
}
else
{
//sensor_msgs::PointCloud2 cloud2;
pcl::PCLPointCloud2 cloud2;
//pcl::PointCloud<Eigen::MatrixXf> cloud2;
Eigen::Vector4f origin;
Eigen::Quaternionf orientation;
int pcd_version;
int data_type;
unsigned int data_idx;
int offset = 0;
pcl::PCDReader rd;
rd.readHeader(file_name, cloud2, origin, orientation, pcd_version, data_type, data_idx);
if (data_type == 0)
{
pcl::io::loadPCDFile(fileName.toStdString(), *cloud);
}
else if (data_type == 2)
{
pcl::PCDReader reader;
reader.read<pcl::PointXYZ>(fileName.toStdString(), *cloud);
}
viewer->updatePointCloud(cloud, "cloud");
viewer->resetCamera();
ui.qvtkWidget->update();
}
}
}
运行结果
//读取文本型和二进制型点云数据
void onOpen()
{
//打开文件
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open PointCloud"), ".",
tr("Open PCD files(*.pcd);;Open WRL files(*.wrl)"));
//filename类型转换
std::string file_name = fileName.toStdString();
//获取文件名称以及扩展名
vector<string> tokens;
boost::char_separator<char> sep(".");
boost::tokenizer<boost::char_separator<char> > tok(file_name, sep);
tokens.clear();
std::copy(tok.begin(), tok.end(), std::back_inserter(tokens));
if (!fileName.isEmpty())
{
//若是其他类型
if (tokens[1] != "pcd")
{
//查找特定位置(所需点坐标)l为所在行数;l-35为点云个数
string fout_name = tokens[0] + ".pcd";
int linenum = 0;
int l;
ifstream in(file_name);
string line;
string s;
int i = 0;
string key = "texCoord DEF texcoord0 TextureCoordinate";
while (getline(in, line))
{
if (line.find(key) != string::npos)
{
// cout << linenum << " ";
l = linenum;
}
linenum++;
}
//写入
ofstream outfile(fout_name, ios::out | ios::trunc);
outfile << "# .PCD v.5 - Point Cloud Data file format" << endl;
outfile << "VERSION .5" << endl;
outfile << "FIELDS x y z" << endl;
outfile << "SIZE 4 4 4" << endl;
outfile << "TYPE F F F" << endl;
outfile << "COUNT 1 1 1" << endl;
outfile << "WIDTH " << l - 35 << endl;
outfile << "HEIGHT 1" << endl;
outfile << "POINTS " << l - 35 << endl;
outfile << "DATA ascii" << endl;
//添加点
ifstream inFile;
inFile.open(file_name);
while (getline(inFile, s, '\n'))
{
if (i > 32 && i < l - 2)
outfile << s << endl;
i++;
}
inFile.close();
outfile.close();
//显示
pcl::PCLPointCloud2 cloud2;
//pcl::PointCloud<Eigen::MatrixXf> cloud2;
Eigen::Vector4f origin;
Eigen::Quaternionf orientation;
int pcd_version;
int data_type;
unsigned int data_idx;
int offset = 0;
pcl::PCDReader rd;
rd.readHeader(fout_name, cloud2, origin, orientation, pcd_version, data_type, data_idx);
if (data_type == 0)
{
pcl::io::loadPCDFile(fout_name, *cloud);
}
else if (data_type == 2)
{
pcl::PCDReader reader;
reader.read<pcl::PointXYZ>(fout_name, *cloud);
}
viewer->updatePointCloud(cloud, "cloud");
viewer->resetCamera();
ui.qvtkWidget->update();
}
else
{
//sensor_msgs::PointCloud2 cloud2;
pcl::PCLPointCloud2 cloud2;
//pcl::PointCloud<Eigen::MatrixXf> cloud2;
Eigen::Vector4f origin;
Eigen::Quaternionf orientation;
int pcd_version;
int data_type;
unsigned int data_idx;
int offset = 0;
pcl::PCDReader rd;
rd.readHeader(file_name, cloud2, origin, orientation, pcd_version, data_type, data_idx);
if (data_type == 0)
{
pcl::io::loadPCDFile(fileName.toStdString(), *cloud);
}
else if (data_type == 2)
{
pcl::PCDReader reader;
reader.read<pcl::PointXYZ>(fileName.toStdString(), *cloud);
}
viewer->updatePointCloud(cloud, "cloud");
viewer->resetCamera();
ui.qvtkWidget->update();
}
}
}
运行结果
相关文章推荐
- C++ GUI Programming with Qt 4 - 10.3 实现自定义模型
- C++ GUI Programming with Qt 4 - 10.3 实现自定义模型
- paip.c++ qt 项目工程互相引用的方法
- Qt and C++ Reflection,利用Qt简化C++的反射实现
- 在Qtcreator下cmake工程文件及使用Qt制作PCL C++ GUI
- C++ GUI Programming with Qt 4 - 10.3 实现自定义模型
- qt 创建纯c++ 工程, 不依赖qt库
- Qt webKit--实现本地QObject(c++)和JavaScript交互
- QT+C++实现连连看
- Qt工程实现打开目录并选中指定文件的方法
- C++ GUI QT 编程(第二版) -第4章 实现功能源码简介_1
- VS2008、QT及VTK实现DICOM图像三维重建之三:Win32工程配置
- 乱谈Qt程序之i18n的实现(从C++到Qt)
- C++实现截屏 使用Qt
- Qt(C++)之实现风行播放器界面
- C++ GUI Programming with Qt 4 - 10.4 实现自定义代理(delegate)
- C++ GUI Qt 编程(第二版)第8章 Diagram_2(实现主对话框)
- Qt webKit--实现本地QObject(c++)和JavaScript交互
- paip.提升用户体验---c++ qt 悬浮窗实现
- 设计模式之抽象工程模式Abstract Factory Pattern()C++实现