[Insight-users] Re: Passing ITK images in/out of C-like functions
Luis Ibanez
luis.ibanez at kitware.com
Sat Nov 20 19:15:27 EST 2004
Hi Vijay,
In your code, the variable "kimag" is a raw pointer
to a SmartPointer of an ITK image. If you want to
address methods from the image type you have to
unreference the pointer by using the notation (*kimage).
Like in :
(*kimage)->GetSpacing();
Please let us know if you have further questions,
Thanks
Luis
------------------------
Vijay Prashanth wrote:
> Hi Luis,
> Thank you very much for the solution regarding the usage of
> smart pointers. It was helpful in solving the problem. Actually I had also
> arrived at it but I used the SetReferenceCount and GetReferenceCount
> methods for increasing the reference count instead the Register method You
> had suggested.
>
> But I would like to clarify a point on the OptionA.
>
> In the solution -Option A:
>
> // before calling the function
> typedef itk::Image<unsigned char, 2> ImageType;
> Image Type::Pointer img;
> void * pimg = &img;
> myFunctionForCreatingAnImage( pimg, k1, k2, k3,... kn );
>
> // inside the function
> void myFunctionForCreatingAnImage( void * pimg, k1, k2 ... )
> {
> typedef itk::Image<unsigned char, 2> ImageType;
>
> // your code for the importer filter..
>
> ImageType::Pointer *kimg = (ImageType::Pointer *)pimg;
> *kimg = importer->GetOutput();
> return;
> }
>
> Now if we use 'kimg' to call some of the methods of itk::Image
> class inside the function 'myFunctionForCreatingAnImage( )
> an error occured like" the function does not belong to 'kimg'. I
> think this because it is a pointer of type smart pointer class and so it does
> not know the itk::image methods.
> Do we have to use like (*kimg)->itk::imagemethods( ) , in order
> to obtain the address of the itk::image object stored in the smart pointer?.
>
> Option B was working good(increasing the reference count).
>
>
More information about the Insight-users
mailing list