<DIV>Hello world,</DIV>
<DIV>In C++, the need to keep track of created objects in order to call Delete on exit 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> </DIV>
<DIV>#ifndef __vtkClassPtr_h<BR>#define __vtkClassPtr_h</DIV>
<DIV>template<class T><BR>class vtkClassPtr<BR>{<BR>public:<BR> vtkClassPtr( T * O ) : ptr( O ) {}<BR> ~vtkClassPtr() { this->ptr->Delete(); }<BR> operator T*() const { return this->ptr; }<BR> T& operator*() const { return *this->ptr; }<BR> T* operator->() const { return this->ptr; }<BR> vtkClassPtr( const vtkClassPtr & P )<BR> {<BR> this->ptr = P.ptr;<BR> P.ptr->Register( this->ptr );<BR> }<BR> <BR>private: <BR> T * ptr;<BR>};</DIV>
<DIV>#endif<BR></DIV>
<DIV>------------------------------------------------------------------------</DIV>
<DIV>Now, have a look at the adapted Cone.cxx example :</DIV>
<DIV> </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> </DIV>
<DIV>#include "vtkClassPtr.h"<BR>typedef vtkClassPtr< vtkConeSource > vtkConeSourcePtr;<BR>typedef vtkClassPtr< vtkPolyDataMapper > vtkPolyDataMapperPtr;<BR>typedef vtkClassPtr< vtkActor > vtkActorPtr;<BR>typedef vtkClassPtr< vtkRenderer > vtkRendererPtr;<BR>typedef vtkClassPtr< vtkRenderWindow > vtkRenderWindowPtr;<BR>typedef vtkClassPtr< vtkRenderWindowInteractor > vtkRenderWindowInteractorPtr;<BR>typedef vtkClassPtr< vtkInteractorStyleTrackballCamera > vtkInteractorStyleTrackballCameraPtr;</DIV>
<DIV> </DIV>
<DIV>int main( int argc, char *argv[] )<BR>{<BR> vtkConeSourcePtr cone = vtkConeSource::New();<BR> {<BR> vtkConeSourcePtr cone2 = cone;<BR> cone2->SetHeight( 3.0 );<BR> cone2->SetRadius( 1.0 );<BR> cone2->SetResolution( 10 );<BR> }</DIV>
<DIV> vtkPolyDataMapperPtr coneMapper = vtkPolyDataMapper::New();<BR> coneMapper->SetInput( cone->GetOutput() );</DIV>
<DIV> vtkActorPtr coneActor = vtkActor::New();<BR> coneActor->SetMapper( coneMapper );</DIV>
<DIV> vtkRendererPtr ren1= vtkRenderer::New();<BR> ren1->AddActor( coneActor );<BR> ren1->SetBackground( 0.1, 0.2, 0.4 );</DIV>
<DIV> vtkRenderWindowPtr renWin = vtkRenderWindow::New();</DIV>
<DIV> renWin->AddRenderer( ren1 );<BR> renWin->SetSize( 300, 300 );</DIV>
<DIV> vtkRenderWindowInteractorPtr iren = vtkRenderWindowInteractor::New();<BR> iren->SetRenderWindow(renWin);</DIV>
<DIV> vtkInteractorStyleTrackballCameraPtr style = <BR> vtkInteractorStyleTrackballCamera::New();<BR> iren->SetInteractorStyle(style);</DIV>
<DIV> iren->Initialize();<BR> iren->Start(); <BR> return 0;<BR>}</DIV>
<DIV> </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>