[Insight-users] Alternative method for releasing intermediate memory.

Luis Ibanez luis . ibanez at kitware . com
Sun, 07 Sep 2003 11:28:30 -0400


Hi Michael,

One mechanism you can use for releasing the memory of the
VTK-ITK adaptor filter is to construct it in a local scope.

For doing this, simply add a code block "{"  "}" .

For example

main()
{
   typedef ...
   typedef ...
   // more code

   RegistrationMethodType::Pointer registrator =
                            RegistrationMethodType::New();

      {  // ***** start a local scope

      vtkReader * reader    = vtkReader::New();
      AdaptorType::Pointer vtk2itk = AdaptorType::New();
      reader->SetFileName( argv[1] );
      vtk2itk->SetInput( reader->GetOutput() );
      vtk2itk->Update(); //  <---- Very important
      registrator->SetFixedImage( vtk2itk->GetOutput() );
      reader->Delete();  // only VTK filters need Delete();

      }  // ***** end of local scope

         // smart points created inside the scope
         // will be destroyed at this point.
         // In particular "vtk2itk" will be destroyed.
         // The output image of 'vtk2itk' will survive
         // because it is now being referenced from the
         // registration method object

   // Here continue with the registration process...
   registrator->SetOptimizer( optimizer );...
   // ... more code...

}

---


  Regards,



    Luis


--------------------
Michael Kuhn wrote:
> Hi Luis,
> 
> thanks for your answer, that helped. However, I think my application 
> will now consume more memory. Is there a way to nevertheless release the 
> memory allocated by the vtk2itk-Filter? It would also be helpful, if 
> this was only possible after the ResampleImageFilter has completed its 
> work, since the pipeline then continues. My application basically looks 
> like this: vtkReader => vtk2itk => [ResampleImageFilter (with bspline)] 
> => ResampleImageFilter (with bspline) => ImageRegistrationMethod. The 
> Filter in [] is optional (i.e. it depends on a flag whether it is 
> executed or not). This path exists twice, for the fixed and the moving 
> image. (Since it should be possible to visualize the image after the 
> optional filter, I can't just calculate the overall transform for both 
> ResampleFilters and only use one of them)
> 
> Thanks,
> 
> Michael
> 
> 
> 
> Luis Ibanez wrote:
> 
>>
>> Hi Michael,
>>
>> Thanks for your detailed report.
>> We wish all problem reports were as specific as yours.
>>
>>
>> I was able to reproduce the problem you pointed out. Effectively,
>> when the BSpline interpolator is used, the outpur values are
>> all set to the default value. This does not occur with the
>> linear interpolator.
>>
>>
>>
>> However the real culprit of this undesirable effect seems to be
>> the innocent-looking call to "ReleaseDataFlag()" in
>>
>> >    vtk2itk->GetImporter()->SetReleaseDataFlag(true);
>>
>> This call authorizes the itkVTKImporter filter to release its
>> memory as soon as the next filter in the pipeline runs its Update()
>> method.
>>
>> Some ITK filters however are not well suited for supporting this
>> call in their predecessors. This typically happens when the filter
>> has internal calls to Update() othere than their own. Filters having
>> internal pipelines are an example of this condition.
>>
>>
>> Removing the call to ReleaseDataFlagOn() solves the problem in this
>> case.
>>
>>
>>
>> Please let us know if you find further problems,
>>
>>
>>     Luis
>>
>>
>>
>