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

Miller, James V (Research) millerjv at crd.ge.com
Mon Jul 19 09:48:08 EDT 2004


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20040719/8591a225/attachment.html


More information about the Insight-users mailing list