[vtkusers] raycast multithread problem

xabi riobe xabivtk at gmail.com
Thu Jan 4 10:07:13 EST 2007


Hi,

I faced a multithreading problem involving the following macro in
vtkFixedPointVolumeRayCastHelper.h  (vtk release 5.0.2)

#define VTKKWRCHelper_IncrementAndLoopEnd()              \
      imagePtr+=4;
         \
      }
                 \
    if( j%32 == 31 )
           \
      {
                 \
      double fargs[1];
            \
      fargs[0] =
static_cast<double>(j)/static_cast<float>(imageInUseSize[1]-1);    \
      mapper->InvokeEvent(
vtkCommand::VolumeMapperRenderProgressEvent, fargs );   \
      }
              \
    }

I have a vtkCommand observing the event that calls a method
SetProgressState(value) of an object containing a wxProgressDialog
that will be updated with the value comming from 'fargs'.

The problem is that wxProgressDialog calls a "SendMessage" (windows)
and if the event has been fired in a thread that is not the main one,
all that leads to a deadlock when trying to draw the progress bar.

For example if we have two threads for the raycast, the main one will
be in charge of the pair values for the j variable and the event will
be fired by the other thread (when j%32 == 31, j is not pair)

So a solution to avoid that is replacing the "if" line in the #define
by this one:

if( 0==threadID && ( j%10 ||  j==imageInUseSize[1]-1 ) )

In that case the event is only fired by the main thread.
( j%10 is to have a more precise progression and
j==imageInUseSize[1]-1 is to have the value 1.0 with the ProgressEvent
and not only for the EndProgressEvent ).


I am wondering if it could be possible to patch something like this in
vtk or if someone knows a better solution or an incompatibility with
other code.



More information about the vtkusers mailing list