1 #include "clitkImageToImageGenericFilterBase.h"
4 //--------------------------------------------------------------------
5 clitk::ImageToImageGenericFilterBase::~ImageToImageGenericFilterBase() {}
6 //--------------------------------------------------------------------
9 //--------------------------------------------------------------------
10 clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string n)
13 mFailOnImageTypeError = true;
16 //--------------------------------------------------------------------
19 //--------------------------------------------------------------------
20 void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & filenames) {
21 mInputFilenames=filenames;
23 //--------------------------------------------------------------------
26 //--------------------------------------------------------------------
27 void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b) {
30 //--------------------------------------------------------------------
33 //--------------------------------------------------------------------
34 void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename) {
35 std::vector<std::string> f;
36 f.push_back(filename);
39 //--------------------------------------------------------------------
42 //--------------------------------------------------------------------
43 void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename) {
44 mInputFilenames.push_back(filename);
46 //--------------------------------------------------------------------
49 //--------------------------------------------------------------------
50 void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & filename) {
51 mOutputFilenames.clear();
52 mOutputFilenames.push_back(filename);
54 //--------------------------------------------------------------------
57 //--------------------------------------------------------------------
58 void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & filename)
60 mOutputFilenames.push_back(filename);
62 //--------------------------------------------------------------------
65 //--------------------------------------------------------------------
66 void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector<std::string> & filenames)
68 mOutputFilenames.clear();
69 std::copy(filenames.begin(),filenames.end(),mOutputFilenames.begin());
71 //--------------------------------------------------------------------
74 //--------------------------------------------------------------------
75 std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename()
77 assert(mOutputFilenames.size() == 1);
78 return mOutputFilenames.front();
80 //--------------------------------------------------------------------
83 //--------------------------------------------------------------------
84 void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(unsigned int& dim, \
85 std::string& pixeltype,unsigned int& components)
87 if (mReadOnDisk && mInputFilenames.size()) {
88 int comp_temp,dim_temp; //clitkCommonImage takes ints
89 ReadImageDimensionAndPixelType(mInputFilenames[0], dim_temp, pixeltype,comp_temp);
90 components=comp_temp; dim=dim_temp;
93 if (mInputVVImages.size()) {
94 pixeltype=mInputVVImages[0]->GetScalarTypeAsString();
95 dim=mInputVVImages[0]->GetNumberOfDimensions();
96 components=mInputVVImages[0]->GetNumberOfScalarComponents();
99 assert(false); //No input image, shouldn't happen
102 std::cout << "Input is " << mDim << "D " << mPixelTypeName << "." << std::endl;
105 //--------------------------------------------------------------------
108 //--------------------------------------------------------------------
109 vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage ()
111 assert(mOutputVVImages.size());
112 return mOutputVVImages[0];
114 //--------------------------------------------------------------------
117 //--------------------------------------------------------------------
118 std::vector<vvImage::Pointer> clitk::ImageToImageGenericFilterBase::GetOutputVVImages()
120 return mOutputVVImages;
122 //--------------------------------------------------------------------
125 //--------------------------------------------------------------------
126 void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer input)
128 mInputVVImages.clear();
129 mInputVVImages.push_back(input);
131 //--------------------------------------------------------------------
134 //--------------------------------------------------------------------
135 void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer input)
137 mInputVVImages.push_back(input);
139 //--------------------------------------------------------------------
142 //--------------------------------------------------------------------
143 void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage::Pointer> input)
145 mInputVVImages=input;
147 //--------------------------------------------------------------------
150 //--------------------------------------------------------------------
151 void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes() {
152 std::cout << GetAvailableImageTypes();
154 //--------------------------------------------------------------------
158 //--------------------------------------------------------------------
159 void clitk::ImageToImageGenericFilterBase::ImageTypeError() {
160 std::cerr << "**Error** The filter <" << mFilterName << "> is not available for "
161 << mDim << "D images with pixel="
162 << mPixelTypeName << " and "
163 << mNbOfComponents << " component." << std::endl;
164 std::cerr << GetAvailableImageTypes();
167 //--------------------------------------------------------------------
170 //--------------------------------------------------------------------
171 void clitk::ImageToImageGenericFilterBase::SetImageTypeError() {
172 std::cerr << "TODO ! " << std::endl;
175 //--------------------------------------------------------------------
178 //--------------------------------------------------------------------
179 const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName() {
182 //--------------------------------------------------------------------
185 //--------------------------------------------------------------------
186 void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n) {
189 //--------------------------------------------------------------------
192 //--------------------------------------------------------------------
193 void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b) {
196 //--------------------------------------------------------------------
198 #define DEF_SetNextOutput_And_GetInput(PixelType, Dim) \
200 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<PixelType, Dim> >(itk::Image<PixelType,Dim>::Pointer output); \
202 itk::Image<PixelType, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<PixelType, Dim> >(unsigned int n);
204 #define DEF_SetNextOutput_And_GetInput_WithCompo(Compo, Dim) \
206 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<itk::Vector<float, Compo>, Dim> >(itk::Image<itk::Vector<float, Compo>,Dim>::Pointer output); \
208 itk::Image<itk::Vector<float,Compo>, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<itk::Vector<float, Compo>, Dim> >(unsigned int n);
210 DEF_SetNextOutput_And_GetInput(char, 2);
211 DEF_SetNextOutput_And_GetInput(unsigned char, 2);
212 DEF_SetNextOutput_And_GetInput(short, 2);
213 DEF_SetNextOutput_And_GetInput(unsigned short, 2);
214 DEF_SetNextOutput_And_GetInput(int, 2);
215 DEF_SetNextOutput_And_GetInput(float, 2);
216 DEF_SetNextOutput_And_GetInput(double, 2);
218 DEF_SetNextOutput_And_GetInput(char, 3);
219 DEF_SetNextOutput_And_GetInput(unsigned char, 3);
220 DEF_SetNextOutput_And_GetInput(short, 3);
221 DEF_SetNextOutput_And_GetInput(unsigned short, 3);
222 DEF_SetNextOutput_And_GetInput(int, 3);
223 DEF_SetNextOutput_And_GetInput(float, 3);
224 DEF_SetNextOutput_And_GetInput(double, 3);
226 DEF_SetNextOutput_And_GetInput_WithCompo(2, 2);
227 DEF_SetNextOutput_And_GetInput_WithCompo(2, 3);
228 DEF_SetNextOutput_And_GetInput_WithCompo(2, 4);
229 DEF_SetNextOutput_And_GetInput_WithCompo(3, 2);
230 DEF_SetNextOutput_And_GetInput_WithCompo(3, 3);
231 DEF_SetNextOutput_And_GetInput_WithCompo(3, 4);
232 DEF_SetNextOutput_And_GetInput_WithCompo(4, 2);
233 DEF_SetNextOutput_And_GetInput_WithCompo(4, 3);
234 DEF_SetNextOutput_And_GetInput_WithCompo(4, 4);
236 DEF_SetNextOutput_And_GetInput(char, 4);
237 DEF_SetNextOutput_And_GetInput(unsigned char, 4);
238 DEF_SetNextOutput_And_GetInput(short, 4);
239 DEF_SetNextOutput_And_GetInput(unsigned short, 4);
240 DEF_SetNextOutput_And_GetInput(int, 4);
241 DEF_SetNextOutput_And_GetInput(float, 4);
242 DEF_SetNextOutput_And_GetInput(double, 4);
245 //--------------------------------------------------------------------
246 template<class ImageType>
247 void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output) {
248 if (mOutputFilenames.size())
250 clitk::writeImage<ImageType>(output, mOutputFilenames.front(), mIOVerbose);
251 mOutputFilenames.pop_front();
253 if (mInputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
254 mOutputVVImages.push_back(vvImageFromITK<ImageType::ImageDimension,typename ImageType::PixelType>(output));
256 //--------------------------------------------------------------------
259 //--------------------------------------------------------------------
260 template<class ImageType>
261 typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n) {
262 if (mReadOnDisk && mInputFilenames.size() > n) {
263 return clitk::readImage<ImageType>(mInputFilenames[n], mIOVerbose);
266 if (mInputVVImages.size() > n)
267 return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(mInputVVImages[n]).GetPointer()));
270 assert(false); //No input, this shouldn't happen
271 return typename ImageType::Pointer(NULL);
275 //--------------------------------------------------------------------