[Insight-users] importing a 2D array into a itk::Image
Luis Ibanez
luis . ibanez at kitware . com
Wed, 07 Aug 2002 09:13:23 -0400
Hi zecrou,
The ImportImageContainer, as most of the ITK classes, derives
from itk::Object. As a consequence it is managed using SmartPointers
instead of raw pointers.
The notation in your code should be:
itk::ImportImageContainer<long unsigned int,
unsgned char>::Pointer import;
instead of
itk::ImportImageContainer<long unsigned int,
unsgned char> * import;
by using a raw pointer, the reference count of the object is
dropping to zero when the New() operator returns and the new
born object is destroyed by the time you try to use it.
This is a common source of confusion for VTK users because
VTK uses raw pointers to receive the results of the New() operator.
The same goes for the use of Delete() method which is mandatory
in VTK but forbiden in ITK (since the SmartPointers will take care
of releasing memory when appropiate).
Please let us know if you encounter any further problem,
Thanks,
Luis
==========================================
Zecrou@aol.com wrote:
> Hi everybody
>
> I would like to import an 512*512 2D array of unsigned char into an itk::Image<unsigned char, 2>
>
> itk::ImportImageContainer<long unsigned int, unsgned char> *import;
> import = itk::ImportImageContainer<long unsigned int, unsigned char>::New();
> import->Initialize();
> import->Reserve(512*512);
> import->SetImportPointer(pointer_to_my_array,512,true);
>
> itk::Image<unsigned char, 2> *img = itk::Image<unsigned char, 2>::New();
> img->SetPixelContainer(import);
>
> the problem is that when I launch the program, there's a segmentation fault with the import->Initialize()
>
> I tried to remove the initialization but there is a new segmentation fault with the import->Reserve(512*512)
>
> Does anyone have an idea?
>
> Is there any other way to import my array?
>
>
> Thank you in advance
>
> zecrou
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>
>