[vtkusers] Problem with vtkPolyDataMapper

Pascal Augustin pascal at rogue-research.com
Mon Apr 11 11:18:53 EDT 2011


Hi, 

Let's assume I have two actors with exactly the same shape. To avoid creating the vtkPolyData and vtkPolyDataMapper twice, I decided to let both actors share the same vtkPolyDataMapper.

vtkSmartPointer<vtkPolyDataMapper> sphereMapper = ...


// Sphere
vtkSmartPointer<vtkActor> sphereActor1 = ...
sphereActor1->SetMapper(sphereMapper);

// Sphere
vtkSmartPointer<vtkActor> sphereActor2 = ...
sphereActor2->SetMapper(sphereMapper);


// Cube
vtkSmartPointer<vtkPolyDataMapper> cubeMapper = ...
vtkSmartPointer<vtkActor> cubeActor = ...
cubeActor->SetMapper(cubeMapper);

I was expecting sphereActor1 and sphereActor2 to be displayed as spheres while cubeActor would be a cube. Here is what I sometimes get:

sphereActor1 ---> sphere
sphereActor2 --> sphere    
cubeActor ---> *** sphere*** 

The cubeActor seems to be using the shereMapper. It has the correct position, color, scale, etc. Only the shape is wrong.

I can avoid this problem by doing this:
sphereMapper->ImmediateModeRenderingOn();

Doing a shallowCopy also seems to prevent that bug from happening:
vtkSmartPointer<vtkPolyDataMapper> sphereMapper1 = vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper1->ShallowCopy(sphereMapper);
sphereActor1->SetMapper(sphereMapper1);

Am I missing something? Can multiple actors safely share the same mapper?

Thanks!

I am using VTK 5.7 on Mac OS X 10.6.7.

______________________
Pascal Augustin
Rogue Research Inc.
Montreal (Quebec), Canada
www.rogue-research.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110411/7ad626a6/attachment.htm>


More information about the vtkusers mailing list