-#ifndef CLITKIMAGETOIMAGEGENERICFILTER_H
-#define CLITKIMAGETOIMAGEGENERICFILTER_H
+/*=========================================================================
+
+ Program: clitk
+ Module: $RCSfile: clitkImageToImageGenericFilter.h,v $
+ Language: C++
+ Date: $Date: 2010/01/29 07:27:31 $
+ Version: $Revision: 1.2 $
+ Author : Joel Schaerer <joel.schaerer@creatis.insa-lyon.fr>
+ David Sarrut <david.sarrut@creatis.insa-lyon.fr>
+
+ Copyright (C) 2008
+ Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ CREATIS-LRMN http://www.creatis.insa-lyon.fr
-/**
- ===================================================================
- * @file clitkImageToImageGenericFilter.h
- * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
- * @date 05 May 2008 14:40:51
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 3 of the License.
- * @brief
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- ===================================================================*/
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ =========================================================================*/
+
+#ifndef CLITKIMAGETOIMAGEGENERICFILTER_H
+#define CLITKIMAGETOIMAGEGENERICFILTER_H
// clitk include
#include "clitkCommon.h"
#include "clitkImageCommon.h"
+#include "clitkCommonGenericFilter.h"
#include <itkImage.h>
+// vv include
#include <vvImage.h>
#include <vvFromITK.h>
#include <vvToITK.h>
namespace clitk {
- class ImageToImageGenericFilter: public itk::Object {
+ //--------------------------------------------------------------------
+ class ImageToImageGenericFilterBase: public itk::Object {
public:
// constructor - destructor
- ImageToImageGenericFilter();
+ ImageToImageGenericFilterBase(std::string filterName);
+ virtual ~ImageToImageGenericFilterBase() {}
// Types
- typedef ImageToImageGenericFilter Self;
+ typedef ImageToImageGenericFilterBase Self;
typedef Object Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
+ // Filters information
+ const std::string & GetFilterName() { return mFilterName; }
+ void SetFilterName(std::string & n) { mFilterName = n; }
+
// Generic IO
/// Returns the dimension and pixel type of the *first* input
void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,unsigned int & components);
vvImage::Pointer GetOutputVVImage ();
std::vector<vvImage::Pointer> GetOutputVVImages ();
- /// Main function to implement
- virtual void Update() = 0;
-
- protected:
+ // Information on available image types
+ void PrintAvailableImageTypes();
+ bool CheckDimension(unsigned int d);
+ bool CheckPixelType(std::string pt);
+
+ // Main function to call for using the filter.
+ virtual bool Update() = 0;
+
+ // Use internally only (TO PUT PROTECTED !!!)
+ void AddImageType(unsigned int d, std::string p);
+
+ protected:
/// Call this function to dispatch an output towards the correct sink
template<class ImageType>
- void SetNextOutput(typename ImageType::Pointer output);
+ void SetNextOutput(typename ImageType::Pointer output);
+
/// Call this function to get the nth itk input image, regardless of input source
template<class ImageType>
- typename ImageType::Pointer GetInput(unsigned int n);
+ typename ImageType::Pointer GetInput(unsigned int n);
std::vector<std::string> mInputFilenames;
std::list<std::string> mOutputFilenames;
unsigned int mDim;
std::string mPixelTypeName;
unsigned int mNbOfComponents;
+ std::string mFilterName;
std::vector<vvImage::Pointer> mInputVVImages;
std::vector<vvImage::Pointer> mOutputVVImages;
+ std::vector<std::string> mListOfAllowedPixelType;
+ std::vector<unsigned int> mListOfAllowedDimension;
+ bool CheckImageType();
+ bool CheckDimension();
+ bool CheckPixelType();
+ void ImageTypeError();
+ void SetImageTypeError();
+ bool mFailOnImageTypeError;
+
}; // end class clitk::ImageToImageGenericFilter
+
+ //--------------------------------------------------------------------
+ template<class FilterType>
+ class ImageToImageGenericFilter: public ImageToImageGenericFilterBase {
+
+ public:
+
+ typedef ImageToImageGenericFilter<FilterType> Self;
+
+ // constructor - destructor
+ ImageToImageGenericFilter(std::string filterName);
+ virtual ~ImageToImageGenericFilter() { delete mImageTypesManager; }
+
+ // Main function to call for using the filter.
+ virtual bool Update();
+
+ protected:
+ // Object that will manage the list of templatized function for
+ // each image type.
+ ImageTypesManager<FilterType> * mImageTypesManager;
+
+ }; // end class clitk::ImageToImageGenericFilter
+
+ // #define ADD_IMAGE_DIMENSION(DIM) Initialize<DIM>();
+
+#define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager->template AddNewDimensionAndPixelType<DIM, PT>();
+
+
+#include "clitkImageToImageGenericFilter.txx"
+
} // end namespace
-template<class ImageType>
-void clitk::ImageToImageGenericFilter::SetNextOutput(typename ImageType::Pointer output)
-{
- if (mOutputFilenames.size())
- {
- clitk::writeImage<ImageType>(output, mOutputFilenames.front(), mIOVerbose);
- mOutputFilenames.pop_front();
- }
- if (mInputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
- mOutputVVImages.push_back(vvImageFromITK<ImageType::ImageDimension,typename ImageType::PixelType>(output));
-}
-template<class ImageType>
-typename ImageType::Pointer clitk::ImageToImageGenericFilter::GetInput(unsigned int n)
-{
- if (mInputFilenames.size() > n)
- return clitk::readImage<ImageType>(mInputFilenames[n], mIOVerbose);
- else if (mInputVVImages.size() > n)
- return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(mInputVVImages[n]).GetPointer()));
- else
- assert(false); //No input, this shouldn't happen
-}
#endif /* end #define CLITKIMAGETOIMAGEGENERICFILTER_H */