<DIV>Hello world,</DIV>
<DIV>In C++,&nbsp;the need to keep track of&nbsp;created objects in order to call Delete on exit&nbsp;is cumbersome.</DIV>
<DIV>So, I plan to use a small template to avoid calling Delete.</DIV>
<DIV>I would like your opinion :</DIV>
<DIV>&nbsp;</DIV>
<DIV>#ifndef __vtkClassPtr_h<BR>#define __vtkClassPtr_h</DIV>
<DIV>template&lt;class T&gt;<BR>class vtkClassPtr<BR>{<BR>public:<BR>&nbsp;&nbsp;&nbsp; vtkClassPtr( T * O ) : ptr( O ) {}<BR>&nbsp;&nbsp;&nbsp; ~vtkClassPtr() { this-&gt;ptr-&gt;Delete(); }<BR>&nbsp;&nbsp;&nbsp; operator T*() const { return this-&gt;ptr; }<BR>&nbsp;&nbsp;&nbsp; T&amp; operator*() const { return *this-&gt;ptr; }<BR>&nbsp;&nbsp;&nbsp; T* operator-&gt;() const { return this-&gt;ptr; }<BR>&nbsp;&nbsp;&nbsp; vtkClassPtr( const vtkClassPtr &amp; P )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;ptr = P.ptr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P.ptr-&gt;Register( this-&gt;ptr );<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>private:&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; T * ptr;<BR>};</DIV>
<DIV>#endif<BR></DIV>
<DIV>------------------------------------------------------------------------</DIV>
<DIV>Now, have a look at the&nbsp;adapted Cone.cxx example :</DIV>
<DIV>&nbsp;</DIV>
<DIV>#include "vtkConeSource.h"<BR>#include "vtkPolyDataMapper.h"<BR>#include "vtkRenderWindow.h"<BR>#include "vtkRenderWindowInteractor.h"<BR>#include "vtkCamera.h"<BR>#include "vtkActor.h"<BR>#include "vtkRenderer.h"<BR>#include "vtkInteractorStyleTrackballCamera.h"</DIV>
<DIV>&nbsp;</DIV>
<DIV>#include "vtkClassPtr.h"<BR>typedef vtkClassPtr&lt; vtkConeSource &gt; vtkConeSourcePtr;<BR>typedef vtkClassPtr&lt; vtkPolyDataMapper &gt; vtkPolyDataMapperPtr;<BR>typedef vtkClassPtr&lt; vtkActor &gt; vtkActorPtr;<BR>typedef vtkClassPtr&lt; vtkRenderer &gt; vtkRendererPtr;<BR>typedef vtkClassPtr&lt; vtkRenderWindow &gt; vtkRenderWindowPtr;<BR>typedef vtkClassPtr&lt; vtkRenderWindowInteractor &gt; vtkRenderWindowInteractorPtr;<BR>typedef vtkClassPtr&lt; vtkInteractorStyleTrackballCamera &gt; vtkInteractorStyleTrackballCameraPtr;</DIV>
<DIV>&nbsp;</DIV>
<DIV>int main( int argc, char *argv[] )<BR>{<BR>&nbsp;&nbsp;&nbsp; vtkConeSourcePtr cone = vtkConeSource::New();<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkConeSourcePtr cone2 = cone;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cone2-&gt;SetHeight( 3.0 );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cone2-&gt;SetRadius( 1.0 );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cone2-&gt;SetResolution( 10 );<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; vtkPolyDataMapperPtr coneMapper = vtkPolyDataMapper::New();<BR>&nbsp;&nbsp;&nbsp; coneMapper-&gt;SetInput( cone-&gt;GetOutput() );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; vtkActorPtr coneActor = vtkActor::New();<BR>&nbsp;&nbsp;&nbsp; coneActor-&gt;SetMapper( coneMapper );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; vtkRendererPtr ren1= vtkRenderer::New();<BR>&nbsp;&nbsp;&nbsp; ren1-&gt;AddActor( coneActor );<BR>&nbsp;&nbsp;&nbsp; ren1-&gt;SetBackground( 0.1, 0.2, 0.4 );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; vtkRenderWindowPtr renWin = vtkRenderWindow::New();</DIV>
<DIV>&nbsp;&nbsp;&nbsp; renWin-&gt;AddRenderer( ren1 );<BR>&nbsp;&nbsp;&nbsp; renWin-&gt;SetSize( 300, 300 );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; vtkRenderWindowInteractorPtr iren = vtkRenderWindowInteractor::New();<BR>&nbsp;&nbsp;&nbsp; iren-&gt;SetRenderWindow(renWin);</DIV>
<DIV>&nbsp;&nbsp;&nbsp; vtkInteractorStyleTrackballCameraPtr style = <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkInteractorStyleTrackballCamera::New();<BR>&nbsp;&nbsp;&nbsp; iren-&gt;SetInteractorStyle(style);</DIV>
<DIV>&nbsp;&nbsp;&nbsp; iren-&gt;Initialize();<BR>&nbsp;&nbsp;&nbsp; iren-&gt;Start();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; return 0;<BR>}</DIV>
<DIV>&nbsp;</DIV><BR><BR>Aurélien REGAT-BARREL<p>
                <hr size=1>
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
<br><a href="http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/mail/mail_taglines/default/*http://fr.benefits.yahoo.com/">Créez votre Yahoo! Mail</a>
<br><br>
Dialoguez en direct avec vos amis grâce à <a href="http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.messenger.yahoo.com/">Yahoo! Messenger !</a>