Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fixes for texture mesh export for pcl > 1.13.0 #1039

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions guilib/include/rtabmap/gui/ExportCloudsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};

}
Expand Down
37 changes: 30 additions & 7 deletions guilib/src/ExportCloudsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2844,7 +2844,7 @@ bool ExportCloudsDialog::getExportedClouds(
}
if(!image.empty())
{

if(_ui->spinBox_camProjDecimation->value()>1)
{
image = util2d::decimate(image, _ui->spinBox_camProjDecimation->value());
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -4455,7 +4455,7 @@ void ExportCloudsDialog::saveMeshes(
}
else if(suffix == "obj")
{
success = pcl::io::saveOBJFile(pathFile.toStdString(), mesh) == 0;
success = saveOBJFile(pathFile, mesh);
}
else
{
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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<std::vector<pcl::Vertices>>();
auto nr_meshes = static_cast<unsigned>(mesh->tex_polygons.size());
unsigned f_idx = 0;
for (unsigned m = 0; m < nr_meshes; m++) {
std::vector<pcl::Vertices> 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<unsigned>(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;
}


}