[Insight-developers] an itkImage "Hello world"

Miller, James V (CRD) millerjv@crd.ge.com
Fri, 13 Apr 2001 15:21:11 -0400


Here is a slightly editted version.  A couple of lines can be removed, though we do need to add one
other line.

int main()
{
 typedef itk::BloxImage<itk::BloxPixel,3> Blox3D;

 Blox3D::Pointer image = Blox3D::New();

 Blox3D::SizeType size = {{10, 10, 10}};

 Blox3D::RegionType largestPossibleRegion;
 largestPossibleRegion.SetSize( size );

 image->SetLargestPossibleRegion( largestPossibleRegion );
 image->SetBufferedRegion( largestPossibleRegion );

 image->Allocate();

 return 1;
}


Let me give some insight :) into the code and see if anyone has suggestions to get around the
problems we faced designing this.

It would be nice, if at constructor time you could specify the size of the image as a width, height
depth construct.  So the call to the New() method could be something like:

Blox3D::Pointer image = Blox3D::New(10, 10, 10);

which would automatically setup the region ivars and allocate the memory.  The existing API can
remain as a means to resize an image.

The problem is: how do we write the constructor for itk::BloxImage<T, N>? 

1) The constructor (and New() method) could take 12 unsigned ints which all have default values of 0
and we hope that someone nevers tries to instantiate a 13 dimensional image.

2) We use ellipsis notation (don't even know if that still exists and whether it can be used on a
constructor).

3) We provide 12 different subclasses of BloxImage, each specifying a different dimension parameter
to the superclass and each having a constructor that takes in the appropriate number of parameters.

4) The constructor and New() method take a Size at its argument, allowing the use of code like

Blox3D::Pointer image = Blox3D::New( Blox3D::SizeType(10, 10, 10) );

Given that one of these options (or perhaps one I did not think of) is more appealing than the
complexity we currently have, should be provide a simple means of constructing an image specifying
the StartIndex and the Size? i.e.

Blox3D::Pointer image = Blox3D::New( Blox3D::IndexType(1, 1, 1), Blox3D::SizeType(10, 10, 10) );

Option #4 essentially moves the problem of writing the constructor for the image class down to the
index and size classes since these templated classes must have the burden of having a constructor
with a variable length parameter list. So options 1-3 could be used in Index, Size, and Offset.

I'll have to defer to Brad as to whether you could write code like

Blox3D::Pointer image = Blox3D::New( {1, 1, 1}, {10, 10, 10});

Would (should) the compiler be able to take what is inbetween the {}'s and call the constructors for
Index and Size directly?

The API could be simplified further if we add constructors to Region's that take combinations of and
Index and Size, or just a Size, etc.

These changes will eliminate some of the code and hence complexity.  We'll still have to address the
complexity of the traits, etc.


-----Original Message-----
From: Damion Shelton [mailto:dmsst59+@pitt.edu]
Sent: Friday, April 13, 2001 1:25 PM
To: 'insight-Developers'
Subject: [Insight-developers] an itkImage "Hello world"


Hi all...

As requested here's the code for the "hello world" equivalent that I use to
test out our BloxImage class:

int main()
{
 unsigned long imagesize[]  = {10,10,10};
 unsigned long spacing[] = {1,1,1};

 typedef itk::BloxImage<itk::BloxPixel,3> Blox3D;

 Blox3D::Pointer image = itk::BloxImage<itk::BloxPixel,3>::New();

 Blox3D::SizeType size = {{0}};
 size.SetSize( imagesize );

 Blox3D::RegionType largestPossibleRegion;
 largestPossibleRegion.SetSize( size );

 image->SetLargestPossibleRegion( largestPossibleRegion );

 image->Allocate();

 return 1;
}

It would be *really* handy to have a simpler way of handling creation of
images. Keep in mind that the above code doesn't set index or pixel spacing,
so a full instantiation of the image class would require another 5-10 lines
of code.

Others have expressed concern that requiring this quantity of code for what
should be the simplest (or one of the simplest) operations in ITK can be
frustrating to new users. Any thoughts....?

-Damion-



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