[Insight-developers] Index<0> size problem comming from ImageDimension
Luis Ibanez
luis.ibanez@kitware.com
Fri, 22 Feb 2002 15:16:31 -0500
Hi,
Brad found a solution to the Index<0> problem that
appeared today on the dashboard.
It is a specific VC++ problem.
Here is the minimal case:
-----------------------------------------------------------------------
template < typename TImageType >
class BloxImage : public Image < BloxPixelType<
TImageType::ImageDimension >,
TImageType::ImageDimension >
{
};
------------------------------------------------------------------------
For some reason VC++ is not able to get the integer value from the
template parameter and sticks a (0) in its place. Or maybe it is actually
getting the value from the template parameter but it is doing so before
the enums in the actual TImageType have been initialized.
The workaround is to introduce a helper small class :
--------------------------------------------------------------------------
template < typename TImageType, unsigned int V = TImageType::ImageDimension>
struct ExtractImageDimension
{
enum { ImageDimension = V };
};
----------------------------------------------------------------------------
By using TImageType::ImageDimension as *default* value of the integer
template
parameter V, this class forces the enum ImageDimension of the TImageType
template
parameter to be effectively initialized and passed to the new
ImageDimension enum.
This class is the used in the previous BloxImage declaration as
-----------------------------------------------------------------------
template < typename TImageType >
class BloxImage :
public Image < BloxPixelType<
ExtractImageDimension<TImageType>::ImageDimension >,
ExtractImageDimension<TImageType>::ImageDimension >
{
};
------------------------------------------------------------------------
The helper class ExtractImageDimension was added at the end of
itkImageBase.h
==========================================
For Supersticious people....
Browsing on the mailing list archives we found that this problem was
found by the
first time by Lydia on Oct 26 2000 when trying to create a ProcessObject
that used
the ImageDimension for instantiating a temporary image. She found a
similar solution
by adding an extra integer parameter to the process class and passing
the ImageDimension
as default value for it.
The problem appeared a secon time in Feb 2001. Jim used a similar approach
to solve it, this time by using a small Traits class and checked in Feb
21 2001
which makes it exactly a year ago.
So why don't we call "Feb 21" the "VC++ Hacking" day ?
We could start a tradition and celebrate this day by installing Linux in as
many machines as we can :-)
Luis