Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove depreciated VTK function MapDataArrayToMultiTextureAttribute #2291

Merged
merged 1 commit into from May 16, 2018

Conversation

jasjuang
Copy link
Contributor

VTK removed MapDataArrayToMultiTextureAttribute in commit https://gitlab.kitware.com/vtk/vtk/commit/2f231fbd33fd936c23d5b4a375e6a2c542b771d3. This PR uses the newer functions to achieve the same functionality.

@taketwo
Copy link
Member

taketwo commented Apr 28, 2018

Unfortunately this is incompatible with VTK 5. I know it's super old, but it's still used on Travis.

What about this:

#if new VTK
  const char* tu = mesh.tex_materials[tex_id].tex_name.c_str ();
#else
  int tu = VTK_TEXTURE_UNIT_0 + tex_id;
#endif

mapper->MapDataArrayToMultiTextureAttribute(tu,
                                            this_coordinates_name.c_str (),
                                            this_coordinates_name.c_str (),
                                            vtkDataObject::FIELD_ASSOCIATION_POINTS);
                                            vtkDataObject::FIELD_ASSOCIATION_POINTS);
polydata->GetPointData ()->AddArray (coordinates);
polydata->GetPointData ()->AddArray (coordinates);
actor->GetProperty ()->SetTexture (tu, texture);
++tex_id; 

@jasjuang
Copy link
Contributor Author

Yeah we can try to add macros to support VTK 5. However, new VTK doesn't seem to be working. Do you know whether VTK provide something out of the box or do we have to define something in the CMakeLists ourselves?

@taketwo
Copy link
Member

taketwo commented Apr 29, 2018

Sorry, I did not make it clear, but #if new VTK was pseudo-code (I was lazy to look up what exactly is the name of their version macro). Now I checked, it should be #if VTK_MAJOR_VERSION > 5.

@jasjuang
Copy link
Contributor Author

I added VTK_MAJOR_VERSION to support VTK 5, it's a bit ugly but should do the job.

@taketwo
Copy link
Member

taketwo commented Apr 29, 2018

Please have another look at what I proposed, it is considerably less ugly. The idea is to have a local variable tu, which will have different type (int or string) depending on VTK version. The remaining code stays the same.

@jasjuang
Copy link
Contributor Author

jasjuang commented May 2, 2018

@taketwo I actually asked on VTK about how to solve this, and here is his reponse. Kitware/VTK@2f231fb I just force pushed a commit with the code he pasted. Could you take a look and see whether this make sense to you? If you think it is good I will try to add the VTK 5 support onto it.

@taketwo
Copy link
Member

taketwo commented May 2, 2018

I'm fine with the suggestion to drop the "no multi-texturing support" branch. Besides from that, the only thing that is different to your previous attempt is that you now use pcltexture + tex_id instead of mesh.tex_materials[tex_id].tex_name as the texture name. In my opinion, the latter is more meaningful, so I don't see a good reason for this change.

@jasjuang
Copy link
Contributor Author

jasjuang commented May 9, 2018

@taketwo Please take a look and see if this is the preferred change. Thanks.

{
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 ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be const char*? Because this the type that c_str() returns and also the type that VTK expects? Apart from that looks good.

@jasjuang
Copy link
Contributor Author

jasjuang commented May 9, 2018

@taketwo I just fixed the mistake. Please take a look, thanks!

@taketwo
Copy link
Member

taketwo commented May 9, 2018

Why do you create the tu variable outside of the while loop? Please refer to my very first comment, it can be created inside the loop and thus there will be no need for the second ugly #if #else #end block, which makes code more readable.

Also, I've just realized that the if ((mesh.tex_materials.size () > 1)) condition should be removed. Otherwise, we are breaking visualization of meshes with a single material!

@jasjuang
Copy link
Contributor Author

@taketwo You are right. I just forced push a commit with your suggestion. Please take a look.

Copy link
Member

@taketwo taketwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@taketwo taketwo merged commit fb44a10 into PointCloudLibrary:master May 16, 2018
@frozar
Copy link
Contributor

frozar commented May 16, 2018

Hi there, maybe I'm the only one but on my laptop, after this PR the PCL project doesn't compile anymore.

I got this error:

/home/frozar/wk/pcl_repo/visualization/src/pcl_visualizer.cpp: In member function ‘bool pcl::visualization::PCLVisualizer::addTextureMesh(const pcl::TextureMesh&, const string&, int)’:
/home/frozar/wk/pcl_repo/visualization/src/pcl_visualizer.cpp:3559:88: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
                                                 vtkDataObject::FIELD_ASSOCIATION_POINTS);

I check the prototype of the function in the header /usr/include/vtk-6.2/vtkPolyDataMapper.h:

  virtual void MapDataArrayToMultiTextureAttribute(
    int unit,
    const char* dataArrayName, int fieldAssociation, int componentno = -1);

And in the file .../visualization/src/pcl_visualizer.cpp you can find:

#if VTK_MAJOR_VERSION > 5
    const char *tu = mesh.tex_materials[tex_id].tex_name.c_str ();
[...]
    mapper->MapDataArrayToMultiTextureAttribute(tu,
                                                this_coordinates_name.c_str (),
                                                vtkDataObject::FIELD_ASSOCIATION_POINTS);

The type of the tu variable doesn't seem to be good, am I wrong? (I use VTK 6.2 which is available in Ubuntu 16.04 package repository.)

@taketwo
Copy link
Member

taketwo commented May 16, 2018

Let's make the version check tighter then, #if VTK_MAJOR_VERSION > 7. Would you mind submitting a PR?

@frozar
Copy link
Contributor

frozar commented May 16, 2018 via email

@taketwo
Copy link
Member

taketwo commented May 16, 2018

How did you discover the problem?!

@frozar
Copy link
Contributor

frozar commented May 16, 2018 via email

@taketwo
Copy link
Member

taketwo commented May 16, 2018

I see. Well, we have the policy of not merging own pull requests, so I need one of you guys (@jasjuang @frozar) to send a patch, because @SergioRAgostinho is on a... sabbatical.

@SergioRAgostinho
Copy link
Member

SergioRAgostinho commented May 16, 2018 via email

taketwo added a commit to taketwo/pcl that referenced this pull request May 16, 2018
@taketwo
Copy link
Member

taketwo commented May 16, 2018

Great, thanks. I've sent a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants