X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkImageToImageGenericFilter.h;h=eb244b8e5bdf724060a3ef2ba64c25f2a6ede9e9;hb=33b0605f7f0b0b8bb2a6d90c3fec771487b29744;hp=43a62df8aaaabc969842ba388860fe03e6daec20;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/common/clitkImageToImageGenericFilter.h b/common/clitkImageToImageGenericFilter.h index 43a62df..eb244b8 100644 --- a/common/clitkImageToImageGenericFilter.h +++ b/common/clitkImageToImageGenericFilter.h @@ -1,40 +1,67 @@ -#ifndef CLITKIMAGETOIMAGEGENERICFILTER_H -#define CLITKIMAGETOIMAGEGENERICFILTER_H +/*========================================================================= + + Program: clitk + Module: $RCSfile: clitkImageToImageGenericFilter.h,v $ + Language: C++ + Date: $Date: 2010/02/09 14:40:55 $ + Version: $Revision: 1.7 $ + Author : Joel Schaerer + David Sarrut + + 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 - * @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 . + + =========================================================================*/ + +#ifndef CLITKIMAGETOIMAGEGENERICFILTER_H +#define CLITKIMAGETOIMAGEGENERICFILTER_H // clitk include #include "clitkCommon.h" #include "clitkImageCommon.h" +#include "clitkCommonGenericFilter.h" #include +// vv include #include #include #include #include +#include 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 Pointer; typedef itk::SmartPointer 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); @@ -56,16 +83,24 @@ namespace clitk { vvImage::Pointer GetOutputVVImage (); std::vector GetOutputVVImages (); - /// Main function to implement - virtual void Update() = 0; - - protected: + // Information on available image types + void PrintAvailableImageTypes(); + virtual std::string GetAvailableImageTypes() = 0; + + virtual bool CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype) = 0; + virtual bool CheckImageType() = 0; + + // Main function to call for using the filter. + virtual bool Update() = 0; + + protected: /// Call this function to dispatch an output towards the correct sink template - 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 - typename ImageType::Pointer GetInput(unsigned int n); + typename ImageType::Pointer GetInput(unsigned int n); std::vector mInputFilenames; std::list mOutputFilenames; @@ -74,34 +109,51 @@ namespace clitk { unsigned int mDim; std::string mPixelTypeName; unsigned int mNbOfComponents; + std::string mFilterName; std::vector mInputVVImages; std::vector mOutputVVImages; + void ImageTypeError(); + void SetImageTypeError(); + bool mFailOnImageTypeError; + }; // end class clitk::ImageToImageGenericFilter + + //-------------------------------------------------------------------- + template + class ImageToImageGenericFilter: public ImageToImageGenericFilterBase { + + public: + + typedef ImageToImageGenericFilter Self; + + // constructor - destructor + ImageToImageGenericFilter(std::string filterName); + + // Main function to call for using the filter. + virtual bool Update(); + virtual bool CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype); + virtual bool CheckImageType(); + virtual std::string GetAvailableImageTypes(); + + protected: + // Object that will manage the list of templatized function for + // each image type. + ImageTypesManager mImageTypesManager; + + }; // end class clitk::ImageToImageGenericFilter + + // #define ADD_IMAGE_DIMENSION(DIM) Initialize(); + +#define ADD_VEC_IMAGE_TYPE(DIM, COMP, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType(); +#define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType(); + + +#include "clitkImageToImageGenericFilter.txx" + } // end namespace -template -void clitk::ImageToImageGenericFilter::SetNextOutput(typename ImageType::Pointer output) -{ - if (mOutputFilenames.size()) - { - clitk::writeImage(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(output)); -} -template -typename ImageType::Pointer clitk::ImageToImageGenericFilter::GetInput(unsigned int n) -{ - if (mInputFilenames.size() > n) - return clitk::readImage(mInputFilenames[n], mIOVerbose); - else if (mInputVVImages.size() > n) - return typename ImageType::Pointer(const_cast(vvImageToITK(mInputVVImages[n]).GetPointer())); - else - assert(false); //No input, this shouldn't happen -} #endif /* end #define CLITKIMAGETOIMAGEGENERICFILTER_H */