<div>Alex,</div>
<div>&nbsp;</div>
<div>I think you should pass in the smart pointer by reference. Otherwise, I think it is copied.</div>
<div>&nbsp;</div>
<div>Bill<br><br></div>
<div class="gmail_quote">On Dec 12, 2007 10:09 PM, Alex. GOUAILLARD &lt;<a href="mailto:hanfei@caltech.edu">hanfei@caltech.edu</a>&gt; 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 &quot;itkImageFileWriter.h&quot;<br>#include &quot;itkVectorLinearInterpolateImageFunction.h&quot;<br>#include &quot;itkVectorResampleImageFilter.h&quot;<br>#include &quot;
itkCastImageFilter.h&quot;<br>#include &quot;itkTransform.h&quot;<br><br><br>template&lt;class ImageType, class RegistrationType&gt;<br>int Resample( &nbsp;typename ImageType::Pointer InImage,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; typename ImageType::Pointer OutImage, // should be allocated outside
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; typename RegistrationType::Pointer InRegistration,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bool Write)<br>{<br>&nbsp;//------------- resample RGB =&gt; Vector<br>&nbsp;typedef itk::VectorResampleImageFilter&lt; ImageType, ImageType &gt; ResampleFilterType;
<br>&nbsp;ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br>&nbsp;typedef itk::VectorLinearInterpolateImageFunction&lt; ImageType, double &gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ResamplerInterpolatorType;
<br>&nbsp;ResamplerInterpolatorType::Pointer interpolator = ResamplerInterpolatorType::New();<br>&nbsp;resampler-&gt;SetInterpolator( interpolator );<br>&nbsp;resampler-&gt;SetInput( InImage );<br>&nbsp;resampler-&gt;SetTransform( InRegistration-&gt;GetOutput()-&gt;Get() );
<br><br>&nbsp;resampler-&gt;SetSize( InImage-&gt;GetLargestPossibleRegion().GetSize() );<br>&nbsp;resampler-&gt;SetOutputOrigin( &nbsp;InImage-&gt;GetOrigin() );<br>&nbsp;resampler-&gt;SetOutputSpacing( InImage-&gt;GetSpacing() );<br>&nbsp;resampler-&gt;SetDefaultPixelValue( 100 );
<br><br>&nbsp;OutImage = resampler-&gt;GetOutput();<br>&nbsp;OutImage-&gt;DisconnectPipeline();<br><br>&nbsp;if(Write)<br>&nbsp; &nbsp;{<br>&nbsp; &nbsp;typedef itk::ImageFileWriter&lt; ImageType &gt; &nbsp;WriterType;<br>&nbsp; &nbsp;WriterType::Pointer writer = &nbsp;WriterType::New();
<br>&nbsp; &nbsp;writer-&gt;SetFileName( &quot;Resample.jpg&quot; );<br>&nbsp; &nbsp;writer-&gt;SetInput( OutImage );<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp;writer-&gt;Update();<br>&nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp;catch ( itk::ExceptionObject &amp;err)<br>&nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp;std::cout &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl;
<br>&nbsp; &nbsp; &nbsp;std::cout &lt;&lt; err &lt;&lt; std::endl;<br>&nbsp; &nbsp; &nbsp;return -1;<br>&nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp;}<br>&nbsp;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>