]> Creatis software - clitk.git/blobdiff - common/clitkImageToImageGenericFilterBase.cxx
add FilterBase (trial)
[clitk.git] / common / clitkImageToImageGenericFilterBase.cxx
index fb61bbfb7b93fbd3459c821eff2edfa508413a71..bf68c9c28c9ebddc4541210d43bf1d0f0072eab7 100644 (file)
@@ -1,31 +1,20 @@
 /*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Program:   vv
-  Module:    $RCSfile: clitkImageToImageGenericFilterBase.cxx,v $
-  Language:  C++
-  Date:      $Date: 2010/03/02 13:02:52 $
-  Version:   $Revision: 1.1 $
-  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://oncora1.lyon.fnclcc.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.
-
-  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/>.
-
-  =========================================================================*/
+  It is distributed under dual licence
 
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+======================================================================-====*/
 #include "clitkImageToImageGenericFilterBase.h"
 #include <itkImage.h>
 
@@ -36,22 +25,34 @@ clitk::ImageToImageGenericFilterBase::~ImageToImageGenericFilterBase() {}
 
 //--------------------------------------------------------------------
 clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string n)
-  :mIOVerbose(false) {
+  :mIOVerbose(false)
+{
   mFilterName = n;
   mFailOnImageTypeError = true;
+  mReadOnDisk = true;
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & filenames)
+{
+  mInputFilenames=filenames;
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & filenames) {
-    mInputFilenames=filenames;
+void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b)
+{
+  mReadOnDisk = b;
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename) {
+void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename)
+{
   std::vector<std::string> f;
   f.push_back(filename);
   SetInputFilenames(f);
@@ -60,14 +61,16 @@ void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string &
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename) {
+void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename)
+{
   mInputFilenames.push_back(filename);
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & filename) {
+void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & filename)
+{
   mOutputFilenames.clear();
   mOutputFilenames.push_back(filename);
 }
@@ -85,8 +88,8 @@ void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string &
 //--------------------------------------------------------------------
 void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector<std::string> & filenames)
 {
-    mOutputFilenames.clear();
-    std::copy(filenames.begin(),filenames.end(),mOutputFilenames.begin());
+  mOutputFilenames.clear();
+  std::copy(filenames.begin(),filenames.end(),mOutputFilenames.begin());
 }
 //--------------------------------------------------------------------
 
@@ -94,31 +97,29 @@ void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector<
 //--------------------------------------------------------------------
 std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename()
 {
-    assert(mOutputFilenames.size() == 1);
-    return mOutputFilenames.front();
+  assert(mOutputFilenames.size() == 1);
+  return mOutputFilenames.front();
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
 void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(unsigned int& dim, \
-        std::string& pixeltype,unsigned int& components)
+    std::string& pixeltype,unsigned int& components)
 {
-  if (mInputFilenames.size())
-    {
-      int comp_temp,dim_temp; //clitkCommonImage takes ints
-      ReadImageDimensionAndPixelType(mInputFilenames[0], dim_temp, pixeltype,comp_temp);
-      components=comp_temp; dim=dim_temp;
-    }
-  else if (mInputVVImages.size())
-    {
+  if (mReadOnDisk && mInputFilenames.size()) {
+    int comp_temp,dim_temp; //clitkCommonImage takes ints
+    ReadImageDimensionAndPixelType(mInputFilenames[0], dim_temp, pixeltype,comp_temp);
+    components=comp_temp;
+    dim=dim_temp;
+  } else {
+    if (mInputVVImages.size()) {
       pixeltype=mInputVVImages[0]->GetScalarTypeAsString();
       dim=mInputVVImages[0]->GetNumberOfDimensions();
       components=mInputVVImages[0]->GetNumberOfScalarComponents();
-    }
-  else
-    assert(false); //No input image, shouldn't happen
-  
+    } else
+      assert(false); //No input image, shouldn't happen
+  }
   if (mIOVerbose) {
     std::cout << "Input is " << mDim << "D " << mPixelTypeName << "." << std::endl;
   }
@@ -129,8 +130,8 @@ void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(un
 //--------------------------------------------------------------------
 vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage ()
 {
-    assert(mOutputVVImages.size());
-    return mOutputVVImages[0];
+  assert(mOutputVVImages.size());
+  return mOutputVVImages[0];
 }
 //--------------------------------------------------------------------
 
@@ -138,7 +139,7 @@ vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage ()
 //--------------------------------------------------------------------
 std::vector<vvImage::Pointer> clitk::ImageToImageGenericFilterBase::GetOutputVVImages()
 {
-    return mOutputVVImages;
+  return mOutputVVImages;
 }
 //--------------------------------------------------------------------
 
@@ -146,8 +147,8 @@ std::vector<vvImage::Pointer> clitk::ImageToImageGenericFilterBase::GetOutputVVI
 //--------------------------------------------------------------------
 void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer input)
 {
-    mInputVVImages.clear();
-    mInputVVImages.push_back(input);
+  mInputVVImages.clear();
+  mInputVVImages.push_back(input);
 }
 //--------------------------------------------------------------------
 
@@ -155,7 +156,7 @@ void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer inp
 //--------------------------------------------------------------------
 void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer input)
 {
-    mInputVVImages.push_back(input);
+  mInputVVImages.push_back(input);
 }
 //--------------------------------------------------------------------
 
@@ -163,13 +164,14 @@ void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer inp
 //--------------------------------------------------------------------
 void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage::Pointer> input)
 {
-    mInputVVImages=input;
+  mInputVVImages=input;
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes() {
+void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes()
+{
   std::cout << GetAvailableImageTypes();
 }
 //--------------------------------------------------------------------
@@ -177,9 +179,10 @@ void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes() {
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::ImageTypeError() {
-  std::cerr << "**Error** The filter <" << mFilterName << "> is not available for " 
-            << mDim << "D images with pixel=" 
+void clitk::ImageToImageGenericFilterBase::ImageTypeError()
+{
+  std::cerr << "**Error** The filter <" << mFilterName << "> is not available for "
+            << mDim << "D images with pixel="
             << mPixelTypeName << " and "
             << mNbOfComponents << " component." << std::endl;
   std::cerr << GetAvailableImageTypes();
@@ -189,7 +192,8 @@ void clitk::ImageToImageGenericFilterBase::ImageTypeError() {
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::SetImageTypeError() {
+void clitk::ImageToImageGenericFilterBase::SetImageTypeError()
+{
   std::cerr << "TODO ! " << std::endl;
   exit(0);
 }
@@ -197,22 +201,25 @@ void clitk::ImageToImageGenericFilterBase::SetImageTypeError() {
 
 
 //--------------------------------------------------------------------
-const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName() { 
-  return mFilterName; 
+const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName()
+{
+  return mFilterName;
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n) { 
-  mFilterName = n; 
+void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n)
+{
+  mFilterName = n;
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b) { 
-  mIOVerbose = b; 
+void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b)
+{
+  mIOVerbose = b;
 }
 //--------------------------------------------------------------------
 
@@ -264,13 +271,13 @@ DEF_SetNextOutput_And_GetInput(double, 4);
 
 
 //--------------------------------------------------------------------
-template<class ImageType> 
-void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output) {
-  if (mOutputFilenames.size())
-    {
-      clitk::writeImage<ImageType>(output, mOutputFilenames.front(), mIOVerbose);
-      mOutputFilenames.pop_front();
-    }
+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));
 }
@@ -278,18 +285,19 @@ void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Poi
 
 
 //--------------------------------------------------------------------
-template<class ImageType> 
-typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n) {
-  if (mInputFilenames.size() > n) {
+template<class ImageType>
+typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n)
+{
+  if (mReadOnDisk && 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
-    {
+  } 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
       return typename ImageType::Pointer(NULL);
     }
+  }
 }
 //--------------------------------------------------------------------