Skip to content

Commit

Permalink
remove depreciated function MapDataArrayToMultiTextureAttribute for V…
Browse files Browse the repository at this point in the history
…TK newer than 5
  • Loading branch information
jasjuang committed May 9, 2018
1 parent 9084aec commit 10bfd9e
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3510,16 +3510,20 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh,
vtkTextureUnitManager* tex_manager = vtkOpenGLRenderWindow::SafeDownCast (win_)->GetTextureUnitManager ();
if (!tex_manager)
return (false);
// Check if hardware support multi texture
// hardware always supports multitexturing of some degree
int texture_units = tex_manager->GetNumberOfTextureUnits ();
if ((mesh.tex_materials.size () > 1) && (texture_units > 1))
if ((mesh.tex_materials.size () > 1))
{
if ((size_t) texture_units < mesh.tex_materials.size ())
PCL_WARN ("[PCLVisualizer::addTextureMesh] GPU texture units %d < mesh textures %d!\n",
texture_units, mesh.tex_materials.size ());
// Load textures
std::size_t last_tex_id = std::min (static_cast<int> (mesh.tex_materials.size ()), texture_units);
#if VTK_MAJOR_VERSION > 5
std::string tu = mesh.tex_materials[0].tex_name.c_str ();
#else
int tu = vtkProperty::VTK_TEXTURE_UNIT_0;
#endif
std::size_t tex_id = 0;
while (tex_id < last_tex_id)
{
Expand Down Expand Up @@ -3557,35 +3561,13 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh,
polydata->GetPointData ()->AddArray (coordinates);
actor->GetProperty ()->SetTexture (tu, texture);
++tex_id;
#if VTK_MAJOR_VERSION > 5
tu = mesh.tex_materials[tex_id].tex_name.c_str ();
#else
++tu;
#endif
}
} // end of multi texturing
else
{
if ((mesh.tex_materials.size () > 1) && (texture_units < 2))
PCL_WARN ("[PCLVisualizer::addTextureMesh] Your GPU doesn't support multi texturing. "
"Will use first one only!\n");

vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New ();
// fill vtkTexture from pcl::TexMaterial structure
if (textureFromTexMaterial (mesh.tex_materials[0], texture))
PCL_WARN ("[PCLVisualizer::addTextureMesh] Failed to create vtkTexture from %s!\n",
mesh.tex_materials[0].tex_name.c_str ());

// set texture coordinates
vtkSmartPointer<vtkFloatArray> coordinates = vtkSmartPointer<vtkFloatArray>::New ();
coordinates->SetNumberOfComponents (2);
coordinates->SetNumberOfTuples (mesh.tex_coordinates[0].size ());
for (std::size_t tc = 0; tc < mesh.tex_coordinates[0].size (); ++tc)
{
const Eigen::Vector2f &uv = mesh.tex_coordinates[0][tc];
coordinates->SetTuple2 (tc, uv[0], uv[1]);
}
coordinates->SetName ("TCoords");
polydata->GetPointData ()->SetTCoords (coordinates);
// apply texture
actor->SetTexture (texture);
} // end of one texture

// set mapper
actor->SetMapper (mapper);
Expand Down

0 comments on commit 10bfd9e

Please sign in to comment.