[Insight-users] Design question when using ITK classes

Anja Ende anja.ende at googlemail.com
Wed Feb 20 09:55:06 EST 2008


Hi Hendrik,

Thanks for your reply. But the 'type' of data is defined only at runtime!

For example, if you have a Nifti file, the underlying type whether it is
char, short, float or what have you is only defined at run time!

So what I did is following:

template<typename DataType, unsigned int dimensions=3>
class MyReader
{
    typedef itk::ImportImageFilter<DataType, dimensions> ImportFilterType;
    // This class uses the itk::ImportImageFilter
    private:
         typename ImportFilterType::Pointer              m_importer; ///<
The ITK data importer
};

And I can have a factory object that creates the instance with the correct
template arguments....

However, how can I return such a dynamic object from the class factory and
how can I store this created object in another class member variable?

Thanks,
Anja


On 20/02/2008, Hendrik Belitz <hbelitz at darkon.info> wrote:
>
> Hi Anja,
>
> However, with this scheme you are unable to have <i>class member
> variables</i> that are of templated type. Say for example, I need to read
> data from a file inside a class method. So, I find the underlying data type
> and dimensions and read the data. However, if I want to access this data
> later or basically store it in the class, how can I do that?
>
> You do not need templated class members since you can just hold a pointer
> to the data in a (less or even non-templated) base class like itk::ImageBase
> (which is not templated by data type). If you also
> need independence of dimension, use itk::DataObject instead. Of course
> this means that you have to downcast it using dynamic_cast<> again later.
>
> Hope this helps,
>  Hendrik
>
> -------------------------------------------------------------------
> Brilliance is typically the act of an individual, but incredible
> stupidity can usually be traced to an organization. - Jon Bentley
>
> Hendrik Belitz, Computer Scientist
> email: hbelitz at computer.org or hbelitz at ieee.org
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>


-- 
Cheers,

Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080220/cc80ac27/attachment.html


More information about the Insight-users mailing list