]> Creatis software - clitk.git/blobdiff - common/clitkImageToImageGenericFilter.txx
Allow compilation with ITK4.13.0
[clitk.git] / common / clitkImageToImageGenericFilter.txx
index 253d421d0f4bfd37112f06fd63cc5134cb1a6cc0..a13dca9f9d25eea604c2da79fc66306cc1e878d1 100644 (file)
@@ -1,85 +1,93 @@
 /*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Program:   vv
-  Module:    $RCSfile: clitkImageToImageGenericFilter.txx,v $
-  Language:  C++
-  Date:      $Date: 2010/02/08 15:45:17 $
-  Version:   $Revision: 1.2 $
-  Author :   Joel Schaerer <joel.schaerer@creatis.insa-lyon.fr>
-             David Sarrut <david.sarrut@creatis.insa-lyon.fr>
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.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 software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
 
-  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.
+  It is distributed under dual licence
 
-  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/>.
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+template<class FilterType>
+clitk::ImageToImageGenericFilter<FilterType>::ImageToImageGenericFilter(std::string filterName) :
+  ImageToImageGenericFilterBase(filterName),
+  mImageTypesManager(static_cast<FilterType*>(this))
+{
+}
+//--------------------------------------------------------------------
 
-  =========================================================================*/
 
 //--------------------------------------------------------------------
-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 FilterType>
+bool clitk::ImageToImageGenericFilter<FilterType>::Update()
+{
+  GetInputImageDimensionAndPixelType(m_Dim,m_PixelTypeName,m_NbOfComponents);
+
+  // Check ImageType
+  if (!CheckImageType()) {
+    if (m_FailOnImageTypeError) ImageTypeError();
+    else SetImageTypeError();
+    return false;
+  }
+
+  // Go ! Call the right templatized function
+  mImageTypesManager.DoIt(m_Dim, m_NbOfComponents, m_PixelTypeName);
+  return true;
 }
 //--------------------------------------------------------------------
 
-
 //--------------------------------------------------------------------
-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>
+bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType(unsigned int dim, unsigned int ncomp, std::string pixeltype)
+{
+  //SR: commented line creates an element in mMapOfImageTypeToFunction which, even if 0, is confusing, e.g. for GetAvailableImageTypes
+  //return static_cast<bool>(mImageTypesManager.mMapOfImageTypeToFunction[dim][ncomp][pixeltype]);
+  typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType &m = mImageTypesManager.mMapOfImageTypeToFunction;
+  return (m            .find(dim)       != m.end()      &&
+          m[dim]       .find(ncomp)     != m[dim].end() &&
+          m[dim][ncomp].find(pixeltype) != m[dim][ncomp].end());
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
 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));
+bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType()
+{
+  return CheckImageType(m_Dim, m_NbOfComponents, m_PixelTypeName);
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
 template<class FilterType>
-bool clitk::ImageToImageGenericFilter<FilterType>::Update() {
-  GetInputImageDimensionAndPixelType(mDim,mPixelTypeName,mNbOfComponents);    
-  
-  // Check ImageType
-  if (!CheckImageType()) {
-    if (mFailOnImageTypeError) ImageTypeError();
-    else SetImageTypeError();
-    return false;
-  }
+std::string clitk::ImageToImageGenericFilter<FilterType>::GetAvailableImageTypes()
+{
+  std::ostringstream oss;
+  oss << "The filter <" << m_FilterName << "> manages:" << std::endl;
 
-  // Go ! Call the right templatized function
-  mImageTypesManager->DoIt(mDim, mNbOfComponents, mPixelTypeName);
-  return true;
+  typedef typename ImageTypesManager<FilterType>::MapOfImageComponentsToFunctionType::const_iterator MCompItType;
+  typedef typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType::const_iterator MDimItType;
+  typedef typename ImageTypesManager<FilterType>::MapOfPixelTypeToFunctionType::const_iterator MPixelItType;
+  for (MDimItType i=mImageTypesManager.mMapOfImageTypeToFunction.begin();
+       i!=mImageTypesManager.mMapOfImageTypeToFunction.end();
+       i++) {
+    for (MCompItType j=(*i).second.begin(); j!= (*i).second.end(); j++) {
+      for (MPixelItType k=(*j).second.begin(); k!= (*j).second.end(); k++) {
+        oss << "Dim: " << (*i).first;
+        if ((*j).first != 1) oss << ", Components: " << (*j).first;
+        oss << ", Type: " << (*k).first << std::endl;
+      }
+    }
+  }
+  return oss.str();
 }
 //--------------------------------------------------------------------