2 Star 1 Fork 1

liuzhongtu/HelloQocct

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pclDemo.cpp 6.51 KB
一键复制 编辑 原始数据 按行查看 历史
Monss 提交于 2024-03-11 19:57 . 以MVC模式构建点云运行框架;
#include "pclDemo.h"
#include "Viewer.h"
#include "util.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <chrono>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <Graphic3d_ArrayOfPoints.hxx>
#include <AIS_PointCloud.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <QFile>
#include <QTextStream>
//int pcl_demo::visualizeXYZ(Viewer* viewer, const ReadFileData& data)
//{
// // 变量声明
// Handle(Graphic3d_ArrayOfPoints) occPoints = nullptr; // occt点云对象
// pcl::PointCloud<pcl::PointXYZ>::Ptr inputData(new pcl::PointCloud<pcl::PointXYZ>); // PCL点云数组
// pcl::PointCloud<pcl::PointXYZ>::Ptr resultData(new pcl::PointCloud<pcl::PointXYZ>); // PCL结果点云数组
//
// // 获取文件类型
// QString filetype = data.filepath.mid(data.filepath.lastIndexOf(".")).toLower();
// file_filter::Filter typeIdx = static_cast<file_filter::Filter>(file_filter::filters.indexOf(filetype));
//
// // 根据文件类型不同进行不同的处理方式
// switch (typeIdx)
// {
// case file_filter::PCD:
// // Fill in the Cloud data
// if (pcl::io::loadPCDFile<pcl::PointXYZ>(data.filepath.toStdString(), *inputData) == -1)
// return -1;
// break;
// case file_filter::STL:
// break;
// case file_filter::PLY:
// break;
// default:
// // 测试操作时间
// auto start = std::chrono::system_clock::now();
//
// // 不限类型,作文本文件处理
// // 打开文件
// std::ifstream inFile(data.filepath.toStdString());
// if (!inFile.is_open()) {
// std::cerr << "Failed to open file." << std::endl;
// return -1;
// }
//
// // 逐行读取文件,添加到PCL点云数组内
// std::string line;
// double data[3];
// unsigned int idx = 0;
// char delimiter; // 用于存储分隔符的变量
// while (std::getline(inFile, line)) {
// std::istringstream iss(line);
// idx = 0;
//
// while (iss >> data[idx++]) {
// // 尝试读取分隔符,但不存储其值
// if (!(iss >> std::noskipws >> delimiter)) {
// break; // 如果没有更多的数据或分隔符,跳出循环
// }
// // 如果需要,可以在这里对分隔符进行处理或跳过
//
// if (idx > 2)
// break;
// }
// inputData->points.push_back(pcl::PointXYZ(data[0], data[1], data[2]));
// }
//
// // 关闭文件
// inFile.close();
//
// // 显示测试操作时间结果
// auto end = std::chrono::system_clock::now();
// auto time_elapse = std::chrono::duration<double>(end - start);
// std::cout << "time cost: " << time_elapse.count() << std::endl;
// break;
// }
//
// //// 降采样
// //if (inputData->size() > 500000)
// //{
// // // 使用体素化网格(VoxelGrid)进行下采样
// // pcl::VoxelGrid<pcl::PointXYZ> grid; //创建滤波对象
// // const float leaf = 0.5f;
// // grid.setLeafSize(leaf, leaf, leaf); // 设置体素体积
// // grid.setInputCloud(inputData); // 设置点云
// // grid.filter(*resultData); // 执行滤波,输出结果
// //}
// //else
// // resultData = inputData;
//
// // 添加数据到occt对象
// occPoints = new Graphic3d_ArrayOfPoints(inputData->size(), Standard_True);
//
// for (const pcl::PointXYZ& point : *inputData)
// occPoints->AddVertex(gp_Pnt(point.x, point.y, point.z), Quantity_Color(Quantity_NOC_FLORALWHITE));
//
// // 使用occt绘制到屏幕
// if (occPoints->ItemNumber() > 0)
// {
// // 生成并设置occt点云对象
// Handle(AIS_PointCloud) occPntCloud = new AIS_PointCloud();
// occPntCloud->SetPoints(occPoints);
//
// // 显示occt点云
// Handle(AIS_InteractiveContext) context = viewer->context();
// context->Display(occPntCloud, Standard_True);
// return 0;
// }
//
// return -2;
//}
//int pcl_demo::visualizeXYZNormalCurvature(Viewer* viewer, const ReadFileData& data)
//{
// // 变量声明
// Handle(Graphic3d_ArrayOfPoints) occPoints = nullptr; // occt点云对象
// pcl::PointCloud<pcl::PointNormal>::Ptr inputData(new pcl::PointCloud<pcl::PointNormal>); // PCL点云数组
// pcl::PointCloud<pcl::PointNormal>::Ptr resultData(new pcl::PointCloud<pcl::PointNormal>); // PCL结果点云数组
//
// // 获取文件类型
// QString filetype = data.filepath.mid(data.filepath.lastIndexOf(".")).toLower();
// file_filter::Filter typeIdx = static_cast<file_filter::Filter>(file_filter::filters.indexOf(filetype));
//
// // 根据文件类型不同进行不同的处理方式
// switch (typeIdx)
// {
// case file_filter::PCD:
// // Fill in the Cloud data
// if (pcl::io::loadPCDFile<pcl::PointNormal>(data.filepath.toStdString(), *inputData) == -1)
// return -1;
// break;
// case file_filter::STL:
// break;
// case file_filter::PLY:
// break;
// default:
// // 不限类型,作文本文件处理
// // 打开文件
// QFile file(data.filepath);
// // 文件打开失败则提示
// if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
// return -1;
//
// // 跳过文件开头的注释行
// QTextStream in(&file);
// QString line;
// while (true)
// {
// line = in.readLine();
// // 若文件开始几行以#开头,则视为注释行,跳过
// if (!(line.size() > 0 && line.at(0) == '#'))
// break;
// }
//
// do {
// // 逐行读取文件,添加到PCL点云数组内
// QVector<QString> lineData;
// util::divideLine(line, 3, data.divideSign, &lineData); // 解析一行数据
//
// pcl::PointNormal newPoint; // 添加新点
// newPoint.x = lineData[0].toFloat();
// newPoint.y = lineData[1].toFloat();
// newPoint.z = lineData[2].toFloat();
// newPoint.normal_x = lineData[3].toFloat();
// newPoint.normal_y = lineData[4].toFloat();
// newPoint.normal_z = lineData[5].toFloat();
// newPoint.curvature = lineData[6].toFloat();
//
// inputData->points.push_back(newPoint);
// } while (in.readLineInto(&line));
//
// // 关闭文件
// file.close();
// break;
// }
//
// //// 降采样
// //if (inputData->size() > 1500000)
// //{
// // // 使用体素化网格(VoxelGrid)进行下采样
// // pcl::VoxelGrid<pcl::PointNormal> grid; //创建滤波对象
// // const float leaf = 0.005f;
// // grid.setLeafSize(leaf, leaf, leaf); // 设置体素体积
// // grid.setInputCloud(inputData); // 设置点云
// // grid.filter(*resultData); // 执行滤波,输出结果
// //}
// //else
// // resultData = inputData;
//
// // 添加数据到occt对象
// occPoints = new Graphic3d_ArrayOfPoints(inputData->size(), Standard_True);
//
// for (const pcl::PointNormal& point : *inputData)
// occPoints->AddVertex(gp_Pnt(point.x, point.y, point.z), gp_Dir(point.normal_x, point.normal_y, point.normal_z), Quantity_Color(Quantity_NOC_FLORALWHITE));
//
// // 使用occt绘制到屏幕
// if (occPoints->ItemNumber() > 0)
// {
// // 生成并设置occt点云对象
// Handle(AIS_PointCloud) occPntCloud = new AIS_PointCloud();
// occPntCloud->SetPoints(occPoints);
//
// // 显示occt点云
// Handle(AIS_InteractiveContext) context = viewer->context();
// context->Display(occPntCloud, Standard_True);
// return 0;
// }
//
// return -2;
//}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/liuzhongtu/hello-qocct.git
git@gitee.com:liuzhongtu/hello-qocct.git
liuzhongtu
hello-qocct
HelloQocct
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385