[vtkusers] Multi-threaded creation, display and deletion of actors
Dženan Zukić
dzenanz at gmail.com
Fri Feb 22 10:28:41 EST 2013
The other problem was usage of static variable. When I changed code to
avoid it, I introduced a bug. I have fixed it meanwhile, and it is working
correctly even with mapper update called from threads.
But to be on the safe side I removed those updates from threads. Thanks
again for advice.
On Thu, Feb 21, 2013 at 7:14 PM, Sebastien Jourdain <
sebastien.jourdain at kitware.com> wrote:
> Ok this is still wrong.
>
> You can not have part of a vtk pipeline shared across 2 thread. Which is
> the case for you as you call v->actor->GetMapper()->Update(); while the
> actor is already bind to the renderer that is driven by the VTK thread.
>
> You should create the mapper and the actor within your thread and transfer
> the actor to the VTK thread with the locking mechanism.
> But before giving that actor, as I said, you should call update on the
> mapper.
>
> Basically what you've done could work if you don't call
> v->actor->GetMapper()->Update();
>
> Seb
>
>
> On Thu, Feb 21, 2013 at 4:21 PM, Dženan Zukić <dzenanz at gmail.com> wrote:
>
>> 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/20130222/94c431b8/attachment.htm>
More information about the vtkusers
mailing list