[Insight-users] Need help: import/export of memory buffers

David Holmes holmesd3@yahoo.com
Fri, 14 Feb 2003 07:34:11 -0800 (PST)


Todd-

there is a nice section on this in the
ITKSoftwareGuide (found on the website).  I recommend
that you start there.  I believe it is section 4.1.7. 
The only real requirement is that your data is located
in a linear, contiguous chunk of memory.

Here is some similar code that we use to accomplish
that task.  It's not the complete code, but it gives
you the idea.  If you need more of an explaination,
let me know.

//Our array to ITK

if (copyMemFlag) {
  outVolITK->Allocate();
  memcpy((void *)outVolITK->GetBufferPointer(),
inVol->Mem, inVol->BytesPerVolume);
} else {
  itk::ImportImageContainer<long unsigned
int,T>::Pointer import; 
  import = itk::ImportImageContainer<long unsigned
int,T>::New();
  import->Initialize();
  import->SetImportPointer((T*)inVol->Mem,
inVol->BytesPerVolume, false);
  outVolITK->SetPixelContainer(import);
}


//ITK to our array

if (copyMemFlag) {
  outVol = AVW_CreateVolume(NULL, region.GetSize(0),
region.GetSize(1), region.GetSize(2));
  outVol->Mem = memcpy(outVol->Mem, (void
*)inImgITK->GetBufferPointer(),
outVol->BytesPerVolume);
} else 	{
 
inImgITK->GetPixelContainer()->SetContainerManageMemory(false);
  outVol =
AVW_CreateVolume(inImgITK->GetPixelContainer()->GetImportPointer(),
region.GetSize(0), region.GetSize(1),
region.GetSize(2));
}


david


--- Todd Koumrian <todd@core-dump.stanford.edu> wrote:
> Hello,
> 
> I need help interfacing ITK functionality to our
> research framework.  In
> order to use ITK, I must New() appropriate itkImages
> and somehow load them
> with pixel data from another in-memory format. 
> After processing, I must
> return the results to another buffer (not ITK) also
> managed by the
> application.  While I understand the basics of image
> creation no problem, I
> don't understand how to do this bulk load/unload
> efficiently.
> 
> GetPixel()/SetPixel() is of course too inefficient.
> 
> itkImportImageFilter exists, but what about export?
> 
> The manual makes mention of using image iterators as
> a better alternative to
> GetPixel()/SetPixel(), but does not seem to explain
> them.  I'm lost here.
> 
> Regards,
> 
> Todd Koumrian
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
>
http://public.kitware.com/mailman/listinfo/insight-users


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com