<div>Alex,</div>
<div> </div>
<div>I think you should pass in the smart pointer by reference. Otherwise, I think it is copied.</div>
<div> </div>
<div>Bill<br><br></div>
<div class="gmail_quote">On Dec 12, 2007 10:09 PM, Alex. GOUAILLARD <<a href="mailto:hanfei@caltech.edu">hanfei@caltech.edu</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">hi all,<br><br>I developped (read: copied from the examples) a simple function that<br>should resample a given 2D image according to the result of a
<br>registration (see attached file).<br><br>I have a scope problem: after I copy the output of the filter in a<br>separate disconnected image, if I write the image in a file from within<br>the function, I have what I expect, but If I try to pass the pointer out
<br>and to print it from outside later, it fails. It looks like the buffer<br>and a few other attributes are being wiped out.<br><br>Any idea on what I am doing wrong? Better, any suggestion on what to do<br>to make it right ?
<br><font color="#888888"><br>alex.<br></font><br>#include "itkImageFileWriter.h"<br>#include "itkVectorLinearInterpolateImageFunction.h"<br>#include "itkVectorResampleImageFilter.h"<br>#include "
itkCastImageFilter.h"<br>#include "itkTransform.h"<br><br><br>template<class ImageType, class RegistrationType><br>int Resample( typename ImageType::Pointer InImage,<br> typename ImageType::Pointer OutImage, // should be allocated outside
<br> typename RegistrationType::Pointer InRegistration,<br> bool Write)<br>{<br> //------------- resample RGB => Vector<br> typedef itk::VectorResampleImageFilter< ImageType, ImageType > ResampleFilterType;
<br> ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br> typedef itk::VectorLinearInterpolateImageFunction< ImageType, double ><br> ResamplerInterpolatorType;
<br> ResamplerInterpolatorType::Pointer interpolator = ResamplerInterpolatorType::New();<br> resampler->SetInterpolator( interpolator );<br> resampler->SetInput( InImage );<br> resampler->SetTransform( InRegistration->GetOutput()->Get() );
<br><br> resampler->SetSize( InImage->GetLargestPossibleRegion().GetSize() );<br> resampler->SetOutputOrigin( InImage->GetOrigin() );<br> resampler->SetOutputSpacing( InImage->GetSpacing() );<br> resampler->SetDefaultPixelValue( 100 );
<br><br> OutImage = resampler->GetOutput();<br> OutImage->DisconnectPipeline();<br><br> if(Write)<br> {<br> typedef itk::ImageFileWriter< ImageType > WriterType;<br> WriterType::Pointer writer = WriterType::New();
<br> writer->SetFileName( "Resample.jpg" );<br> writer->SetInput( OutImage );<br> try<br> {<br> writer->Update();<br> }<br> catch ( itk::ExceptionObject &err)<br> {<br> std::cout << "ExceptionObject caught !" << std::endl;
<br> std::cout << err << std::endl;<br> return -1;<br> }<br> }<br> return 0;<br>}<br>_______________________________________________<br>Insight-users mailing list<br><a href="mailto:Insight-users@itk.org">
Insight-users@itk.org</a><br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br><br></blockquote></div><br>