[Insight-users] Copy one pointer's content to another pointer

Ivan Macia imacia at vicomtech.es
Tue Jul 20 02:42:27 EDT 2004


For creating a filter that does nothing, one straightforward way without
setting parameters is using a CastImageFilter. Here is a pseudoexample :

typedef itk::Image<float,3>	FloatImageType;
typedef itk::CastImageFilter<FloatImageType,FloatImageType>  NullFilterType;
NullFilterType::Pointer myNullFilter = NullFilterType ::New();
myNullFilter->SetInput(someImagePtr->GetOutput());
myNullFilter->Update();

That should work. The main difference is that the image remains connected to
the pipeline.
Hope that helps

Iván



-----Mensaje original-----
De: Jiang [mailto:jiang at TI.Uni-Trier.DE]
Enviado el: lunes, 19 de julio de 2004 22:02
Para: ITK
Asunto: WG: [Insight-users] Copy one pointer's content to another pointer




-----Ursprüngliche Nachricht-----
Von: Jiang [mailto:jiang at ti.uni-trier.de]
Gesendet: Montag, 19. Juli 2004 22:02
An: 'Miller, James V (Research)'
Betreff: AW: [Insight-users] Copy one pointer's content to another pointer

Many thanks for your reply.
I use your first method to copy image, since I’m familiar with it. For
second method, I tried it, but failed.
I don’t know how to set the other parameters for ShiftScaleImageFilter. It
is not easy to find example from
the documentation.

Anyway your answer helps me to solve this problem


Best regards,

Jiang


-----Ursprüngliche Nachricht-----
Von: Miller, James V (Research) [mailto:millerjv at crd.ge.com]
Gesendet: Montag, 19. Juli 2004 15:48
An: 'Jiang'; ITK
Betreff: RE: [Insight-users] Copy one pointer's content to another pointer

The line

tmp->SetPixelContainer(pointer1->GetPixelContainer());

copies a reference (pointer) from pointer1 to tmp.  This is a shallow copy
of the pixel data.  So any changes you make to the pixel data in tmp is
actually modifying the same pixel data from pointer1.

Instead of copying the pixel container, you'll need to call Allocate() on
tmp and then use iterators to copy the data from pointer1 to tmp.

Another option is to run you image through a filter, setting the parameters
of the filter to do nothing.  For instance, you could use the
ShiftScaleImageFilter and set the Shift to zero and the Scale to one.  This
is not the most efficient way to copy an image (since some trivial math is
done) but is a simple way to create a copy of an image.

Jim


-----Original Message-----
From: Jiang [mailto:jiang at TI.Uni-Trier.DE]
Sent: Monday, July 19, 2004 9:27 AM
To: ITK
Subject: [Insight-users] Copy one pointer's content to another pointer
Hi ITK users,
I want to copy one ITK pointer’s content to another ITK pointer, so that the
operation
performed on the second pointer will not influence the first pointer.
I do it as follow:
   WriteImageType::Pointer pointer1 already exists and has some content
   WriteImageType::Pointer tmp = WriteImageType::New();//copy pointer1’s
content to tmp
    tmp->SetRequestedRegion( pointer1->GetRequestedRegion() );
    tmp->SetBufferedRegion( pointer1->GetBufferedRegion() );
    tmp->SetLargestPossibleRegion( pointer ->GetLargestPossibleRegion() );
    tmp->SetPixelContainer(pointer1->GetPixelContainer() );
    tmp->CopyInformation( pointer1 );


Now I can operate the tmp’s content. However it still affect pointer1. It
seems that all operations
performed on tmp are same as performed on pointer1.

How can I copy one pointer totally to another one?


Thanks!


Jiang



More information about the Insight-users mailing list