[vtkusers] Multi-threaded creation, display and deletion of actors

Dženan Zukić dzenanz at gmail.com
Thu Feb 21 16:21:39 EST 2013


Thank you for your help Sebastien. Other issues appeared as well after I
have introduced multi-threading. The VTK-related part is finished. Here is
a sketch of my solution:

void timerFunction()
{
    if (render)
    {
        renderLock->Lock();
        render=false;
        renderLock->Unlock();
        mainForm.vis->GetRenderWindow()->Render();
  QApplication::processEvents();
    }
}

void threadFunction()
{
    while (notFinished)
    {
        //calculate stuff
        vtkSmartPointer<vtkPolyData> pd=v->getPoly();
        renderLock->Lock();
        render=true;
        ((vtkPolyDataMapper *)v->actor->GetMapper())->SetInput(pd);
        v->actor->GetMapper()->Modified();
        renderLock->Unlock();
        v->actor->GetMapper()->Update();
    }
}


On Wed, Feb 20, 2013 at 8:06 PM, Sebastien Jourdain <
sebastien.jourdain at kitware.com> wrote:

> The add actor should be done by the same VTK thread that is rendering.
> So only one thread can do that action.
> Moreover, you should call Update() on the mapper within each of your
> thread to reduce the work that will be done by the main vtk thread.
>
> Hope that make sense,
>
> Seb
>
> PS: VTK is not thread safe, but I've already done something similar to
> what you did without any issue.
>
>
> On Wed, Feb 20, 2013 at 5:18 PM, Dženan Zukić <dzenanz at gmail.com> wrote:
>
>> I have a need to modify the scene from multiple threads.
>>
>> Each thread looks like:
>> {
>> for (i=1 to 100)
>> create mesh_i;
>> convert it to vtkPolyData;
>> if exists actor delete it;
>> create actor with pd;
>> add actor to renderer;
>> update display;
>> }
>>
>> How best to accomplish this? I already tried this<http://www.vtk.org/pipermail/vtkusers/2004-April/073478.html>approach, but it does not work. It always crashes before returning from
>> Render() method. Crashes are at random location in VTK rendering code.
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130221/3c6222ec/attachment.htm>


More information about the vtkusers mailing list