]> Creatis software - clitk.git/commitdiff
- new GF system
authordsarrut <dsarrut>
Fri, 29 Jan 2010 08:48:42 +0000 (08:48 +0000)
committerdsarrut <dsarrut>
Fri, 29 Jan 2010 08:48:42 +0000 (08:48 +0000)
common/clitkCommonGenericFilter.h [new file with mode: 0644]
common/clitkImageToImageGenericFilter.txx [new file with mode: 0644]

diff --git a/common/clitkCommonGenericFilter.h b/common/clitkCommonGenericFilter.h
new file mode 100644 (file)
index 0000000..751a726
--- /dev/null
@@ -0,0 +1,90 @@
+/*=========================================================================
+
+  Program:   clitk
+  Module:    $RCSfile: clitkCommonGenericFilter.h,v $
+  Language:  C++
+  Date:      $Date: 2010/01/29 08:48:42 $
+  Version:   $Revision: 1.1 $
+  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
+
+  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.
+
+  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 CLITKCOMMONGENERICFILTER_H
+#define CLITKCOMMONGENERICFILTER_H
+
+// clitk include
+#include "clitkCommon.h"
+
+/*--------------------------------------------------------------------
+  DISCLAIMER : I obviously know how to make this mess much clearer and
+  shorter, but I fear its being too long to put in this margin ...
+  D.S.
+  -------------------------------------------------------------------- */
+
+namespace clitk {
+  
+  //--------------------------------------------------------------------
+  template<class FilterType>
+  class GenericFilterFunctorBase {
+  public:
+    GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
+    virtual void DoIt()= 0;
+    FilterType * mFilter;
+  };
+  //--------------------------------------------------------------------
+  template<class FilterType, unsigned int Dim, class PixelType>
+  class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
+  public:
+    GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
+    virtual void DoIt() {       
+      //GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithDimAndPixelType<Dim,PixelType>();
+      typedef itk::Image<PixelType,Dim> InputImageType;
+      GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
+    }
+  };
+
+  //--------------------------------------------------------------------
+  template<class FilterType>
+  class ImageTypesManager  {
+  public:
+    typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
+    std::map<int, MapOfPixelTypeToFunctionType> mMapOfImageTypeToFunction;
+
+    ImageTypesManager(FilterType * f) { mFilter = f;  }
+    virtual void DoIt(int dim, std::string pixelname) {
+      // std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
+      if (mMapOfImageTypeToFunction[dim][pixelname])
+        mMapOfImageTypeToFunction[dim][pixelname]->DoIt();
+    }
+    template<unsigned int Dim, class Pixeltype>
+    void AddNewDimensionAndPixelType() {
+      // std::cout << "Adding Dim=" << Dim << " and PT = " << GetTypeAsString<Pixeltype>() << std::endl;
+      mFilter->AddImageType(Dim, GetTypeAsString<Pixeltype>());
+      mMapOfImageTypeToFunction[Dim][ GetTypeAsString<Pixeltype>() ] = 
+        new GenericFilterFunctorWithDimAndPixelType<FilterType, Dim, Pixeltype>(mFilter);
+    }
+    FilterType * mFilter;
+  };
+  //--------------------------------------------------------------------
+
+} // end namespace
+
+#endif // end CLITKCOMMONGENERICFILTER_H
diff --git a/common/clitkImageToImageGenericFilter.txx b/common/clitkImageToImageGenericFilter.txx
new file mode 100644 (file)
index 0000000..6343c8b
--- /dev/null
@@ -0,0 +1,85 @@
+/*=========================================================================
+
+  Program:   vv
+  Module:    $RCSfile: clitkImageToImageGenericFilter.txx,v $
+  Language:  C++
+  Date:      $Date: 2010/01/29 08:48:42 $
+  Version:   $Revision: 1.1 $
+  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
+
+  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.
+
+  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/>.
+
+  =========================================================================*/
+
+//--------------------------------------------------------------------
+template<class ImageType> 
+void clitk::ImageToImageGenericFilterBase::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::ImageToImageGenericFilterBase::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
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class FilterType>
+clitk::ImageToImageGenericFilter<FilterType>::ImageToImageGenericFilter(std::string filterName)
+ :ImageToImageGenericFilterBase(filterName){
+  // Create main function manager
+  this->mImageTypesManager = new
+ ImageTypesManager<FilterType>(static_cast<FilterType*>(this));
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class FilterType>
+bool clitk::ImageToImageGenericFilter<FilterType>::Update() {
+  GetInputImageDimensionAndPixelType(mDim,mPixelTypeName,mNbOfComponents);    
+  
+  // Check ImageType
+  if (!CheckImageType()) {
+    if (mFailOnImageTypeError) ImageTypeError();
+    else SetImageTypeError();
+    return false;
+  }
+
+  // Go ! Call the right templatized function
+  mImageTypesManager->DoIt(mDim, mPixelTypeName);
+  return true;
+}
+//--------------------------------------------------------------------
+