[Insight-developers] Container of heterogeneous images

Dan Mueller dan.muel at gmail.com
Mon Jan 9 21:08:56 EST 2012


Hi David,

Have you seen the pimpl idiom used in SimpleITK? It might be helpful...

http://en.wikipedia.org/wiki/Pimpl
http://itk.org/gitweb?p=SimpleITK.git;a=blob;f=Code/Common/include/sitkImage.h;h=82a1bf1665c8261a56427d0a3f832ccd004a604b;hb=HEAD
http://itk.org/gitweb?p=SimpleITK.git;a=blob;f=Code/Common/src/sitkImage.cxx;h=f495ea19f533bdfd6b5f3b90318902deeeb2d5cf;hb=HEAD
http://itk.org/gitweb?p=SimpleITK.git;a=blob;f=Code/Common/src/sitkPimpleImageBase.h;h=1d93c9c57f19c2b55d4d1e3635abc75f9917ca79;hb=HEAD
http://itk.org/gitweb?p=SimpleITK.git;a=blob;f=Code/Common/src/sitkPimpleImageBase.hxx;h=31b8c6d4cdd9457a66030588d71674c36aebc45d;hb=HEAD

HTH

Cheers, Dan

On 10 January 2012 12:10, David Doria <daviddoria at gmail.com> wrote:
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list