Thread: Template typedef and ITK

  1. #1
    Registered User
    Join Date
    Sep 2010

    Template typedef and ITK

    Hello there,

    I'm trying to create a class to hold some 3D volume data and I want to use the ITK library to do this. At the same time I want my class to contain some information that is particular to the data. As the data type may change, it would be nice to have some flexibility about it, and here lies my problem.
    With itk, one creates a new image type by spcifying the pixel type and the dimensionality of the data. In my case the first one is varible and the dimension is fixed at 3.
    Clasically, for a volume of data type double on would do something like:
    typedef itk::Image<double, 3> DoubleVolume;
    DoubleVolume::Pointer aVolume = DoubleVolume::New();
    Now, this is not enough for me so I created my own templated class and here was one classical caveat of the template typedef so I had to be careful about this.
    In a very much simplified implementation, this is what I need and I can't figure it out, what I am doing wrong:

    template<typename VoxelT = double>
    class OctVolume
        typedef itk::Image<VoxelT, 3> ItkVolume;
        ItkVolume::Pointer m_vol;
    In main:
    typedef OctVolume<double> DoubleOctVolume;    
    DoubleOctVolume::ItkVolume::Pointer DoubleVolume;
    Upon compilation I get the following:
    ../src/main.cpp:20: error: type ‘itk::Image<VoxelT, 3u>’ is not derived from type ‘OctVolume<VoxelT>’
    ../src/main.cpp:20: error: expected ‘;’ before ‘m_vol’
    Any idea about what the problem may be? I tried a yet more simplified version by partially specializing an own defined template and having it as a member of my class, and that worked very much ok.


  2. #2
    Registered User
    Join Date
    Nov 2008
    You need to disambiguate the declaration of m_vol using typename inside the OctVolume class because ItkVolume::Pointer is a template.

    I am using slightly different names that made sense to me when I tried your examples.

    #include <iostream>
    using namespace std;
    template<typename dataType, int dimension>
    struct Image
    	typedef dataType (*pointer)[dimension];
    template<typename dataType = int>
    struct VolumeImage
    	typedef Image<dataType, 3> Volume;
    	typename Volume::pointer vol_;
    	VolumeImage() : vol_(NULL) {}
    int main(int argc, char** argv)
    	typedef VolumeImage<int> IntVolume;
    	IntVolume x;
    	cout << "the pointer is " << x.vol_ << endl;
    	return 0;

Popular pages Recent additions subscribe to a feed
Website Security Test