[Insight-users] Inheriting ITK Image

Matt Kelsey mkelsey at gmail.com
Thu Dec 28 12:04:10 EST 2006


Hello,
I have another question about inheriting an ITK Image Type if you have
a moment.  I've created CustomImageClass as discussed below (
inheriting from Image<unsigned char, 2> and it seems to be operating
correctly.  I'm wondering how you would store an image in the
CustomImageClass object's allocated space.
I would like to be able to wirte:
customImageObject = reader->GetOutput();
without over writing my custom class members.
and later:
someFilter->SetInput(customImageObject);
meaning that the Image<unsigned char, 2> information should be passed
to someFilter.
The way I am doing this now is for the CustomImageClass to have a method:
     ImageType::Pointer GetOutput() { reader->GetOutput(); }
however this does not allow for setting properties such as resolution
to the image and does not really create an intermediate image.

My thoughts are for CustomImageClass to simply have a member
Image<unsigned char, 2> and access it through the CustomImageClass
methods.  I think this will work, but I suspect there is a better way
to accomplish this.  Perhaps I need to overload the method
reader->GetOutput() to produce what I need.  Any Ideas.

Thanks for you time,
Matt Kelsey

On 11/29/06, Iván Macía <imacia at vicomtech.es> wrote:
> 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