[vtkusers] stenciling problem-- is this code thread safe?
David Gobbi
david.gobbi at gmail.com
Fri Feb 11 13:35:24 EST 2011
If you are reporting the vtkLinearExtrusionFilter, I already did.
On Fri, Feb 11, 2011 at 11:31 AM, Mark Roden <mmroden at gmail.com> wrote:
> Hi David,
>
> Unfortunately, the current vtk master branch is seriously broken in
> its java wrappings. I'm putting together a bug report now...
>
> Thanks,
> Mark
>
> On Fri, Feb 11, 2011 at 10:09 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>> I should add: with the current VTK master and release branches,
>> vtkPolyDataToImageStencil no longer requires vtkLinearExtrusionFilter
>> to be used beforehand. So you could try that.
>>
>> - David
>>
>>
>> On Fri, Feb 11, 2011 at 11:06 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>>> I was doubtful about the global memory, but I looked through the
>>> filters just to be sure. And guess what I found... here is some
>>> highly suspect code in vtkLinearExtrusionFilter:
>>>
>>> double *vtkLinearExtrusionFilter::ViaNormal(double x[3], vtkIdType id,
>>> vtkDataArray *n)
>>> {
>>> static double xNew[3], normal[3];
>>> int i;
>>>
>>> n->GetTuple(id, normal);
>>> for (i=0; i<3; i++)
>>> {
>>> xNew[i] = x[i] + this->ScaleFactor*normal[i];
>>> }
>>>
>>> return xNew;
>>> }
>>>
>>> Code like the above is definitely going to cause thread problems.
>>> And this isn't the only place in that class where code like this appears.
>>>
>>> Yikes!
>>>
>>> - David
>>>
>>>
>>> On Fri, Feb 11, 2011 at 10:46 AM, Mark Roden <mmroden at gmail.com> wrote:
>>>> What I mean is, I have a vtkPolyData that has been DeepCopied and a
>>>> vtkImageData that is binary and distinct from all other data.
>>>>
>>>> When I call the previously listed code with multiple threads (each
>>>> with their own polydata and binary image to fill in), the result is
>>>> generally a very garbled image. If I call from a single thread in
>>>> series, one for each polydata/image pair, then everything works out
>>>> fine.
>>>>
>>>> So it seems to me that something in the above series isn't thread
>>>> safe. Each thread is declaring its own local objects, but is there
>>>> some global memory that's being used or accessed here?
>>>>
>>>> On Fri, Feb 11, 2011 at 9:23 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>>>>> Hi Mark,
>>>>>
>>>>> Explain in more detail what you mean by "call from multiple threads".
>>>>> VTK is, in general, not thread safe and you cannot call Update() on
>>>>> a filter from more than one thread. Each thread needs to have its own
>>>>> set of filters. And in general, you cannot feed a data object into more
>>>>> than one thread, because even simple methods like GetBounds() are
>>>>> not thread safe.
>>>>>
>>>>> When using VTK from multiple threads, it is necessary to apply
>>>>> extreme caution.
>>>>>
>>>>> - David
>>>>>
>>>>>
>>>>> On Fri, Feb 11, 2011 at 10:00 AM, Mark Roden <mmroden at gmail.com> wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> This code does not have threads enabled in vtk 5.6.1 (the code is in Java):
>>>>>>
>>>>>> vtkLinearExtrusionFilter extruder = new vtkLinearExtrusionFilter();
>>>>>> extruder.SetInput(data);
>>>>>> extruder.SetVector(0, 0, spacing[2]);
>>>>>> extruder.Update();
>>>>>> vtkPolyData extruderOutput = extruder.GetOutput();
>>>>>>
>>>>>> vtkPolyDataToImageStencil pol2Stenc = new vtkPolyDataToImageStencil();
>>>>>> pol2Stenc.SetTolerance(0);
>>>>>> pol2Stenc.SetInput(extruderOutput);
>>>>>> pol2Stenc.SetInformationInput(binaryOrgan);
>>>>>> pol2Stenc.Update();
>>>>>> vtkImageStencilData pol2StencOutput = pol2Stenc.GetOutput();
>>>>>>
>>>>>> // This is where the memory leak is!!!!
>>>>>> vtkImageStencil stencil = new vtkImageStencil();
>>>>>> stencil.SetInput(binaryOrgan);
>>>>>> stencil.ReverseStencilOn();
>>>>>> stencil.SetStencil(pol2StencOutput);
>>>>>> stencil.Update();
>>>>>>
>>>>>> // We're doing this because of an email to Mark
>>>>>> // that says this will fix our memory issues
>>>>>> final vtkImageData stencilOutput = stencil.GetOutput();
>>>>>> final vtkImageData imageToKeep = new vtkImageData();
>>>>>> imageToKeep.DeepCopy(stencilOutput);
>>>>>> stencilOutput.Delete();
>>>>>>
>>>>>> When I try to call this code from multiple threads (ie, to create the
>>>>>> stencils for multiple organs), Bad Things happen, as in, the data are
>>>>>> entirely corrupted. Is this code thread safe?
>>>>>>
>>>>>> Mark
>>>>>> _______________________________________________
>>>>>> 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
>>>>>>
>>>>>
>>>>
>>>
>>
>
More information about the vtkusers
mailing list