[vtkusers] Problem with vtkPolyDataMapper

David Gobbi david.gobbi at gmail.com
Tue Apr 12 12:25:29 EDT 2011


Hi Bill,

Mappers can definitely share data, but I'm not sure if actors can
safely share mappers.

For instance, mappers use information from the vtkProperty, and they
check the MTime of the property to see if they should re-compute
certain cached items like the display lists.  If you have two
different actors with two different properties, then the timestamp
checks are no longer valid and things might go haywire.

Personally, I would be very cautious about code that shares mappers
between actors.

 - David


On Tue, Apr 12, 2011 at 9:57 AM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> It should work as you expect. Something else is going on. Can you post a
> small, compilable example that illustrates the problem?
>
> Bill
>
> On Mon, Apr 11, 2011 at 11:18 AM, Pascal Augustin
> <pascal at rogue-research.com> wrote:
>>
>> 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



More information about the vtkusers mailing list