From ba5a05e8e8bf783619171122d7de7ec888c79aa0 Mon Sep 17 00:00:00 2001 From: jasjuang Date: Mon, 14 May 2018 15:58:07 -0700 Subject: [PATCH] remove depreciated function MapDataArrayToMultiTextureAttribute for VTK newer than 5 --- visualization/src/pcl_visualizer.cpp | 117 +++++++++++---------------- 1 file changed, 46 insertions(+), 71 deletions(-) diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 3d77a7d2e31..9ab7204e75a 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -3510,82 +3510,57 @@ 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 ((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 (mesh.tex_materials.size ()), texture_units); - int tu = vtkProperty::VTK_TEXTURE_UNIT_0; - std::size_t tex_id = 0; - while (tex_id < last_tex_id) - { - vtkSmartPointer texture = vtkSmartPointer::New (); - if (textureFromTexMaterial (mesh.tex_materials[tex_id], texture)) - { - PCL_WARN ("[PCLVisualizer::addTextureMesh] Failed to load texture %s, skipping!\n", - mesh.tex_materials[tex_id].tex_name.c_str ()); - continue; - } - // the first texture is in REPLACE mode others are in ADD mode - if (tex_id == 0) - texture->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_REPLACE); - else - texture->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD); - // add a texture coordinates array per texture - vtkSmartPointer coordinates = vtkSmartPointer::New (); - coordinates->SetNumberOfComponents (2); - std::stringstream ss; ss << "TCoords" << tex_id; - std::string this_coordinates_name = ss.str (); - coordinates->SetName (this_coordinates_name.c_str ()); - - for (std::size_t t = 0; t < mesh.tex_coordinates.size (); ++t) - if (t == tex_id) - for (std::size_t tc = 0; tc < mesh.tex_coordinates[t].size (); ++tc) - coordinates->InsertNextTuple2 (mesh.tex_coordinates[t][tc][0], - mesh.tex_coordinates[t][tc][1]); - else - for (std::size_t tc = 0; tc < mesh.tex_coordinates[t].size (); ++tc) - coordinates->InsertNextTuple2 (-1.0, -1.0); - - mapper->MapDataArrayToMultiTextureAttribute(tu, - this_coordinates_name.c_str (), - vtkDataObject::FIELD_ASSOCIATION_POINTS); - polydata->GetPointData ()->AddArray (coordinates); - actor->GetProperty ()->SetTexture (tu, texture); - ++tex_id; - ++tu; - } - } // 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"); + 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 (mesh.tex_materials.size ()), texture_units); + std::size_t tex_id = 0; + while (tex_id < last_tex_id) + { +#if VTK_MAJOR_VERSION > 5 + const char *tu = mesh.tex_materials[tex_id].tex_name.c_str (); +#else + int tu = vtkProperty::VTK_TEXTURE_UNIT_0 + tex_id; +#endif vtkSmartPointer texture = vtkSmartPointer::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 coordinates = vtkSmartPointer::New (); - coordinates->SetNumberOfComponents (2); - coordinates->SetNumberOfTuples (mesh.tex_coordinates[0].size ()); - for (std::size_t tc = 0; tc < mesh.tex_coordinates[0].size (); ++tc) + if (textureFromTexMaterial (mesh.tex_materials[tex_id], texture)) { - const Eigen::Vector2f &uv = mesh.tex_coordinates[0][tc]; - coordinates->SetTuple2 (tc, uv[0], uv[1]); + PCL_WARN ("[PCLVisualizer::addTextureMesh] Failed to load texture %s, skipping!\n", + mesh.tex_materials[tex_id].tex_name.c_str ()); + continue; } - coordinates->SetName ("TCoords"); - polydata->GetPointData ()->SetTCoords (coordinates); - // apply texture - actor->SetTexture (texture); - } // end of one texture + // the first texture is in REPLACE mode others are in ADD mode + if (tex_id == 0) + texture->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_REPLACE); + else + texture->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD); + // add a texture coordinates array per texture + vtkSmartPointer coordinates = vtkSmartPointer::New (); + coordinates->SetNumberOfComponents (2); + std::stringstream ss; ss << "TCoords" << tex_id; + std::string this_coordinates_name = ss.str (); + coordinates->SetName (this_coordinates_name.c_str ()); + + for (std::size_t t = 0; t < mesh.tex_coordinates.size (); ++t) + if (t == tex_id) + for (std::size_t tc = 0; tc < mesh.tex_coordinates[t].size (); ++tc) + coordinates->InsertNextTuple2 (mesh.tex_coordinates[t][tc][0], + mesh.tex_coordinates[t][tc][1]); + else + for (std::size_t tc = 0; tc < mesh.tex_coordinates[t].size (); ++tc) + coordinates->InsertNextTuple2 (-1.0, -1.0); + + mapper->MapDataArrayToMultiTextureAttribute(tu, + this_coordinates_name.c_str (), + vtkDataObject::FIELD_ASSOCIATION_POINTS); + polydata->GetPointData ()->AddArray (coordinates); + actor->GetProperty ()->SetTexture (tu, texture); + ++tex_id; + } // set mapper actor->SetMapper (mapper);