[Insight-users] Functions vs classes

Luis Ibanez luis.ibanez at kitware.com
Tue, 23 Dec 2003 14:52:33 -0500


Hi Radhika,

Please look at the Tutorial session

http://www . itk . org/CourseWare/Training/GettingStarted-V . pdf

It describes the issues related to integrating ITK
into non-ITK-ified code.

In particular the problem of passing image buffers
in and out of ITK.

----

Here is the rule you may want to use as guidance:

1) If your function creates a new image, and fills
    its content, then you should return this image
    as a SmartPointer.

2) If you function receives an existing image and
    stores output data on it. Then you can simply
    receive the image as a raw pointer.

----


If you convert this to a class, you may want to
follow the examples of ITK calculators.

for example:
http://www . itk . org/Insight/Doxygen/html/classitk_1_1ImageMomentsCalculator . html



Regards,


    Luis



----------------------------------
Radhika Sivaramakrishna wrote:

> Hi Luis,
> I agree with you that going with classes is a better way and I will 
> ultimately do that as I get deeper and deeper into this.
> I have another question regarding functions and the Execute() function 
> in a class.
> In my previous example, if I had wanted to return an image pointer of 
> the same type as one of the inputs, is there a way to do it? The only 
> way I can think of is to pass a imagetype pointer (with space allocated) 
> to the function and copying the result into it in my function. Is there 
> a better way to do this?
> Even if I were to write it using classes, and I want my Execute() method 
> to finally produce an image type, how do I return this?
> How is this done with GetOutput() member functions for the various filters?
> Thanks
> Radhika
>