Thread: Template typedef and ITK

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    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:
    Code:
    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:

    Code:
    template<typename VoxelT = double>
    class OctVolume
    {
    public:
        typedef itk::Image<VoxelT, 3> ItkVolume;
        ItkVolume::Pointer m_vol;
    };
    In main:
    Code:
    typedef OctVolume<double> DoubleOctVolume;    
    DoubleOctVolume::ItkVolume::Pointer DoubleVolume;
    Upon compilation I get the following:
    Code:
    ../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.

    Thanks,
    Tibi

  2. #2
    Registered User
    Join Date
    Nov 2008
    Posts
    30
    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.

    Code:
    #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::Volume::
    	IntVolume x;
    	cout << "the pointer is " << x.vol_ << endl;
    	return 0;
    }

Popular pages Recent additions subscribe to a feed