From 67df99aa57199c1beaae0eb95eb8cf83c3a1a91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lison?= Date: Tue, 30 May 2023 04:00:18 +0200 Subject: [PATCH] fixes for texture mesh export pcl > 1.13.0 (#1039) Co-authored-by: FIRST_NAME LAST_NAME --- .../include/rtabmap/gui/ExportCloudsDialog.h | 4 ++ guilib/src/ExportCloudsDialog.cpp | 37 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/guilib/include/rtabmap/gui/ExportCloudsDialog.h b/guilib/include/rtabmap/gui/ExportCloudsDialog.h index fcfd66f76e..71bb674c94 100644 --- a/guilib/include/rtabmap/gui/ExportCloudsDialog.h +++ b/guilib/include/rtabmap/gui/ExportCloudsDialog.h @@ -153,6 +153,10 @@ private Q_SLOTS: GainCompensator * _compensator; const DBDriver * _dbDriver; bool _scansHaveRGB; + + bool saveOBJFile(const QString &path, pcl::TextureMesh::Ptr &mesh) const; + bool saveOBJFile(const QString &path, pcl::PolygonMesh &mesh) const; + }; } diff --git a/guilib/src/ExportCloudsDialog.cpp b/guilib/src/ExportCloudsDialog.cpp index 378ddbae15..d85bdcf445 100644 --- a/guilib/src/ExportCloudsDialog.cpp +++ b/guilib/src/ExportCloudsDialog.cpp @@ -2844,7 +2844,7 @@ bool ExportCloudsDialog::getExportedClouds( } if(!image.empty()) { - + if(_ui->spinBox_camProjDecimation->value()>1) { image = util2d::decimate(image, _ui->spinBox_camProjDecimation->value()); @@ -4369,11 +4369,11 @@ void ExportCloudsDialog::saveMeshes( } else if(QFileInfo(path).suffix() == "obj") { - success = pcl::io::saveOBJFile(path.toStdString(), *meshes.begin()->second) == 0; + success = saveOBJFile(path, *meshes.begin()->second); } else { - UERROR("Extension not recognized! (%s) Should be (*.ply).", QFileInfo(path).suffix().toStdString().c_str()); + UERROR("Extension not recognized! (%s) Should be (*.ply) or (*.obj).", QFileInfo(path).suffix().toStdString().c_str()); } if(success) { @@ -4455,7 +4455,7 @@ void ExportCloudsDialog::saveMeshes( } else if(suffix == "obj") { - success = pcl::io::saveOBJFile(pathFile.toStdString(), mesh) == 0; + success = saveOBJFile(pathFile, mesh); } else { @@ -4779,8 +4779,7 @@ void ExportCloudsDialog::saveTextureMeshes( } } - success = pcl::io::saveOBJFile(path.toStdString(), *mesh) == 0; - if(success) + if(saveOBJFile(path, mesh)) { _progressDialog->incrementStep(); _progressDialog->appendText(tr("Saving the mesh (with %1 textures)... done.").arg(mesh->tex_materials.size())); @@ -4976,7 +4975,7 @@ void ExportCloudsDialog::saveTextureMeshes( bool success =false; if(suffix == "obj") { - success = pcl::io::saveOBJFile(pathFile.toStdString(), *mesh) == 0; + success = saveOBJFile(pathFile, mesh); } else { @@ -5010,4 +5009,28 @@ void ExportCloudsDialog::saveTextureMeshes( } } + bool ExportCloudsDialog::saveOBJFile(const QString &path, pcl::TextureMesh::Ptr &mesh) const { +#if PCL_VERSION_COMPARE(>=, 1, 13, 0) + mesh->tex_coord_indices = std::vector>(); + auto nr_meshes = static_cast(mesh->tex_polygons.size()); + unsigned f_idx = 0; + for (unsigned m = 0; m < nr_meshes; m++) { + std::vector ci = mesh->tex_polygons[m]; + for(std::size_t i = 0; i < ci.size(); i++) { + for (std::size_t j = 0; j < ci[i].vertices.size(); j++) { + ci[i].vertices[j] = ci[i].vertices.size() * (i + f_idx) + j; + } + } + mesh->tex_coord_indices.push_back(ci); + f_idx += static_cast(mesh->tex_polygons[m].size()); + } +#endif + return pcl::io::saveOBJFile(path.toStdString(), *mesh) == 0; + } + + bool ExportCloudsDialog::saveOBJFile(const QString &path, pcl::PolygonMesh &mesh) const { + return pcl::io::saveOBJFile(path.toStdString(), mesh) == 0; + } + + }