[Insight-users] Problem with ImageDimension and typedef

Karthik Krishnan Karthik.Krishnan at kitware.com
Sat Oct 1 17:48:36 EDT 2005


On Sat, 2005-10-01 at 10:58 +0200, Bryn wrote:
> > I cannot reproduce your problem without seeing a minimal example of  
> > your code...
> >
> I am posting a some code as attachment, to show the problem...
> 
> > The pixeltype for the VectorImage, if you write code, should be 
> > obtained from the Image class.. This is the reason for generic 
> > programming. But if you find it convenient, I can easily add 
> > overloaded  = operators in itk::VariableLengthVector and itk::Array, 
> > which is probably a good thing anyway, since they should be assignable 
> > from each other...
> >
> That would be nice.
> 
> > I still do not understand what compiles in gcc34 and not in gcc33. If 
> > any, I've seen things go the other way......
> >
> It seems that, if I define a templated class which holds a specific type 
> of Image or VectorImage, say VectorImage<int,3>.
> I then typedef  the PixelType from the VectorImage, and finally add a 
> function with this PixelType as argument type, gcc-3.3 compiles ok.
> 
> so say I have something like this (inside the class):
> 
> typedef VectorImage<int,3>    VectorImageType;
> typedef VectorImageType::PixelType PType;
> 
> PType method( PType );
> 
> gcc-3.3 compiles ok.
> 
> 
> But if I change this VectorImage typedef to:
> 
> typedef VectorImage<int,ImageDimension>    VectorImageType;

Change this line to 

typedef VectorImage< int, itkGetStaticConstMacro(ImageDimension) >
VectorImageType;

and you should be good with both compilers.

-karthik

PS:
In gcc33 and below, to reference an inclass static const member, you
need to use Self as a trait to get it as in 
typedef VectorImage< int, Self::ImageDimension > VectorImageType;

This would work on all compilers except that VS doesn't support it. 
In VS you would need 
typedef VectorImage< int, ImageDimension > VectorImageType;

Hence a macro to do the job for you... 


>         where the ImageDimension is defined by:
>  
>         itkStaticConstMacro(ImageDimension, unsigned int,
>                               TInputImage::ImageDimension);
> 
> 
> 
> gcc-3.3 complains. gcc-3.4 compiles both versions just fine.
> 
> 
> 
> Maybe something I am doing is wrong. It seems it has to do with the way 
> I get the ImageDimension.
> 
> It would be nice to know why the second version doesn't compile with gcc-3.3
> 
> 
> 
> Thanks
> 
> Bryn
> 
> 
> 
> > -karthik
> >
> >>
> >>
> >> Thanks
> >> Bryn
> >>
> >>
> >> _______________________________________________
> >> Insight-users mailing list
> >> Insight-users at itk.org
> >> http://www.itk.org/mailman/listinfo/insight-users
> >>
> 
> plain text document attachment (itkVectorImageAndTypedefTest.txx)
> ///author: Bryn Lloyd
> 
> #ifndef _itkVectorImageAndTypedefTest_txx
> #define _itkVectorImageAndTypedefTest_txx
> 
> 
> 
> 
> 
> namespace itk
> {
> 
> 
> /**
>  *    Constructor
>  */
> template <class TInputImage,class TOutputImage>
> VectorImageAndTypedefTest<TInputImage,TOutputImage>
> ::VectorImageAndTypedefTest()
> {
> 
> }
> 
> 
> 
> /**
>  * Sort an int Array
>  */
> template <class TInputImage,class TOutputImage>
> typename VectorImageAndTypedefTest<TInputImage,TOutputImage>::TestPixelType
> VectorImageAndTypedefTest<TInputImage,TOutputImage>
> ::DoSomething(const TestPixelType& indices)
> {
>   TestPixelType test(3);
>   return test;
> }
> 
> 
> /**
>  * Sort an int Array
>  */
> template <class TInputImage,class TOutputImage>
> void
> VectorImageAndTypedefTest<TInputImage,TOutputImage>
> ::GenerateData()
> {
> }
> 
> 
> 
> 
> 
> /**
>  *  Print Self
>  */
> template <class TInputImage,class TOutputImage>
> void 
> VectorImageAndTypedefTest<TInputImage,TOutputImage>
> ::PrintSelf(std::ostream& os, Indent indent) const
> {
>   Superclass::PrintSelf(os,indent);
> }
> 
> 
> 
> } // end namespace itk
> 
> #endif
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list