[Insight-developers] Container of heterogeneous images
David Doria
daviddoria at gmail.com
Mon Jan 9 20:40:58 EST 2012
I would like to store several images of different types in a vector.
Something like this:
#include "itkImage.h"
template <typename TImage>
void MyFunction(TImage* image) // A function that needs access to the
itk::Image interface
{
itk::Index<2> index;
index.Fill(0);
cout << image->GetPixel(index);
}
int main(int, char *[])
{
std::vector<itk::ImageBase<2>*> images;
itk::ImageBase<2>* image1 = itk::Image<float, 2>::New();
images.push_back(image1);
itk::ImageBase<2>* image2 = itk::Image<int,2>::New();
images.push_back(image2);
MyFunction(images[0]); // no member named GetPixel
return EXIT_SUCCESS;
}
Of course the above doesn't work because MyFunction gets instantated
with TImage = itk::ImageBase<2>, so none of the itk::Image functions
are available through that pointer. One solution is to modify
itk::ImageBase to have pure virtual functions declarations and then
subclass itk::Image to implement them. The result would be this:
itk::ImageBase<2>* image1 = itk::Image<float, 2>::New().GetPointer();
image1->MyNewFunction();
However, this would be extremely annoying for users, as then the code
would rely on a custom ITK version.
Is there an easier way to do this?
Thanks,
David
More information about the Insight-developers
mailing list