Single polydata, different mappers for different scalars?

Hey all,

I am trying to use a single polydata with differents point data scalars mapped to it in vtk.js but I did not manage how to do it. I tried:

polyData.getPointData().setActiveScalars(polyData.getPointData().getArrayByIndex(0).getName());
mapper0.setInputData(polyData);
polyData.getPointData().setActiveScalars(polyData.getPointData().getArrayByIndex(1).getName());
mapper1.setInputData(polyData);

but both actors associated to the mappers display the same point data scalars (index 1), which I expected. Attempt #2:

mapper0.setInputData(polyData);
mapper1.setInputData(polyData);
mapper0.setColorByArrayName(polyData.getPointData().getArrayByIndex(0).getName());
mapper1.setColorByArrayName(polyData.getPointData().getArrayByIndex(1).getName());

But this does not seem to have any effect.

Is there a method to choose which scalars the mapper will map, besides setActiveScalars, or do I need to create as many copies as my polydata as I have mappers? If so, what is the recommended way to create such copies?

Thanks!

but both actors associated to the mappers display the same point data scalars (index 1), which I expected.

Setting the active scalars applies to the entire PointData, so both of your mappers will show the index 1 data scalars.

The second approach is more correct. You probably also want to call mapper.setColorMode(ColorMode.MAP_SCALARS) (ColorMode comes from here). I think that will make it work.

Thanks for your reply! I finally used the shallowCopy method of polydata, but the next time I go back to this project I’ll test mapper.setColorMode to see if it fixes the issue, this seems cleaner.