1 #ifndef CLITKIMAGETOIMAGEGENERICFILTER_H
2 #define CLITKIMAGETOIMAGEGENERICFILTER_H
5 ===================================================================
6 * @file clitkImageToImageGenericFilter.h
7 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
8 * @date 05 May 2008 14:40:51
12 ===================================================================*/
15 #include "clitkCommon.h"
16 #include "clitkImageCommon.h"
20 #include <vvFromITK.h>
26 class ImageToImageGenericFilter: public itk::Object {
29 // constructor - destructor
30 ImageToImageGenericFilter();
33 typedef ImageToImageGenericFilter Self;
34 typedef Object Superclass;
35 typedef itk::SmartPointer<Self> Pointer;
36 typedef itk::SmartPointer<const Self> ConstPointer;
39 /// Returns the dimension and pixel type of the *first* input
40 void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,unsigned int & components);
43 void SetInputFilename(const std::string & filename);
44 void AddInputFilename(const std::string & filename);
45 void SetInputFilenames(const std::vector<std::string> & filenames);
46 void SetOutputFilename(const std::string & filename);
47 void AddOutputFilename(const std::string & filename);
48 void SetOutputFilenames(const std::vector<std::string> & filenames);
49 std::string GetOutputFilename();
50 void SetIOVerbose(bool b) { mIOVerbose = b; }
53 void SetInputVVImage (vvImage::Pointer input);
54 void SetInputVVImages (std::vector<vvImage::Pointer> input);
55 void AddInputVVImage (vvImage::Pointer input);
56 vvImage::Pointer GetOutputVVImage ();
57 std::vector<vvImage::Pointer> GetOutputVVImages ();
59 /// Main function to implement
60 virtual void Update() = 0;
63 /// Call this function to dispatch an output towards the correct sink
64 template<class ImageType>
65 void SetNextOutput(typename ImageType::Pointer output);
66 /// Call this function to get the nth itk input image, regardless of input source
67 template<class ImageType>
68 typename ImageType::Pointer GetInput(unsigned int n);
70 std::vector<std::string> mInputFilenames;
71 std::list<std::string> mOutputFilenames;
75 std::string mPixelTypeName;
76 unsigned int mNbOfComponents;
78 std::vector<vvImage::Pointer> mInputVVImages;
79 std::vector<vvImage::Pointer> mOutputVVImages;
81 }; // end class clitk::ImageToImageGenericFilter
85 template<class ImageType>
86 void clitk::ImageToImageGenericFilter::SetNextOutput(typename ImageType::Pointer output)
88 if (mOutputFilenames.size())
90 clitk::writeImage<ImageType>(output, mOutputFilenames.front(), mIOVerbose);
91 mOutputFilenames.pop_front();
93 if (mInputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
94 mOutputVVImages.push_back(vvImageFromITK<ImageType::ImageDimension,typename ImageType::PixelType>(output));
96 template<class ImageType>
97 typename ImageType::Pointer clitk::ImageToImageGenericFilter::GetInput(unsigned int n)
99 if (mInputFilenames.size() > n)
100 return clitk::readImage<ImageType>(mInputFilenames[n], mIOVerbose);
101 else if (mInputVVImages.size() > n)
102 return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(mInputVVImages[n]).GetPointer()));
104 assert(false); //No input, this shouldn't happen
106 #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTER_H */