This is a digest from the original post from Luis Ibañez:<div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
1) When writing functions that take an image as an argument,</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    we usually use a Raw pointer instead of a Smart Pointer.</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    The reason is that SmartPointers will not do polymorphism.</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    That is, if you use smart pointers, you can call that function</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    later with an argument that is a derived class of that image </blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    type.</blockquote><br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    If you look at most ITK filters, you will find that raw pointers</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    are used in the API, for passing and receiving images.</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    However, when we call those functions we pass a SmartPointer</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    to them (since SmartPointers know how to cast themselves as</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    raw pointers).</blockquote><br><br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
2) The only case in which you may want to pass an image</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    SmartPointer as argument to a function is when you are</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    creating that image inside the function. </blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    In that case, passing the SmartPointer by reference is</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    a reasonable choice.</blockquote><br><br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
3) Please note that the construction</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
          const    Image::<span class="il" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 136); ">ConstPointer</span> &amp;  ptr ....;</blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    prevents the internal mechanisms of the SmartPointer </blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    from working, since the &quot;const&quot; keyword prevents the &quot;ptr&quot;</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    variable from changing. (strictly speaking it prevents the</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    smart pointer from calling the non-const method Register()</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
    on the object that it points to).</blockquote><br><br><span class="Apple-style-span" style="border-collapse: separate; font-size: small;"><span class="Apple-style-span" style="border-collapse: collapse;">And then examples of usage when a Image is an input to a function</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><span class="Apple-style-span" style="border-collapse: separate; font-size: small;"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></span></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><span class="Apple-style-span" style="border-collapse: separate; font-size: small;"><span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="font-size: 13px; "><div class="im" style="color: rgb(80, 0, 80); ">
<span style="font-family: &#39;courier new&#39;, monospace; ">     template&lt;typename TITKImgType&gt;</span><br style="font-family: &#39;courier new&#39;, monospace; "><span style="font-family: &#39;courier new&#39;, monospace; ">     bool</span><br style="font-family: &#39;courier new&#39;, monospace; ">
<span style="font-family: &#39;courier new&#39;, monospace; ">     WriteFile(</span><br style="font-family: &#39;courier new&#39;, monospace; "><span style="font-family: &#39;courier new&#39;, monospace; ">         const std::string&amp; a_fullFilename,</span><br style="font-family: &#39;courier new&#39;, monospace; ">
</div><span style="font-family: &#39;courier new&#39;, monospace; ">         const TITKImgType * );</span><br><br><br>and you will be able to call it as<br><br>    ImgType::Pointer image = filter-&gt;GetOutput();<br><br>    WriteFile&lt;ImgType&gt;(</span></span></span></span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">&quot;out.mhd&quot;</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">, image<span style="background-color: rgb(255, 255, 153); "> </span>);</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Notice how the function is defined to receive a raw pointer but when you call it we pass a smartpointer.</span></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">Regards</span></font></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br>
</span></div><div><div class="gmail_quote">On Mon, Aug 9, 2010 at 9:42 PM, habibbaluwala2010 <span dir="ltr">&lt;<a href="mailto:habibbaluwala@gmail.com">habibbaluwala@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Hello Sergio,<br>
                 Can you give me an example of how to use this in context<br>
with the syntax? I am really thankful for the help.<br>
<br>
<br>
Kind regards,<br>
<br>
Habib Baluwala<br>
<div><div></div><div class="h5"><br>
<br>
<br>
<br>
Sergio Vera wrote:<br>
&gt;<br>
&gt; Following advices from Luis Ibañez in a previous mail of the list, we now<br>
&gt; use the following rules:<br>
&gt;<br>
&gt; const ITKImgType *ImgIn  when images are input to a method and<br>
&gt;<br>
&gt; ITKImgType::Pointer &amp;ImgOut  when the image will be created inside the<br>
&gt; function<br>
&gt;<br>
&gt; regards<br>
&gt;<br>
&gt; 2010/8/6 Dženan Zukić &lt;<a href="mailto:dzenanz@gmail.com">dzenanz@gmail.com</a>&gt;<br>
&gt;<br>
&gt;&gt; Use ImageType::Pointer. Here is an example:<br>
&gt;&gt;<br>
&gt;&gt; void calc2DJointHistogram(VisualizingImageType::Pointer x,<br>
&gt;&gt; VisualizingImageType::Pointer y, std::string savefilename)<br>
&gt;&gt; {<br>
&gt;&gt; ...<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; //calling it<br>
&gt;&gt; VisualizingImageType::Pointer lVis, hVis;<br>
&gt;&gt; ...<br>
&gt;&gt; hVis=hReader-&gt;GetOutput();<br>
&gt;&gt; calc2DJointHistogram(lVis, hVis, fnNoExt+&quot;_LH.png&quot;);<br>
&gt;&gt;<br>
&gt;&gt; Dženan<br>
&gt;&gt;<br>
&gt;&gt; On Fri, Aug 6, 2010 at 15:32, habibbaluwala2010<br>
&gt;&gt; &lt;<a href="mailto:habibbaluwala@gmail.com">habibbaluwala@gmail.com</a>&gt;wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hi Everyone,<br>
&gt;&gt;&gt;                 I am a biot confused on how can i pass an image with<br>
&gt;&gt;&gt; smart<br>
&gt;&gt;&gt; pointers to an outside function . I basically need this to avoid<br>
&gt;&gt;&gt; reproducing<br>
&gt;&gt;&gt; the code again and again and also to avoid composite filters. It would<br>
&gt;&gt;&gt; be<br>
&gt;&gt;&gt; very helpful if you can provide an example which does the job!!! Anyways<br>
&gt;&gt;&gt; looking forward to your replies.<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; View this message in context:<br>
&gt;&gt;&gt; <a href="http://old.nabble.com/Problem-with-passing-images-to-functions-tp29356451p29356451.html" target="_blank">http://old.nabble.com/Problem-with-passing-images-to-functions-tp29356451p29356451.html</a><br>

&gt;&gt;&gt; Sent from the ITK - Users mailing list archive at Nabble.com.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _____________________________________<br>
&gt;&gt;&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Visit other Kitware open-source projects at<br>
&gt;&gt;&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt;&gt;&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt;&gt;&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt;&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _____________________________________<br>
&gt;&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt;<br>
&gt;&gt; Visit other Kitware open-source projects at<br>
&gt;&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt;<br>
&gt;&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt;&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;&gt;<br>
&gt;&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt;&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;&gt;<br>
&gt;&gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Sergio Vera<br>
&gt;<br>
&gt;  Alma IT Systems<br>
&gt;  C/ Vilana, 4B, 4º 1ª<br>
&gt;  08022 Barcelona<br>
&gt;  T. (+34) 932 380 592<br>
&gt;  <a href="http://www.alma3d.com" target="_blank">www.alma3d.com</a><br>
&gt;<br>
&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
<br>
</div></div><font color="#888888">--<br>
View this message in context: <a href="http://old.nabble.com/Problem-with-passing-images-to-functions-tp29356451p29391440.html" target="_blank">http://old.nabble.com/Problem-with-passing-images-to-functions-tp29356451p29391440.html</a><br>

</font><div><div></div><div class="h5">Sent from the ITK - Users mailing list archive at Nabble.com.<br>
<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. (+34) 932 380 592<br> <a href="http://www.alma3d.com">www.alma3d.com</a><br>

</div>