[Insight-users] Follow up question on import/export data buffer from itk filters

Luis Ibanez luis . ibanez at kitware . com
Thu, 18 Sep 2003 22:32:15 -0400


Hi Frank,

There are two ways of passing the buffer of the output image
from an ITK filter.

A) you can pass your own allocated buffer to the ITK
    image filter and ask him to use this buffer to write
    to output on it.

B) you can take the buffer naturally allocated by the
    ITK filter, and ask the filter NOT to deallocate the
    buffer when the filter is destroyed.


For option (A) you use the line
 >  inputImg->GetPixelContainer()->SetImportPointer(inbuffer,
 >                                           dataBufferSize, false);


For option (B) you use the line
 >  inputImg->GetPixelContainer()->SetContainerManageMemory(false);





You should be ok adding the intermediate ReleaseDataFlagOn()
calls in your code.  We have found problems in some very particular
cases related to the use of this call. In particular in complex
filters that internally build mini-pipelines and call Update()
more than once in its first filter. But... that's a very special
case....

In general you are fine calling ReleaseDataFlagOn() on the
intermediate filters of your pipeline. This is specially useful
in your case since you are calling the pipeline only once
inside your "C" function.

The same approach is used for the VolView ITK Plugins.  You may
want to take a look at the code in

        InsightApplications/VolviewPlugins



Regards,


    Luis



--------------------
Frank Webster wrote:
> Hi, all:
> 
>  I read previous posts on import/export data buffer from itk filters. 
> Here I have additional questions regarding this issue.
> 
>  As Luis has warned that SetContainerManageMemory() should not be called 
> prematurely. I am not quite sure I understand this. I have the following 
> code segment to illustrate the situation: Input data buffer from 
> outside; release intermidate filter's data when not needed, returned the 
> final filter's data buffer in the end.
> 
> I put questions between lines.
> 
> 
> int testfunc(short *inbuffer, float *outbuffer, int *dims, double 
> *spacing, doube *orign, ...)
> {
>  typedef itk::Image<short, 3> inputImgType;
>  typedef itk::Image<float, 3> outputImgType;
>  inputImgType::Pointer inputImg;
>  outputImgType::Pointer outputImg;
> 
>  // Keep track of the number of voxels in the image
>  int dataBufferSize = dims[0]*dims[1]*dims[2];
> 
>  //set up inputImg region, origin spacing
> 
>  inputImg = inputImgType::New();
> 
> 
>  itkfilter1->SetInput(inputImg);
>  itkfilter1->ReleaseDataFlagOn(); //Could I add on ReleaseDataFlagOn()?
> 
>  itkfilter2->SetInput(itkfilter1->GetOutput());
>  itkfilter2->ReleaseDataFlagOn(); //Could I?
> 
>  itkfilter3->SetInput(itkfilter2->GetOutput());
> 
>  outbuffer = 
> itkfilter3->GetOutput()->GetPixelContainer()->GetImportPointer();
> }
> 
> Thanks.
> 
> -Feng
> 
> _________________________________________________________________
> Get 10MB of e-mail storage! Sign up for Hotmail Extra Storage.  
> http://join . msn . com/?PAGE=features/es
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>