搞定了点云格式(pcd)的 保存与导出
parent
4635cc287d
commit
7e6f2b435d
|
@ -27,7 +27,7 @@
|
|||
#include <vtkUnstructuredGridWriter.h>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <vtkPointCloudFilter.h>
|
||||
|
||||
// debug
|
||||
#include "Common/DebugLogger.h"
|
||||
|
@ -114,13 +114,12 @@ namespace MeshData {
|
|||
}
|
||||
bool PointClouddataExchange::write()
|
||||
{
|
||||
|
||||
QFileInfo info(_fileName);
|
||||
if (!info.exists())
|
||||
return false;
|
||||
QString name = info.fileName();
|
||||
QString path = info.filePath();
|
||||
QString suffix = info.suffix().toLower();
|
||||
DebugInfo("PointClouddataExchange::writePCD FileName :%s \n",_fileName.toUtf8().constData());
|
||||
|
||||
if (suffix == "pcd")
|
||||
{
|
||||
return writePCD();
|
||||
|
@ -219,18 +218,19 @@ namespace MeshData {
|
|||
{
|
||||
QTextCodec *codec = QTextCodec::codecForName("GB18030");
|
||||
QByteArray ba = codec->fromUnicode(_fileName);
|
||||
vtkUnstructuredGrid *ungird = vtkUnstructuredGrid::New();
|
||||
vtkSmartPointer<vtkAppendFilter> filter = vtkSmartPointer<vtkAppendFilter>::New();
|
||||
// 使用 vtkGeometryFilter 提取几何信息并转换为 vtkPolyData
|
||||
vtkSmartPointer<vtkGeometryFilter> geometryFilter = vtkSmartPointer<vtkGeometryFilter>::New();
|
||||
DebugInfo("PointClouddataExchange::writePCD FileName :%s ",ba);
|
||||
|
||||
DebugInfo("PointClouddataExchange::writePCD Filter prepare :ok \n");
|
||||
// 使用 vtkGeometryFilter 提取几何信息并转换为 vtkPolyData
|
||||
vtkSmartPointer<vtkGeometryFilter> geometryFilter = vtkSmartPointer<vtkGeometryFilter>::New();
|
||||
|
||||
DebugInfo("PointClouddataExchange::writePCD Filter prepare :ok modelID :%d\n",_modelId);
|
||||
|
||||
if (_modelId > 0)
|
||||
{
|
||||
MeshKernal *kernal = _meshData->getKernalByID(_modelId);
|
||||
if (kernal != nullptr)
|
||||
{
|
||||
|
||||
vtkDataSet *dataset = kernal->getMeshData();
|
||||
if (dataset != nullptr)
|
||||
geometryFilter->AddInputData(dataset);
|
||||
|
@ -239,6 +239,7 @@ namespace MeshData {
|
|||
else
|
||||
{
|
||||
const int n = _meshData->getKernalCount();
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
if (!_threadRuning)
|
||||
|
@ -247,16 +248,19 @@ namespace MeshData {
|
|||
if (kernal != nullptr)
|
||||
{
|
||||
vtkDataSet *dataset = kernal->getMeshData();
|
||||
DebugInfo("PointClouddataExchange::writePCD writer over : iKernal %d , %d is nullptr ,points Count %d\n",i,(int)(dataset==nullptr),dataset->GetNumberOfPoints());
|
||||
if (dataset != nullptr)
|
||||
geometryFilter->AddInputData(dataset);
|
||||
}
|
||||
}
|
||||
}
|
||||
filter->Update();
|
||||
vtkSmartPointer<vtkPolyData> polyData = geometryFilter->GetOutput();
|
||||
geometryFilter->Update();
|
||||
vtkSmartPointer<vtkPolyData> outputDataSet = geometryFilter->GetOutput();
|
||||
DebugInfo("PointClouddataExchange::writePCD writer over :ok outputDataSet Point Count : %d\n",outputDataSet->GetNumberOfPoints());
|
||||
// 将输出的点云数据集转换为 PCL 格式
|
||||
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_with_rgba(new pcl::PointCloud<pcl::PointXYZRGBA>);
|
||||
pcl::io::vtkPolyDataToPointCloud(polyData,*cloud_with_rgba);
|
||||
DebugInfo("PointClouddataExchange::writePCD writer prepare :ok \n");
|
||||
pcl::io::vtkPolyDataToPointCloud(outputDataSet,*cloud_with_rgba);
|
||||
DebugInfo("PointClouddataExchange::writePCD writer over :ok cloud_with_rgba Point Count : %d\n",cloud_with_rgba->size());
|
||||
std::string outFileName=ba.data();
|
||||
pcl::io::savePCDFileBinary(outFileName,*cloud_with_rgba);
|
||||
DebugInfo("PointClouddataExchange::writePCD writer over :ok \n");
|
||||
|
@ -293,6 +297,7 @@ namespace MeshData {
|
|||
if (kernal != nullptr)
|
||||
{
|
||||
vtkDataSet *dataset = kernal->getMeshData();
|
||||
|
||||
if (dataset != nullptr)
|
||||
geometryFilter->AddInputData(dataset);
|
||||
}
|
||||
|
|
|
@ -133,8 +133,6 @@ namespace MeshData
|
|||
bool VTKdataExchange::write()
|
||||
{
|
||||
QFileInfo info(_fileName);
|
||||
if (!info.exists())
|
||||
return false;
|
||||
QString name = info.fileName();
|
||||
QString path = info.filePath();
|
||||
QString suffix = info.suffix().toLower();
|
||||
|
|
|
@ -338,10 +338,12 @@ bool MESHDATAEXCHANGEPLUGINAPI FOAMexportMesh(QString AbFileName, int id)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool MESHDATAEXCHANGEPLUGINAPI XYZimportPCL(QString AbFileName, int modelId)
|
||||
bool MESHDATAEXCHANGEPLUGINAPI XYZimportPCL(QString AbFileName, int id)
|
||||
{
|
||||
|
||||
|
||||
auto xyzReader = new MeshData::PointClouddataExchange(
|
||||
AbFileName, MeshData::MESH_READ, MeshData::MeshDataExchangePlugin::getMWpt(), id);
|
||||
ModuleBase::ThreadControl* tc = new ModuleBase::ThreadControl(xyzReader);
|
||||
emit tc->threadStart(); // emit MSHwriter->start();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -354,9 +356,12 @@ bool MESHDATAEXCHANGEPLUGINAPI PCDimportPCL(QString AbFileName, int id)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool MESHDATAEXCHANGEPLUGINAPI PLYimportPCL(QString AbFileName, int modelId)
|
||||
bool MESHDATAEXCHANGEPLUGINAPI PLYimportPCL(QString AbFileName, int id)
|
||||
{
|
||||
|
||||
auto plyReader = new MeshData::PointClouddataExchange(
|
||||
AbFileName, MeshData::MESH_READ, MeshData::MeshDataExchangePlugin::getMWpt(), id);
|
||||
ModuleBase::ThreadControl* tc = new ModuleBase::ThreadControl(plyReader);
|
||||
emit tc->threadStart(); // emit MSHwriter->start();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue