GUI: Fixed crash when adding Texture Dense Mesh to CloudViewer

This commit is contained in:
matlabbe
2016-10-21 19:34:29 -04:00
parent 856b83ac53
commit 7b2bf9ac13
2 changed files with 30 additions and 2 deletions

View File

@@ -659,8 +659,11 @@ bool CloudViewer::addCloudTextureMesh(
{
_visualizer->getCloudActorMap()->find(id)->second.actor->GetProperty()->FrontfaceCullingOn();
}
_visualizer->getCloudActorMap()->find(id)->second.actor->GetTexture()->SetInterpolate(1);
_visualizer->getCloudActorMap()->find(id)->second.actor->GetTexture()->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_REPLACE);
if(!textureMesh->cloud.is_dense)
{
_visualizer->getCloudActorMap()->find(id)->second.actor->GetTexture()->SetInterpolate(1);
_visualizer->getCloudActorMap()->find(id)->second.actor->GetTexture()->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_REPLACE);
}
_visualizer->updatePointCloudPose(id, pose.toEigen3f());
_addedClouds.insert(id, pose);
return true;

View File

@@ -1288,6 +1288,31 @@ bool ExportCloudsDialog::getExportedClouds(
cameraModels,
images,
dir.filePath("tmp_textures").toStdString());
if(!_ui->checkBox_binary->isVisible() && // not visible -> we are not exporting to file
textureMesh->tex_coordinates.size() &&
textureMesh->tex_coordinates[0].size()) // assume first is the texture, second is occluded texture
{
// When not saving to file, tex_coordinates should be linked to points, not polygon vertices
int nPoints = textureMesh->cloud.data.size()/textureMesh->cloud.point_step;
std::vector<Eigen::Vector2f> tmpCoordinates = textureMesh->tex_coordinates[0];
textureMesh->tex_coordinates[0].resize(nPoints);
int polygonSize = textureMesh->tex_polygons[0][0].vertices.size();
UASSERT(textureMesh->tex_polygons[0].size() == tmpCoordinates.size()/polygonSize);
for(unsigned int i=0; i<textureMesh->tex_polygons[0].size(); ++i)
{
const pcl::Vertices & vertices = textureMesh->tex_polygons[0][i];
UASSERT(polygonSize == (int)vertices.vertices.size());
for(int j=0; j<polygonSize; ++j)
{
//uv
UASSERT((int)vertices.vertices[j] < nPoints);
UASSERT(i*polygonSize+j < tmpCoordinates.size());
textureMesh->tex_coordinates[0][vertices.vertices[j]] = tmpCoordinates[i*polygonSize+j];
}
}
}
}
textureMeshes.insert(std::make_pair(iter->first, textureMesh));