[Insight-developers] SmartPointer and Get/Set Input/Output

Miller, James V (CRD) millerjv at crd.ge.com
Wed Sep 6 09:35:40 EDT 2000


I think that images should be passed by smart pointers.  I think (Bill Hoffman can correct me here)
that the smart pointers should be passed by value.  I think when smart pointers are passed by value
all the reference counting is handled automatically as the smart pointers go into and out of scope.

I think the SetInput method should take a smartpointer and GetOutput should return a smartpointer. I
think line 5 will be

5  myImageType::Pointer theOutput = theFilter.GetOutput();

which should copy the smart pointer and up the reference count automatically.

I think the way to think about smart pointers is that they provide "stack based" handles to "heap"
allocated memory.

I'll look into making these changes.



-----Original Message-----
From: Luis Ibanez [mailto:ibanez at cs.unc.edu]
Sent: Wednesday, September 06, 2000 9:31 AM
To: insight-developers at public.kitware.com
Subject: [Insight-developers] SmartPointer and Get/Set Input/Output



Hi,

I'm still confused about the use of  Normal vs Smart pointers.

This time with the methods SetInput() , and GetOutput() for
the filters.

Currently they are defined like

TImageOutput   *   GetOutput();


Shouldn't  they be:              TImageOutput::Pointer
GetOutput();   ?
or maybe:                   const TImageOutput::Pointer & GetOutput();
?

------

And the SetInput() method it is currently:

void SetInput(  TImageInput * );

shouldn't it be:    void SetInput(             TImageInput::Pointer
);   ?
or maybe :            void SetInput(  const TImageInput::Pointer &  );
?

--------------------------

With the current code, in order to connect
images to filters we have to do :

1  typedef   itk::Image< double, 3 >   myImageType;
2  myImageType::Pointer  theImage = myImgeType::New();
3  myFilterType  theFilter = myFilterType::New();
4  theFilter.SetInput (   theImage.GetPointer()  );
5  myImageType::Pointer theOutput = theFilter.GetOutput();

----------------------------

Passing SmartPointers, lines 4 and 5 become:

4  theFilter.SetInput (   theImage  );
5  myImageType::Pointer theOutput = theFilter.GetOutput().GetPointer();

------------------------------

The points are:

1) Do we want to pass images to filters as normal pointers or as
smartpointers ?
2) If we want SmartPointers, should they be passed by copy or by
reference ?



Thanks


Luis




_______________________________________________
Insight-developers mailing list
Insight-developers at public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers




More information about the Insight-developers mailing list