[Insight-users] Inheriting ITK Image

Iván Macía imacia at vicomtech.es
Wed Nov 29 03:47:18 EST 2006


Hi Matt, 

In order to inherit a class from itk and behave as expected you need to
follow certain conventions (see also chapter How to Write a Filter -> Filter
Conventions in the ITK Software Guide)

In your case try something like this

#include "itkImage.h"

namespace itk
{

class CustomImageClass : public Image< unsigned char, 2,>
{

public:

  typedef CustomImageClass            Self;
  typedef Image<unsigned char,2>      Superclass;
  typedef SmartPointer<Self>          Pointer;
  typedef SmartPointer<const Self>    ConstPointer; 

public:

  itkNewMacro(Self); // smart pointer support for object creation 
  itkTypeMacro(CustomImageClass, Image); // methods for RTTI

  void NewFunction();

  ... // some more methods 

private:

  CustomImageClass(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

protected:

  ... // some attributes


};

}

You can follow the scheme above (and I definitely recommend it) with most of
the classes that inherit from itk::Object.

In your case, I would still keep the template parameters and set unsigned
char and 2 as default parameters, something like

template <class TPixel, unsigned char VImageDimension>
class CustomImageClass : public Image< TPixel = unsigned char,
VImageDimension = 2>
{
	...
};

Now you can do something like you were trying

CustomImageClass::Pointer image = CustomImageClass::New();
image->NewFunction();  // works :)


Hope that helps

Iván


-----Mensaje original-----
De: insight-users-bounces+imacia=vicomtech.es at itk.org
[mailto:insight-users-bounces+imacia=vicomtech.es at itk.org] En nombre de Matt
Kelsey
Enviado el: miércoles, 29 de noviembre de 2006 3:51
Para: insight-users at itk.org
Asunto: [Insight-users] Inheriting ITK Image

Hello,
I am trying to inherit a fully specified ITK image and add my own
functionality.  Test code below:

>>>>>>>>>>>>>>>

#include "itkImage.h"

typedef unsigned char  PixelType;
const   unsigned int Dimension = 2;
typedef itk::Image< PixelType, Dimension >  ImageType;

class CustomImageClass : public ImageType
{
   public:
      void NewFunction() {};
};

int main()
{
   CustomImageClass::Pointer image = CustomImageClass::New();
   image->NewFunction();  // doesn't work
}

>>>>>>>>>>>>>>>
This results in not having access to NewFunction().  I'm guessing this
is because the Pointer is from ImageType and not CustomImageType.  Is
there a way to do this while keeping the functionality of the smart
pointer.

Thanks for the help,
Matt
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.14.19/555 - Release Date: 27/11/2006
18:09
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.14.19/556 - Release Date: 28/11/2006
15:22
 



More information about the Insight-users mailing list