WG: [Insight-users] Copy one pointer's content to another pointer
Jiang
jiang at TI.Uni-Trier.DE
Mon Jul 19 16:02:18 EDT 2004
-----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 Im familiar with it. For
second method, I tried it, but failed.
I dont 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 pointers 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 pointer1s
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 tmps 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/b48bcf09/attachment-0001.html
More information about the Insight-users
mailing list