]> Creatis software - clitk.git/commitdiff
- multiple inputs in vv
authordsarrut <dsarrut>
Wed, 24 Mar 2010 10:48:05 +0000 (10:48 +0000)
committerdsarrut <dsarrut>
Wed, 24 Mar 2010 10:48:05 +0000 (10:48 +0000)
- example with (vv/clitk)ImageArithm

27 files changed:
common/clitkCommon.txx
common/clitkImageToImageGenericFilterBase.cxx
common/clitkImageToImageGenericFilterBase.h
filters/CMakeLists.txt
filters/clitkBinarizeImageGenericFilter.h
filters/clitkImageArithmGenericFilter.cxx
filters/clitkImageArithmGenericFilter.h
filters/clitkImageArithmGenericFilter.txx
filters/clitkImageResampleGenericFilter.cxx
tools/CMakeLists.txt
tools/clitkBinarizeImage.cxx
tools/clitkImageArithm.cxx
vv/CMakeLists.txt
vv/qt_ui/vvToolSimpleInputSelectorWidget.ui
vv/qt_ui/vvToolWidgetBase.ui
vv/vvMainWindow.cxx
vv/vvToolBinarize.cxx
vv/vvToolBinarize.h
vv/vvToolCropImage.cxx
vv/vvToolFooWithWidgetBase.cxx
vv/vvToolFooWithWidgetBase.h
vv/vvToolInputSelectorWidget.cxx
vv/vvToolInputSelectorWidget.h
vv/vvToolSimpleInputSelectorWidget.cxx
vv/vvToolSimpleInputSelectorWidget.h
vv/vvToolWidgetBase.cxx
vv/vvToolWidgetBase.h

index 4d16648fbc020aa025c70b5c46de41c16b330ab3..bb4508a91a1866f81feed5dd9d8195096fbe0765 100644 (file)
@@ -132,6 +132,7 @@ std::string GetTypeAsString() {
 template<class ImageType>
 void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output) {
   output->SetRegions(input->GetLargestPossibleRegion());
+  output->SetOrigin(input->GetOrigin());
   output->SetSpacing(input->GetSpacing());
   output->Allocate();
   typedef itk::ImageRegionConstIterator<ImageType> ConstIteratorType; 
index 1a3782a62dca975e23ff8ae8ddf05a1ba38bc14a..2c445bc7b2180f4e42e44557b3f75648b09a6b1c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: clitkImageToImageGenericFilterBase.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/03 13:00:36 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2010/03/24 10:48:05 $
+  Version:   $Revision: 1.3 $
   Author :   Joel Schaerer <joel.schaerer@creatis.insa-lyon.fr>
   David Sarrut <david.sarrut@creatis.insa-lyon.fr>
 
@@ -39,6 +39,7 @@ clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string
   :mIOVerbose(false) {
   mFilterName = n;
   mFailOnImageTypeError = true;
+  mReadOnDisk = true;
 }
 //--------------------------------------------------------------------
 
@@ -50,6 +51,13 @@ void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<s
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b) {
+  mReadOnDisk = b;
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename) {
   std::vector<std::string> f;
@@ -104,21 +112,20 @@ std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename()
 void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(unsigned int& dim, \
         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
+    else
     assert(false); //No input image, shouldn't happen
-  
+  }
   if (mIOVerbose) {
     std::cout << "Input is " << mDim << "D " << mPixelTypeName << "." << std::endl;
   }
@@ -280,16 +287,18 @@ void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Poi
 //--------------------------------------------------------------------
 template<class ImageType> 
 typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n) {
-  if (mInputFilenames.size() > 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
-    {
-      assert(false); //No input, this shouldn't happen
-      return typename ImageType::Pointer(NULL);
-    }
+  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);
+      }
+  }
 }
 //--------------------------------------------------------------------
 
index 4933b10db4edc6c5f753e27092e42e6370d20021..7d5583c5ee02e9e015c40b7c021ff27671a469a4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   clitk
   Module:    $RCSfile: clitkImageToImageGenericFilterBase.h,v $
   Language:  C++
-  Date:      $Date: 2010/03/03 13:00:36 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2010/03/24 10:48:05 $
+  Version:   $Revision: 1.3 $
   Author :   Joel Schaerer <joel.schaerer@creatis.insa-lyon.fr>
              David Sarrut <david.sarrut@creatis.insa-lyon.fr>
 
@@ -71,6 +71,7 @@ namespace clitk {
     void SetInputFilename(const std::string & filename);
     void AddInputFilename(const std::string & filename);
     void SetInputFilenames(const std::vector<std::string> & filenames);
+    void EnableReadOnDisk(bool b);
     void SetOutputFilename(const std::string & filename);
     void AddOutputFilename(const std::string & filename);
     void SetOutputFilenames(const std::vector<std::string> & filenames);
@@ -95,6 +96,7 @@ namespace clitk {
     virtual bool Update() = 0;
 
   protected:  
+    bool mReadOnDisk;
     /// Call this function to dispatch an output towards the correct sink
     template<class ImageType> 
     void SetNextOutput(typename ImageType::Pointer output);
@@ -124,7 +126,7 @@ namespace clitk {
 #define ADD_VEC_IMAGE_TYPE(DIM, COMP, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM,COMP, PT>();
 #define ADD_IMAGE_TYPE(DIM, PT) this->mImageTypesManager.template AddNewDimensionAndPixelType<DIM, PT>();
 
-#include "clitkImageToImageGenericFilterBase.txx"
+  //#include "clitkImageToImageGenericFilterBase.txx"
 
 } // end namespace
 
index ca56f4eb7ed5aaf9e5355bd9bb32c2b9074199ef..89339caf09054a18e4d008ef3ce11a9c7bdb245b 100644 (file)
@@ -6,6 +6,7 @@ INCLUDE(../cmake/common.cmake)
 
 SET(clitkFilters_SRC
   clitkGuerreroVentilationGenericFilter.cxx
+  clitkImageArithm_ggo.c
   clitkImageArithmGenericFilter.cxx
   clitkImageConvertGenericFilter.cxx
   clitkImageFillRegionGenericFilter.cxx
index ad2966d92a3f00723d1a9f65229f8f1ef175157f..ddab776d30ccff2b9fe3b32dc02d0c34eb463779 100644 (file)
@@ -3,8 +3,8 @@
   Program:   clitk
   Module:    $RCSfile: clitkBinarizeImageGenericFilter.h,v $
   Language:  C++
-  Date:      $Date: 2010/02/03 10:54:58 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2010/03/24 10:48:09 $
+  Version:   $Revision: 1.3 $
   Author :   Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
              David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
@@ -31,7 +31,6 @@
 
 // clitk include
 #include "clitkIO.h"
-#include "clitkCommon.h"
 #include "clitkImageToImageGenericFilter.h"
 
 //--------------------------------------------------------------------
index fb33c2b7a133eb4b606ce96d347f7cae53bad83e..ea22f14cd89d46e401c56624cb24847c723e7b25 100644 (file)
 
 #include "clitkImageArithmGenericFilter.h"
 
-//--------------------------------------------------------------------
-clitk::ImageArithmGenericFilter::ImageArithmGenericFilter()
-  :ImageToImageGenericFilter<Self>("ImageArithmGenericFilter"),mTypeOfOperation(0) {
-  InitializeImageType<2>();
-  InitializeImageType<3>();
-  InitializeImageType<4>();  
-  mIsOperationUseASecondImage = false;
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-template<unsigned int Dim>
-void clitk::ImageArithmGenericFilter::InitializeImageType() {      
-  ADD_IMAGE_TYPE(Dim, char);
-  ADD_IMAGE_TYPE(Dim, short);
-  ADD_IMAGE_TYPE(Dim, float);
-  /*  ADD_IMAGE_TYPE(Dim, short);
-  ADD_IMAGE_TYPE(Dim, ushort;
-  ADD_IMAGE_TYPE(Dim, int);
-  ADD_IMAGE_TYPE(Dim, unsigned int);
-  ADD_IMAGE_TYPE(Dim, double);
-  */
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-template<class ImageType>
-void clitk::ImageArithmGenericFilter::UpdateWithInputImageType() {
-
-  // Check Input
-
-  //DS TO BE CHANGED IN GetNumberOfInput() !!!!!!!!
-
-  if (mInputFilenames.size() == 0) {
-    std::cerr << "ERROR : please provide at least a input filename." << std::endl;
-  }
-  if (mInputFilenames.size() == 1) {
-    mIsOperationUseASecondImage = false;
-  }
-  if (mInputFilenames.size() == 2) {
-    mIsOperationUseASecondImage = true;
-  }
-  if (mInputFilenames.size() > 2) {
-    std::cerr << "ERROR : please provide only 1 or 2 input filenames." << std::endl;
-  }
-
-  // Read input1
-  //  typename ImageType::Pointer input1 = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
-  typename ImageType::Pointer input1 = this->template GetInput<ImageType>(0);
-  typename ImageType::Pointer outputImage;  
-
-  // Read input2 (float is ok altough it could take too memory ...)
-  if (mIsOperationUseASecondImage) {
-    typedef itk::Image<float,ImageType::ImageDimension> ImageType2;
-    //    typename ImageType2::Pointer input2 = clitk::readImage<ImageType2>(mInputFilenames[1], mIOVerbose);
-    typename ImageType2::Pointer input2 = this->template GetInput<ImageType2>(1);
-    outputImage = ComputeImage<ImageType, ImageType2>(input1, input2);
-  }
-  else {
-    outputImage = ComputeImage<ImageType>(input1);
-  }
-
-  // Write results
-  this->SetNextOutput<ImageType>(outputImage);
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-template<class ImageType>
-typename ImageType::Pointer 
-clitk::ImageArithmGenericFilter::ComputeImage(typename ImageType::Pointer inputImage) {
-
-  typedef typename ImageType::PixelType PixelType;
-  typedef itk::ImageRegionIterator<ImageType> IteratorType;
-  IteratorType it(inputImage, inputImage->GetLargestPossibleRegion());
-  it.GoToBegin();
-  
-  switch (mTypeOfOperation) {
-  case 0: // Addition
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>((double)it.Get() + mScalar) ); 
-      ++it;
-    }
-    break;
-  case 1: // Multiply
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>((double)it.Get() * mScalar) ); 
-      ++it;
-    }
-    break;
-  case 2: // Inverse
-    while (!it.IsAtEnd()) {
-      if (it.Get() != 0)
-       it.Set(PixelTypeDownCast<double, PixelType>(mScalar / (double)it.Get())); 
-      else it.Set(mDefaultPixelValue);
-      ++it;
-    }
-    break;
-  case 3: // Max 
-    while (!it.IsAtEnd()) {
-      if (it.Get() < mScalar) it.Set(PixelTypeDownCast<double, PixelType>(mScalar)); 
-      ++it;
-    }
-    break;
-  case 4: // Min
-    while (!it.IsAtEnd()) {
-      if (it.Get() > mScalar) it.Set(PixelTypeDownCast<double, PixelType>(mScalar)); 
-      ++it;
-    }
-    break;
-  case 5: // Absolute value 
-    while (!it.IsAtEnd()) {
-      if (it.Get() <= 0) it.Set(PixelTypeDownCast<double, PixelType>(-it.Get())); 
-      // <= zero to avoid warning for unsigned types
-      ++it;
-    }
-    break;
-  case 6: // Squared value
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>((double)it.Get()*(double)it.Get())); 
-      ++it;
-    }
-    break;
-  case 7: // Log
-    while (!it.IsAtEnd()) {
-      if (it.Get() > 0) 
-       it.Set(PixelTypeDownCast<double, PixelType>(log((double)it.Get()))); 
-      else it.Set(mDefaultPixelValue);
-      ++it;
-    }
-    break;
-  case 8: // exp
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>(exp((double)it.Get()))); 
-      ++it;
-    }
-    break;
-  case 9: // sqrt
-    while (!it.IsAtEnd()) {
-      if (it.Get() > 0) 
-       it.Set(PixelTypeDownCast<double, PixelType>(sqrt((double)it.Get()))); 
-      else {
-       if (it.Get() ==0) it.Set(0);
-       else it.Set(mDefaultPixelValue);
-      }
-      ++it;
-    }
-    break;
-  default: // error ?
-    std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl;
-    exit(-1);
-  }
-
-  return inputImage;
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-template<class ImageType1, class ImageType2>
-typename ImageType1::Pointer
-clitk::ImageArithmGenericFilter::ComputeImage(typename ImageType1::Pointer inputImage1, 
-                                      typename ImageType2::Pointer inputImage2) {
-
-  typedef typename ImageType1::PixelType PixelType;
-  typedef itk::ImageRegionIterator<ImageType1> IteratorType;
-  IteratorType it1(inputImage1, inputImage1->GetLargestPossibleRegion());
-  it1.GoToBegin();
-  
-  typedef itk::ImageRegionConstIterator<ImageType2> ConstIteratorType;
-  ConstIteratorType it2(inputImage2, inputImage2->GetLargestPossibleRegion());
-  it2.GoToBegin();
-  
-  switch (mTypeOfOperation) {
-  case 0: // Addition
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() + (double)it2.Get()) ); 
-      ++it1; ++it2;
-    }
-    break;
-  case 1: // Multiply
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() * (double)it2.Get()) ); 
-      ++it1; ++it2;
-    }
-    break;
-  case 2: // Divide
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() != 0)
-       it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() / (double)it2.Get())); 
-      else it1.Set(mDefaultPixelValue);
-      ++it1; ++it2;
-    }
-    break;
-  case 3: // Max 
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() < it2.Get()) it1.Set(PixelTypeDownCast<double, PixelType>(it2.Get())); 
-      ++it1; ++it2;
-    }
-    break;
-  case 4: // Min
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() > it2.Get()) it1.Set(PixelTypeDownCast<double, PixelType>(it2.Get())); 
-      ++it1; ++it2;
-    }
-    break;
-  case 5: // Absolute difference
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>(fabs(it2.Get()-it1.Get()))); 
-      ++it1; ++it2;
-    }
-    break;
-  case 6: // Squared differences
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>(pow((double)it1.Get()-(double)it2.Get(),2))); 
-      ++it1; ++it2;
-    }
-    break;
-  case 7: // Difference
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get()-(double)it2.Get())); 
-      ++it1; ++it2;
-    }
-    break;
-  case 8: // Relative Difference
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() != 0) it1.Set(PixelTypeDownCast<double, PixelType>(((double)it1.Get()-(double)it2.Get()))/(double)it1.Get()); 
-      else it1.Set(0.0);
-      ++it1; ++it2;
-    }
-    break;
-  default: // error ?
-    std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl;
-    exit(-1);
-  }
-
-  return inputImage1;
-}
-//--------------------------------------------------------------------
 
 #endif //define CLITKIMAGEARITHMGENERICFILTER_CXX
index afc6134eba3365f14c9f72cd2b17175209bc4dc8..ebe9c0b1e88ab76429f0cad3e144ed0e0272b774 100644 (file)
@@ -24,7 +24,6 @@
 
 // clitk include
 #include "clitkCommon.h"
-#include "clitkImageCommon.h"
 #include "clitkImageToImageGenericFilter.h"
 
 // itk include
 #include "itkImageRegionIterator.h"
 #include "itkImageRegionConstIterator.h"
 
+//--------------------------------------------------------------------
 namespace clitk {
   
-  //--------------------------------------------------------------------
-  // Main class for an Image Resample Generic Filter 
-  // (multiple dimensions, multiple pixel types)
-  class ImageArithmGenericFilter:
-  public clitk::ImageToImageGenericFilter<ImageArithmGenericFilter> {
-  
+  template<class args_info_type>
+  class ITK_EXPORT ImageArithmGenericFilter:
+    public clitk::ImageToImageGenericFilter<ImageArithmGenericFilter<args_info_type> > {
+    
   public:
        
     // Constructor 
     ImageArithmGenericFilter ();
 
     // Types
-    typedef ImageArithmGenericFilter      Self;
-    typedef ImageToImageGenericFilterBase     Superclass;
-    typedef itk::SmartPointer<Self>       Pointer;
-    typedef itk::SmartPointer<const Self> ConstPointer;
+    typedef ImageArithmGenericFilter        Self;
+    typedef ImageToImageGenericFilterBase   Superclass;
+    typedef itk::SmartPointer<Self>         Pointer;
+    typedef itk::SmartPointer<const Self>   ConstPointer;
 
     // New
     itkNewMacro(Self);
     
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const args_info_type & a);
+
     // Set methods
     void SetDefaultPixelValue (double value) {  mDefaultPixelValue = value ;}
     void SetTypeOfOperation (int value) {  mTypeOfOperation = value ;}
     void SetScalar (double value) {  mScalar = value ;}
+    void EnableOverwriteInputImage(bool b);
 
     // Get methods
     double GetDefaultPixelValue () { return  mDefaultPixelValue ;} 
@@ -76,23 +78,25 @@ namespace clitk {
     double mScalar;
     double mDefaultPixelValue;
     int mTypeOfOperation;  
+    args_info_type mArgsInfo;
+    bool mOverwriteInputImage;
+    bool mOutputIsFloat;
+    
+    template<class Iter1, class Iter2>
+      void ComputeImage(Iter1 it, Iter2 ito);
 
-    template<class ImageType>
-    typename ImageType::Pointer ComputeImage(typename ImageType::Pointer inputImage);
+    template<class Iter1, class Iter2, class Iter3>
+      void ComputeImage(Iter1 it1, Iter2 it2, Iter3 ito);
 
-    template<class ImageType1, class ImageType2>
-    typename ImageType1::Pointer
-    ComputeImage(typename ImageType1::Pointer inputImage1, 
-                typename ImageType2::Pointer inputImage2);
     //--------------------------------------------------------------------
 
   }; // end class ImageArithmGenericFilter
-//--------------------------------------------------------------------
-
-//#include "clitkImageArithmGenericFilter.txx"
-
 } // end namespace
 //--------------------------------------------------------------------
 
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkImageArithmGenericFilter.txx"
+#endif
+
 #endif //#define CLITKIMAGEARITHMGENERICFILTER_H
 
index 8557dc089798b44cb0ea2eec9a64fecb103b9adc..6d406810ae972b0237cdb9d537a23f94f3f33dfc 100644 (file)
 #ifndef CLITKIMAGEARITHMGENERICFILTER_TXX
 #define CLITKIMAGEARITHMGENERICFILTER_TXX
 
-/*-------------------------------------------------
- * @file   clitkImageArithmGenericFilter.txx
- * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
- * @date   9 August 2006
- * 
- -------------------------------------------------*/
-
-//--------------------------------------------------------------------
-template<unsigned int Dim>
-void ImageArithmGenericFilter::Update_WithDim() { 
-#define TRY_TYPE(TYPE)                                                 \
-  if (IsSameType<TYPE>(mPixelTypeName)) { Update_WithDimAndPixelType<Dim, TYPE>(); return; } 
-  TRY_TYPE(char);
-  TRY_TYPE(uchar);
-  TRY_TYPE(short);
-  TRY_TYPE(ushort);
-  TRY_TYPE(int);
-  TRY_TYPE(unsigned int); 
-  TRY_TYPE(float);
-  TRY_TYPE(double);
-#undef TRY_TYPE
-
-  std::string list = CreateListOfTypes<char, uchar, short, ushort, int, uint, float, double>();
-  std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '"
-           << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl;
-  exit(0);
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-template<unsigned int Dim, class PixelType>
-void ImageArithmGenericFilter::Update_WithDimAndPixelType() {
-  // Read input1
-  typedef itk::Image<PixelType,Dim> ImageType;
-  typename ImageType::Pointer input1 = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
-  typename ImageType::Pointer outputImage;  
-
-  // Read input2 (float is ok altough it could take too memory ...)
-  if (mIsOperationUseASecondImage) {
-    typedef itk::Image<float,Dim> ImageType2;
-    typename ImageType2::Pointer input2 = clitk::readImage<ImageType2>(mInputFilenames[1], mIOVerbose);
-    outputImage = ComputeImage<ImageType, ImageType2>(input1, input2);
+namespace clitk
+{
+  
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  ImageArithmGenericFilter<args_info_type>::ImageArithmGenericFilter()
+    :ImageToImageGenericFilter<Self>("ImageArithmGenericFilter"),mTypeOfOperation(0) {
+    InitializeImageType<2>();
+    InitializeImageType<3>();
+    InitializeImageType<4>();  
+    mIsOperationUseASecondImage = false;
+    mOverwriteInputImage = true;
   }
-  else {
-    outputImage = ComputeImage<ImageType>(input1);
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  template<unsigned int Dim>
+  void ImageArithmGenericFilter<args_info_type>::InitializeImageType() {      
+    ADD_IMAGE_TYPE(Dim, char);
+    ADD_IMAGE_TYPE(Dim, short);
+    ADD_IMAGE_TYPE(Dim, float);
   }
+  //--------------------------------------------------------------------
 
-  // Write results
-  this->SetNextOutput<ImageType>(outputImage);
-  //clitk::writeImage<ImageType>(outputImage, mOutputFilename, mIOVerbose);
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-template<class ImageType>
-typename ImageType::Pointer 
-ImageArithmGenericFilter::ComputeImage(typename ImageType::Pointer inputImage) {
-
-  typedef typename ImageType::PixelType PixelType;
-  typedef itk::ImageRegionIterator<ImageType> IteratorType;
-  IteratorType it(inputImage, inputImage->GetLargestPossibleRegion());
-  it.GoToBegin();
-  
-  switch (mTypeOfOperation) {
-  case 0: // Addition
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>((double)it.Get() + mScalar) ); 
-      ++it;
-    }
-    break;
-  case 1: // Multiply
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>((double)it.Get() * mScalar) ); 
-      ++it;
-    }
-    break;
-  case 2: // Inverse
-    while (!it.IsAtEnd()) {
-      if (it.Get() != 0)
-       it.Set(PixelTypeDownCast<double, PixelType>(mScalar / (double)it.Get())); 
-      else it.Set(mDefaultPixelValue);
-      ++it;
-    }
-    break;
-  case 3: // Max 
-    while (!it.IsAtEnd()) {
-      if (it.Get() < mScalar) it.Set(PixelTypeDownCast<double, PixelType>(mScalar)); 
-      ++it;
-    }
-    break;
-  case 4: // Min
-    while (!it.IsAtEnd()) {
-      if (it.Get() > mScalar) it.Set(PixelTypeDownCast<double, PixelType>(mScalar)); 
-      ++it;
-    }
-    break;
-  case 5: // Absolute value 
-    while (!it.IsAtEnd()) {
-      if (it.Get() <= 0) it.Set(PixelTypeDownCast<double, PixelType>(-it.Get())); 
-      // <= zero to avoid warning for unsigned types
-      ++it;
-    }
-    break;
-  case 6: // Squared value
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>((double)it.Get()*(double)it.Get())); 
-      ++it;
-    }
-    break;
-  case 7: // Log
-    while (!it.IsAtEnd()) {
-      if (it.Get() > 0) 
-       it.Set(PixelTypeDownCast<double, PixelType>(log((double)it.Get()))); 
-      else it.Set(mDefaultPixelValue);
-      ++it;
+
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  void ImageArithmGenericFilter<args_info_type>::EnableOverwriteInputImage(bool b) {      
+    mOverwriteInputImage = b;
+  }
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  void ImageArithmGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
+    mArgsInfo=a;
+
+    // Set value
+    SetIOVerbose(mArgsInfo.verbose_flag);
+    mTypeOfOperation = mArgsInfo.operation_arg;
+    mDefaultPixelValue = mArgsInfo.pixelValue_arg;
+    mScalar = mArgsInfo.scalar_arg;
+    mOutputIsFloat = mArgsInfo.setFloatOutput_flag;
+
+    if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
+
+    if (mArgsInfo.input1_given) AddInputFilename(mArgsInfo.input1_arg);
+    if (mArgsInfo.input2_given) {
+      mIsOperationUseASecondImage = true;
+      AddInputFilename(mArgsInfo.input2_arg);
     }
-    break;
-  case 8: // exp
-    while (!it.IsAtEnd()) {
-      it.Set(PixelTypeDownCast<double, PixelType>(exp((double)it.Get()))); 
-      ++it;
+    
+    if (mArgsInfo.output_given) SetOutputFilename(mArgsInfo.output_arg);
+
+    // Check type of operation (with scalar or with other image)
+    if ((mArgsInfo.input2_given) && (mArgsInfo.scalar_given)) {
+      std::cerr << "ERROR : you cannot provide both --scalar and --input2 option" << std::endl;
+      exit(-1);
     }
-    break;
-  case 9: // sqrt
-    while (!it.IsAtEnd()) {
-      if (it.Get() > 0) 
-       it.Set(PixelTypeDownCast<double, PixelType>(sqrt((double)it.Get()))); 
-      else {
-       if (it.Get() ==0) it.Set(0);
-       else it.Set(mDefaultPixelValue);
+    if ((!mArgsInfo.input2_given) && (!mArgsInfo.scalar_given)) {
+      if (mArgsInfo.operation_arg < 5) {
+        std::cerr << "Such operation need the --scalar option." << std::endl;
+        exit(-1);
       }
-      ++it;
     }
-    break;
-  default: // error ?
-    std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl;
-    exit(-1);
   }
+  //--------------------------------------------------------------------
 
-  return inputImage;
-}
-//--------------------------------------------------------------------
 
-//--------------------------------------------------------------------
-template<class ImageType1, class ImageType2>
-typename ImageType1::Pointer
-ImageArithmGenericFilter::ComputeImage(typename ImageType1::Pointer inputImage1, 
-                                      typename ImageType2::Pointer inputImage2) {
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  template<class ImageType>
+  void ImageArithmGenericFilter<args_info_type>::UpdateWithInputImageType() {
+    // Read input1
+    typename ImageType::Pointer input1 = this->template GetInput<ImageType>(0);
+    typename ImageType::PixelType PixelType;
 
-  typedef typename ImageType1::PixelType PixelType;
-  typedef itk::ImageRegionIterator<ImageType1> IteratorType;
-  IteratorType it1(inputImage1, inputImage1->GetLargestPossibleRegion());
-  it1.GoToBegin();
-  
-  typedef itk::ImageRegionConstIterator<ImageType2> ConstIteratorType;
-  ConstIteratorType it2(inputImage2, inputImage2->GetLargestPossibleRegion());
-  it2.GoToBegin();
-  
-  switch (mTypeOfOperation) {
-  case 0: // Addition
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() + (double)it2.Get()) ); 
-      ++it1; ++it2;
-    }
-    break;
-  case 1: // Multiply
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() * (double)it2.Get()) ); 
-      ++it1; ++it2;
-    }
-    break;
-  case 2: // Divide
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() != 0)
-       it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() / (double)it2.Get())); 
-      else it1.Set(mDefaultPixelValue);
-      ++it1; ++it2;
-    }
-    break;
-  case 3: // Max 
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() < it2.Get()) it1.Set(PixelTypeDownCast<double, PixelType>(it2.Get())); 
-      ++it1; ++it2;
+    // Set input image iterator
+    typedef itk::ImageRegionIterator<ImageType> IteratorType;
+    IteratorType it(input1, input1->GetLargestPossibleRegion());
+
+    // typedef input2
+    typename ImageType::Pointer input2 = this->template GetInput<ImageType>(1);
+    IteratorType it2;
+
+    if (mIsOperationUseASecondImage) {
+      // Read input2
+      input2 = this->template GetInput<ImageType>(1);
+      // Set input image iterator
+      it2 = IteratorType(input2, input2->GetLargestPossibleRegion());  
     }
-    break;
-  case 4: // Min
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() > it2.Get()) it1.Set(PixelTypeDownCast<double, PixelType>(it2.Get())); 
-      ++it1; ++it2;
+
+    // Check if overwrite and outputisfloat and pixeltype is not float -> do not overwrite
+    if (mOverwriteInputImage && mOutputIsFloat && (typeid(PixelType) != typeid(float))) {
+      // std::cerr << "Warning. Could not use both mOverwriteInputImage and mOutputIsFloat, because input is " 
+      //                     << typeid(PixelType).name()
+      //                     << std::endl;
+      mOverwriteInputImage = false;
     }
-    break;
-  case 5: // Absolute difference
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>(fabs(it2.Get()-it1.Get()))); 
-      ++it1; ++it2;
+
+    // ---------------- Overwrite input Image ---------------------
+    if (mOverwriteInputImage) {
+      // Set output iterator (to input1)
+      IteratorType ito = IteratorType(input1, input1->GetLargestPossibleRegion());
+      if (mIsOperationUseASecondImage) ComputeImage(it, it2, ito);
+      else ComputeImage(it, ito);
+      this->template SetNextOutput<ImageType>(input1);
     }
-    break;
-  case 6: // Squared differences
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>(pow((double)it1.Get()-(double)it2.Get(),2))); 
-      ++it1; ++it2;
+    
+    // ---------------- Create new output Image ---------------------
+    else {
+      if (mOutputIsFloat) {
+        // Create output image
+        typedef itk::Image<float,ImageType::ImageDimension> OutputImageType;
+        typename OutputImageType::Pointer output = OutputImageType::New();
+        output->SetRegions(input1->GetLargestPossibleRegion());
+        output->SetOrigin(input1->GetOrigin());
+        output->SetSpacing(input1->GetSpacing());
+        output->Allocate();
+        // Set output iterator
+        typedef itk::ImageRegionIterator<OutputImageType> IteratorOutputType;
+        IteratorOutputType ito = IteratorOutputType(output, output->GetLargestPossibleRegion());
+        if (mIsOperationUseASecondImage) ComputeImage(it, it2, ito);
+        else ComputeImage(it, ito);
+        this->template SetNextOutput<OutputImageType>(output);
+      }
+      else {
+        // Create output image
+        typedef ImageType OutputImageType;
+        typename OutputImageType::Pointer output = OutputImageType::New();
+        output->SetRegions(input1->GetLargestPossibleRegion());
+        output->SetOrigin(input1->GetOrigin());
+        output->SetSpacing(input1->GetSpacing());
+        output->Allocate();
+        // Set output iterator
+        typedef itk::ImageRegionIterator<OutputImageType> IteratorOutputType;
+        IteratorOutputType ito = IteratorOutputType(output, output->GetLargestPossibleRegion());
+        if (mIsOperationUseASecondImage) ComputeImage(it, it2, ito);
+        else ComputeImage(it, ito);
+        this->template SetNextOutput<OutputImageType>(output);
+      }
     }
-    break;
-  case 7: // Difference
-    while (!it1.IsAtEnd()) {
-      it1.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get()-(double)it2.Get())); 
-      ++it1; ++it2;
+  }
+  //--------------------------------------------------------------------
+
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  template<class Iter1, class Iter2, class Iter3>
+  void  ImageArithmGenericFilter<args_info_type>::ComputeImage(Iter1 it1, Iter2 it2, Iter3 ito) {
+    it1.GoToBegin();  
+    it2.GoToBegin();  
+    ito.GoToBegin();
+    typedef typename Iter3::PixelType PixelType;
+    
+    switch (mTypeOfOperation) {
+    case 0: // Addition
+      while (!ito.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() + (double)it2.Get()) ); 
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 1: // Multiply
+      while (!ito.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() * (double)it2.Get()) ); 
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 2: // Divide
+      while (!ito.IsAtEnd()) {
+        if (it1.Get() != 0)
+          ito.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get() / (double)it2.Get())); 
+        else ito.Set(mDefaultPixelValue);
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 3: // Max 
+      while (!ito.IsAtEnd()) {
+        if (it1.Get() < it2.Get()) ito.Set(PixelTypeDownCast<double, PixelType>(it2.Get())); 
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 4: // Min
+      while (!ito.IsAtEnd()) {
+        if (it1.Get() > it2.Get()) ito.Set(PixelTypeDownCast<double, PixelType>(it2.Get())); 
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 5: // Absolute difference
+      while (!ito.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>(fabs(it2.Get()-it1.Get()))); 
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 6: // Squared differences
+      while (!ito.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>(pow((double)it1.Get()-(double)it2.Get(),2))); 
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 7: // Difference
+      while (!ito.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>((double)it1.Get()-(double)it2.Get())); 
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    case 8: // Relative Difference
+      while (!ito.IsAtEnd()) {
+        if (it1.Get() != 0) ito.Set(PixelTypeDownCast<double, PixelType>(((double)it1.Get()-(double)it2.Get()))/(double)it1.Get()); 
+        else ito.Set(0.0);
+        ++it1; ++it2; ++ito;
+      }
+      break;
+    default: // error ?
+      std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl;
+      exit(-1);
     }
-    break;
-  case 8: // Relative Difference
-    while (!it1.IsAtEnd()) {
-      if (it1.Get() != 0) it1.Set(PixelTypeDownCast<double, PixelType>(((double)it1.Get()-(double)it2.Get()))/(double)it1.Get()); 
-      else it1.Set(0.0);
-      ++it1; ++it2;
+  }
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  template<class Iter1, class Iter2>
+  void clitk::ImageArithmGenericFilter<args_info_type>::ComputeImage(Iter1 it, Iter2 ito) {
+    ito.GoToBegin();
+    it.GoToBegin();  
+    typedef typename Iter2::PixelType PixelType;
+
+    // Perform operation
+    switch (mTypeOfOperation) {
+    case 0: // Addition
+      while (!it.IsAtEnd()) {
+        ito.Set(clitk::PixelTypeDownCast<double, PixelType>((double)it.Get() + mScalar) ); 
+        ++it; ++ito;
+      }
+      break;
+    case 1: // Multiply
+      while (!it.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>((double)it.Get() * mScalar) ); 
+        ++it; ++ito;
+      }
+      break;
+    case 2: // Inverse
+      while (!it.IsAtEnd()) {
+        if (it.Get() != 0)
+          ito.Set(PixelTypeDownCast<double, PixelType>(mScalar / (double)it.Get())); 
+        else ito.Set(mDefaultPixelValue);
+        ++it; ++ito;
+      }
+      break;
+    case 3: // Max 
+      while (!it.IsAtEnd()) {
+        if (it.Get() < mScalar) ito.Set(PixelTypeDownCast<double, PixelType>(mScalar)); 
+        ++it; ++ito;
+      }
+      break;
+    case 4: // Min
+      while (!it.IsAtEnd()) {
+        if (it.Get() > mScalar) ito.Set(PixelTypeDownCast<double, PixelType>(mScalar)); 
+        ++it; ++ito;
+      }
+      break;
+    case 5: // Absolute value 
+      while (!it.IsAtEnd()) {
+        if (it.Get() <= 0) ito.Set(PixelTypeDownCast<double, PixelType>(-it.Get())); 
+        // <= zero to avoid warning for unsigned types
+        ++it; ++ito;
+      }
+      break;
+    case 6: // Squared value
+      while (!it.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>((double)it.Get()*(double)it.Get())); 
+        ++it; ++ito;
+      }
+      break;
+    case 7: // Log
+      while (!it.IsAtEnd()) {
+        if (it.Get() > 0) 
+          ito.Set(PixelTypeDownCast<double, PixelType>(log((double)it.Get()))); 
+        else ito.Set(mDefaultPixelValue);
+        ++it; ++ito;
+      }
+      break;
+    case 8: // exp
+      while (!it.IsAtEnd()) {
+        ito.Set(PixelTypeDownCast<double, PixelType>(exp((double)it.Get()))); 
+        ++it; ++ito;
+      }
+      break;
+    case 9: // sqrt
+      while (!it.IsAtEnd()) {
+        if (it.Get() > 0) 
+          ito.Set(PixelTypeDownCast<double, PixelType>(sqrt((double)it.Get()))); 
+        else {
+          if (it.Get() ==0) ito.Set(0);
+          else ito.Set(mDefaultPixelValue);
+        }
+        ++it; ++ito;
+      }
+      break;
+    default: // error ?
+      std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl;
+      exit(-1);
     }
-    break;
-  default: // error ?
-    std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl;
-    exit(-1);
   }
+  //--------------------------------------------------------------------
 
-  return inputImage1;
-}
-//--------------------------------------------------------------------
+} // end namespace
 
 #endif  //#define CLITKIMAGEARITHMGENERICFILTER_TXX
index 7302cbee6120c560ce7684e645457b8d21c163c3..ac9d0c57060e962d258e9df848021d73858ad629 100644 (file)
@@ -45,6 +45,7 @@ clitk::ImageResampleGenericFilter::ImageResampleGenericFilter():
 template<unsigned int Dim>
 void clitk::ImageResampleGenericFilter::InitializeImageTypeWithDim() {      
   ADD_IMAGE_TYPE(Dim, char);
+  ADD_IMAGE_TYPE(Dim, unsigned char);
   ADD_IMAGE_TYPE(Dim, short);
   ADD_IMAGE_TYPE(Dim, int);
   ADD_IMAGE_TYPE(Dim, float);
index e4f561fa6a712d1555de5306b2696c8e217c08e2..bd7eb8a2f03154c83878bff2bbfe37f687b78a9e 100644 (file)
@@ -24,9 +24,6 @@ TARGET_LINK_LIBRARIES(clitkImageResample clitkCommon ITKIO clitkFilters)
 ADD_EXECUTABLE(clitkVFResample clitkVFResample.cxx   clitkImageResample_ggo.c)
 TARGET_LINK_LIBRARIES(clitkVFResample clitkCommon ITKIO clitkFilters)
 
-ADD_EXECUTABLE(clitkImageArithm clitkImageArithm.cxx   clitkImageArithm_ggo.c)
-TARGET_LINK_LIBRARIES(clitkImageArithm clitkCommon ITKIO ITKStatistics clitkFilters)
-
 ADD_EXECUTABLE(clitkImageCreate clitkImageCreate.cxx clitkImageCreate_ggo.c)
 TARGET_LINK_LIBRARIES(clitkImageCreate clitkCommon ITKStatistics ITKIO)
 
@@ -77,5 +74,8 @@ ADD_EXECUTABLE(clitkGuerreroVentilation clitkGuerreroVentilation.cxx
 TARGET_LINK_LIBRARIES(clitkGuerreroVentilation clitkCommon ITKIO ITKBasicFilters
 clitkFilters)
 
+ADD_EXECUTABLE(clitkImageArithm clitkImageArithm.cxx)
+TARGET_LINK_LIBRARIES(clitkImageArithm clitkCommon ITKIO ITKStatistics clitkFilters)
+
 ADD_EXECUTABLE(clitkBinarizeImage clitkBinarizeImage.cxx)
 TARGET_LINK_LIBRARIES(clitkBinarizeImage clitkCommon ITKIO clitkFilters) 
index ce10a07385bdef2620956602f68f30ccd2a33ba2..114bf83f171c2a1f66d98035bf51175956a4e498 100644 (file)
@@ -31,8 +31,8 @@ int main(int argc, char * argv[]) {
   CLITK_INIT;
 
   // Filter
-  clitk::BinarizeImageGenericFilter<args_info_clitkBinarizeImage>::Pointer filter = 
-    clitk::BinarizeImageGenericFilter<args_info_clitkBinarizeImage>::New();
+  typedef clitk::BinarizeImageGenericFilter<args_info_clitkBinarizeImage> FilterType;
+  FilterType::Pointer filter = FilterType::New();
   
   filter->SetArgsInfo(args_info);
   filter->Update();
index 0b7b36e6bb47b90188b2f7a62b458980f372d14f..24e374844838dd8163a6b9bfab33746d6c84403a 100644 (file)
 // clitk include
 #include "clitkImageArithm_ggo.h"
 #include "clitkImageArithmGenericFilter.h"
-#include "clitkIO.h"
 
 //--------------------------------------------------------------------
 int main(int argc, char * argv[]) {
 
   // Init command line
   GGO(clitkImageArithm, args_info);
-  CLITK_INIT;
 
-  // Check that we have either the 2nd image or the scalar 
-  if ((args_info.input2_given) && (args_info.scalar_given)) {
-    std::cerr << "ERROR : you cannot provide both --scalar and --input2 option" << std::endl;
-    exit(-1);
-  }
-  if ((!args_info.input2_given) && (!args_info.scalar_given)) {
-    if (args_info.operation_arg < 5) {
-      std::cerr << "Such operation need the --scalar option." << std::endl;
-      exit(-1);
-    }
-  }
-  
-  // Read input image header1 to check image dimension
-  itk::ImageIOBase::Pointer header1 = clitk::readImageHeader(args_info.input1_arg);
-  unsigned int dim1 = header1->GetNumberOfDimensions();
-  std::string pixelTypeName = header1->GetComponentTypeAsString(header1->GetComponentType());
-
-  // Options for arithm operation between 2 images
-  if (args_info.input2_given) {
-
-    itk::ImageIOBase::Pointer header2 = clitk::readImageHeader(args_info.input2_arg);
-    unsigned int dim2 = header2->GetNumberOfDimensions();
-    std::string pixelTypeName2 = header2->GetComponentTypeAsString(header1->GetComponentType());
-    
-    // Check dimension
-    if (dim1 != dim2) {
-      std::cerr << "Images should have the same dimension : " <<std::endl;
-      std::cerr  << "Dim input1 = " << dim1 << std::endl;
-      std::cerr  << "Dim input2 = " << dim2 << std::endl;
-      exit(-1);
-    }
-
-    // Check same type of pixel in both images
-    if (pixelTypeName2 != pixelTypeName) {
-      std::cerr << "Input images do not have the same pixel type: " <<std::endl;
-      std::cerr  << "Type input1 = " << pixelTypeName << std::endl;
-      std::cerr  << "Type input2 = " << pixelTypeName2 << std::endl;
-      exit(-1);
-    }
-    
-    // Check same X,Y dimensions in both images
-    for(int i=0; i<2; i++) {
-      if ( header1->GetDimensions(i) != header2->GetDimensions(i) ) {
-       std::cerr << "ERROR: input images should have same X and Y size. " <<  std::endl;
-       std::cerr << "Dimensions X and Y of input1: = " << header1->GetDimensions(0) <<"  "<< header1->GetDimensions(1)<< std::endl;
-       std::cerr << "Dimensions X and Y of input2: = " << header2->GetDimensions(0) <<"  "<< header2->GetDimensions(1)<< std::endl;
-       exit(-1);
-      }      
-    }//end for
-    if (dim1 == 3) {
-      if (header1->GetDimensions(2) < header2->GetDimensions(2)) {
-       std::cerr << "ERROR: Z size in input1 is greater than in input2. " <<  std::endl;
-       std::cerr << "Size input1 : " << header1->GetDimensions(0) << " " << header1->GetDimensions(1)<< " " << header1->GetDimensions(2) << std::endl;
-       std::cerr << "Size input2 : " << header2->GetDimensions(0) << " " << header2->GetDimensions(1)<< " " << header2->GetDimensions(2) << std::endl;
-      }
-    }
-  } //end if operation between 2 images        
-  
   // Creation of a generic filter
-  clitk::ImageArithmGenericFilter::Pointer filter = clitk::ImageArithmGenericFilter::New();
-  filter->AddInputFilename(args_info.input1_arg);
-  if (args_info.input2_given) filter->AddInputFilename(args_info.input2_arg);
-  else filter->SetScalar(args_info.scalar_arg);
-  //if (args_info.binary_given) filter->SetBinaryMaskFilename(args_info.binary_arg);   
-  filter->SetTypeOfOperation(args_info.operation_arg);   
-  filter->SetDefaultPixelValue(args_info.pixelValue_arg);
-  filter->SetOutputFilename(args_info.output_arg);
+  typedef clitk::ImageArithmGenericFilter<args_info_clitkImageArithm> FilterType;
+  FilterType::Pointer filter = FilterType::New();
 
-  // Go ! 
+  // Go !
+  filter->SetArgsInfo(args_info);
   filter->Update();
-
+  
   // this is the end my friend  
-  return 0;
+  return EXIT_SUCCESS;
 } // end main
 
 #endif //define CLITKIMAGEARITHM_CXX
index b50d8892c0b6bae2ad926e5c29d624409657813f..9d9c89fd0f742596a2ff52b520b6d43811c3289a 100644 (file)
@@ -110,6 +110,7 @@ SET(vv_SRCS
   vvToolSimpleInputSelectorWidget.cxx
   vvToolInputSelectorWidget.cxx
   vvImageContour.cxx
+  vvToolImageArithm.cxx
   )
 
 QT4_WRAP_CPP(vv_SRCS 
@@ -139,6 +140,7 @@ QT4_WRAP_CPP(vv_SRCS
   vvToolInputSelectorWidget.h
   vvToolWidgetBase.h
   vvToolCropImage.h
+  vvToolImageArithm.h
   )
 
 QT4_WRAP_UI(vv_UI_CXX 
@@ -158,12 +160,13 @@ QT4_WRAP_UI(vv_UI_CXX
   qt_ui/vvStructSelector.ui
   qt_ui/vvDummyWindow.ui #For testing
   qt_ui/vvIntensityValueSlider.ui
+  qt_ui/vvToolSimpleInputSelectorWidget.ui
+  qt_ui/vvToolInputSelectorWidget.ui
   qt_ui/vvToolWidgetBase.ui
 #  qt_ui/vvToolFoo.ui
   qt_ui/vvToolCropImage.ui
   qt_ui/vvToolBinarize.ui
-  qt_ui/vvToolSimpleInputSelectorWidget.ui
-  qt_ui/vvToolInputSelectorWidget.ui
+  qt_ui/vvToolImageArithm.ui
   )
 
 SET(vvUI_RCCS vvIcons.qrc)
index 449c9deac2a121a4ad7857bdfe989ee9938bc767..8fafb50cc038a90ed4fc8d4f88ee5c4d9e07abc0 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>573</width>
-    <height>125</height>
+    <width>407</width>
+    <height>82</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -18,7 +18,7 @@
     <number>0</number>
    </property>
    <item row="0" column="0">
-    <widget class="QGroupBox" name="groupBox">
+    <widget class="QGroupBox" name="mGroupBox">
      <property name="font">
       <font>
        <weight>75</weight>
          <item row="0" column="0">
           <layout class="QHBoxLayout" name="horizontalLayout_2">
            <item>
-            <widget class="QGroupBox" name="groupBox_2">
-             <property name="font">
-              <font>
-               <weight>50</weight>
-               <bold>false</bold>
-              </font>
-             </property>
-             <property name="title">
-              <string>Already open</string>
-             </property>
-             <layout class="QGridLayout" name="gridLayout">
-              <property name="margin">
-               <number>1</number>
-              </property>
-              <item row="0" column="0">
-               <widget class="QComboBox" name="mInputSequenceBox">
-                <property name="font">
-                 <font>
-                  <pointsize>11</pointsize>
-                  <weight>50</weight>
-                  <bold>false</bold>
-                 </font>
-                </property>
-                <item>
-                 <property name="text">
-                  <string>Bidon image number 1</string>
-                 </property>
-                </item>
-               </widget>
-              </item>
-             </layout>
-            </widget>
-           </item>
-           <item>
-            <widget class="QRadioButton" name="mRadioButtonLowerThan">
-             <property name="font">
-              <font>
-               <weight>50</weight>
-               <bold>false</bold>
-              </font>
-             </property>
-             <property name="text">
-              <string>OR</string>
-             </property>
-             <property name="autoExclusive">
-              <bool>false</bool>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QGroupBox" name="groupBox_3">
+            <widget class="QComboBox" name="mInputSequenceBox">
              <property name="enabled">
-              <bool>false</bool>
+              <bool>true</bool>
              </property>
              <property name="font">
               <font>
+               <pointsize>11</pointsize>
                <weight>50</weight>
                <bold>false</bold>
               </font>
              </property>
-             <property name="title">
-              <string>Open a new file</string>
-             </property>
-             <layout class="QHBoxLayout" name="horizontalLayout_4">
-              <property name="leftMargin">
-               <number>3</number>
-              </property>
-              <property name="topMargin">
-               <number>3</number>
-              </property>
-              <property name="rightMargin">
-               <number>3</number>
-              </property>
-              <property name="bottomMargin">
-               <number>1</number>
+             <item>
+              <property name="text">
+               <string>Bidon image number 1</string>
               </property>
-              <item>
-               <widget class="QLabel" name="label_2">
-                <property name="text">
-                 <string>Or open a new one</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QToolButton" name="toolButton">
-                <property name="text">
-                 <string>...</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QLineEdit" name="lineEdit">
-                <property name="text">
-                 <string>/home/toto/truc.mhd</string>
-                </property>
-               </widget>
-              </item>
-             </layout>
+             </item>
             </widget>
            </item>
           </layout>
               <enum>QFrame::NoFrame</enum>
              </property>
              <property name="text">
-              <string>3D image Pixel type short bla bla</string>
+              <string>No selected image</string>
              </property>
             </widget>
            </item>
   </layout>
  </widget>
  <resources/>
- <connections>
-  <connection>
-   <sender>mRadioButtonLowerThan</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>groupBox_3</receiver>
-   <slot>setEnabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>296</x>
-     <y>102</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>528</x>
-     <y>122</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>mRadioButtonLowerThan</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>mInputSequenceBox</receiver>
-   <slot>setDisabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>269</x>
-     <y>93</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>214</x>
-     <y>93</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <connections/>
 </ui>
index 567b595e258e1dad4faa07efbabba4fe66aa02c4..7cfdbed051255642025a656e7f705fda6f2a6205 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>615</width>
-    <height>372</height>
+    <width>178</width>
+    <height>61</height>
    </rect>
   </property>
   <property name="windowTitle">
index 1dbd8e4575fadbeeccfd645091ec3b147139c442..36b7db0c9c18e4b7cfa7f34f19e7b99a082eecb4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvMainWindow.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/10 15:36:26 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.17 $
   Author :   Pierre Seroul (pierre.seroul@gmail.com)
 
   Copyright (C) 200COLUMN_IMAGE_NAME
@@ -439,7 +439,7 @@ void vvMainWindow::OpenDCStructContour()
 {
   if (mSlicerManagers.size() > 0)
     {
-      QString Extensions = "Dicom Files ( *.dcm)";
+      QString Extensions = "Dicom Files ( *.dcm; RS*)";
       Extensions += ";;All Files (*)";
       QString file = QFileDialog::getOpenFileName(this,tr("Merge Images"),mInputPathName,Extensions);
       if (file.isNull())
index 343350ce2731a40dcf2c95ecabfbeff21c2566ea..42154e3e27bffce3c9b76d06cb4c9abc4db69ed6 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolBinarize.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:22:18 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.13 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2008
@@ -79,7 +79,7 @@ vvToolBinarize::vvToolBinarize(vvMainWindowBase * parent, Qt::WindowFlags f)
   mFilter = new clitk::BinarizeImageGenericFilter<args_info_clitkBinarizeImage>;
 
   // Set how many inputs are needed for this tool
-  AddInputSelector(mFilter);
+  AddInputSelector("Select one image", mFilter);
 }
 //------------------------------------------------------------------------------
 
@@ -131,7 +131,7 @@ bool vvToolBinarize::close() {
 
 //------------------------------------------------------------------------------
 void vvToolBinarize::reject() { 
-  DD("vvToolBinarize::reject");
+  // DD("vvToolBinarize::reject");
   RemoveVTKObjects();
   return vvToolWidgetBase::reject(); 
 }
@@ -295,8 +295,9 @@ void vvToolBinarize::apply() {
   // Main filter
   clitk::BinarizeImageGenericFilter<args_info_clitkBinarizeImage>::Pointer filter = 
      clitk::BinarizeImageGenericFilter<args_info_clitkBinarizeImage>::New();
-  filter->SetArgsInfo(mArgsInfo);
   filter->SetInputVVImage(mCurrentImage);
+  filter->SetArgsInfo(mArgsInfo);
+  filter->EnableReadOnDisk(false);
   filter->Update();
 
   // Output
index fbc5a24ee5d841dec6b39e20cf02250bf2145d5f..e6abdfeaed4ad4ac714a25f505940216223ef8a2 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolBinarize.h,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:22:18 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.10 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -49,10 +49,8 @@ class vvToolBinarize:
 
   //-----------------------------------------------------
   static void Initialize();
-  void InputIsSet(bool b);
   void GetArgsInfoFromGUI();
   virtual void InputIsSelected(vvSlicerManager * m);
-  //  virtual void InputIsSelected(std::vector<vvSlicerManager *> & m);
 
   //-----------------------------------------------------
   public slots:
index b50e332c6cfc1bf1e9156ace449fd9eb7c7fe36b..c9a0c0d853bc47ff215f3a20f91089a313be3e75 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolCropImage.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:22:18 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.5 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2008
@@ -52,7 +52,7 @@ vvToolCropImage::vvToolCropImage(vvMainWindowBase * parent, Qt::WindowFlags f):
   Ui_vvToolCropImage::setupUi(mToolWidget);
 
   // Set how many inputs are needed for this tool
-  AddInputSelector();
+  AddInputSelector("Select one image");
 }
 //------------------------------------------------------------------------------
 
index 638ca0afa5667084d987286ac093c16eec0cd1ad..23adc9d6b9ff92f0ea706090d3278b90bcd50448 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolFooWithWidgetBase.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/01 08:37:19 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.2 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -62,7 +62,7 @@ void vvToolFooWithWidgetBase::Initialize() {
 
 //------------------------------------------------------------------------------
 void vvToolFooWithWidgetBase::InputIsSelected(vvSlicerManager *m) {
-  mButton->setText(m->GetFileName().c_str());
+  
 }
 //------------------------------------------------------------------------------
 
index e549e9b9669805bac5b913c5c689bf681138df76..77340dee7b358eb473292bad36bad71217d8526b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolFooWithWidgetBase.h,v $
   Language:  C++
-  Date:      $Date: 2010/03/01 08:37:19 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.2 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -29,7 +29,6 @@
 #define VVTOOLFOO_H
 
 #include <QtDesigner/QDesignerExportWidget>
-#include <QDialog>
 
 #include "vvToolBase.h"
 #include "vvToolWidgetBase.h"
@@ -48,6 +47,7 @@ class vvToolFooWithWidgetBase:
 
   static void Initialize();
   virtual void InputIsSelected(vvSlicerManager *m);
+  //  OR ===> virtual void InputIsSelected(std::vector<vvSlicerManager *> & m);
 
 public slots:
   virtual void apply();
index 257966013c7fdb011685f108f9fa2d2ba245bbdb..1542c4bbc82111998988e5c5b378e690937a4bfa 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolInputSelectorWidget.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:22:18 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.5 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -49,12 +49,19 @@ int vvToolInputSelectorWidget::GetNumberOfInput() {
 
 
 //------------------------------------------------------------------------------
-void vvToolInputSelectorWidget::AddInputSelector(const std::vector<vvSlicerManager*> & l, int index) {
-  DD("ICICICICICICICIC AddInputSelector ADD layout");
-  DD(index);
-  DD(l.size());
+void vvToolInputSelectorWidget::AddInputSelector(QString & s, 
+                                                const std::vector<vvSlicerManager*> & l, 
+                                                int index, 
+                                                bool allowSkip) {
+  //  DD("ICICICICICICICIC AddInputSelector ADD layout");
+  //  DD(index);
+  //DD(l.size());
   vvToolSimpleInputSelectorWidget * input = new vvToolSimpleInputSelectorWidget;
   mListOfSimpleInputWidget.push_back(input);
+  mSkipInput.push_back(false);
+  
+  input->SetText(s);
+  input->EnableAllowSkip(allowSkip);
 
   // copy list
   std::vector<vvSlicerManager*> * ll = new std::vector<vvSlicerManager*>;
@@ -69,11 +76,12 @@ void vvToolInputSelectorWidget::AddInputSelector(const std::vector<vvSlicerManag
   // Enable or disable
   if (GetNumberOfInput() == 1) input->setEnabled(true);
   else input->setEnabled(false);
-  DD(GetNumberOfInput());
+  //DD(GetNumberOfInput());
 
   // Connect signals & slots  
   connect(input, SIGNAL(accepted()), this, SLOT(accept()));
   connect(input, SIGNAL(rejected()), this, SLOT(reject()));  
+  connect(input, SIGNAL(sigskip()), this, SLOT(skip()));  
 }
 //------------------------------------------------------------------------------
 
@@ -88,19 +96,19 @@ void vvToolInputSelectorWidget::Initialize() {
 
 //------------------------------------------------------------------------------
 void vvToolInputSelectorWidget::accept() {
-  DD("vvToolInputSelectorWidget::accept");
-  DD(mNumberOfAcceptedInputs);
+  //  DD("vvToolInputSelectorWidget::accept");
+  //DD(mNumberOfAcceptedInputs);
   mNumberOfAcceptedInputs++;
   if (mNumberOfAcceptedInputs == GetNumberOfInput()) {
     setEnabled(false);
     emit accepted();
   }
   else {
-    DD("accepted");
+    //DD("accepted");
     //    for(unsigned int i=mNumberOfAcceptedInputs; i<mListOfSimpleInputWidget.size(); i++) {
-      //      mListOfSimpleInputWidget[i]->Initialize();
-      mListOfSimpleInputWidget[mNumberOfAcceptedInputs]->setEnabled(true);
-      //}
+    //      mListOfSimpleInputWidget[i]->Initialize();
+    mListOfSimpleInputWidget[mNumberOfAcceptedInputs]->setEnabled(true);
+    //}
   }
 }
 //------------------------------------------------------------------------------
@@ -108,11 +116,11 @@ void vvToolInputSelectorWidget::accept() {
 
 //------------------------------------------------------------------------------
 void vvToolInputSelectorWidget::reject() {
-  DD("vvToolInputSelectorWidget::reject");
+  //  DD("vvToolInputSelectorWidget::reject");
   if (mNumberOfAcceptedInputs != 0)  {
     //    for(unsigned int i=mNumberOfAcceptedInputs; i<mListOfSimpleInputWidget.size(); i++) {
     //      mListOfSimpleInputWidget[i]->Initialize();
-    DD(mNumberOfAcceptedInputs);
+    //    DD(mNumberOfAcceptedInputs);
     mListOfSimpleInputWidget[mNumberOfAcceptedInputs]->setEnabled(false);
     mListOfSimpleInputWidget[mNumberOfAcceptedInputs-1]->setEnabled(true);
     mNumberOfAcceptedInputs--;
@@ -125,11 +133,22 @@ void vvToolInputSelectorWidget::reject() {
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvToolInputSelectorWidget::skip() {
+  DD("SKIP");
+  mSkipInput[mNumberOfAcceptedInputs] = true;
+  accept();//mNumberOfAcceptedInputs++;
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 std::vector<vvSlicerManager*> & vvToolInputSelectorWidget::GetSelectedInputs() {
   std::vector<vvSlicerManager*> * l = new std::vector<vvSlicerManager*>;
-  for(unsigned int i=0; i<mListOfSimpleInputWidget.size(); i++)
-    l->push_back(mListOfSimpleInputWidget[i]->GetSelectedInput());
+  for(unsigned int i=0; i<mListOfSimpleInputWidget.size(); i++) {
+    if (!mSkipInput[i])
+      l->push_back(mListOfSimpleInputWidget[i]->GetSelectedInput());
+  }
   return *l;
 }
 //------------------------------------------------------------------------------
@@ -137,7 +156,7 @@ std::vector<vvSlicerManager*> & vvToolInputSelectorWidget::GetSelectedInputs() {
 
 //------------------------------------------------------------------------------
 void vvToolInputSelectorWidget::AnImageIsBeingClosed(vvSlicerManager * m) {
-  DD("TODO : verify that the image still exist !!");
+  //  DD("TODO : verify that the image still exist !!");
   //  for(int i=0; i<
 }
 //------------------------------------------------------------------------------
index 8aef39d188ed3d40c53f7561574ce2dd61b60e68..f9f5a0bedeb4204f08a1e4723ab356763da52d62 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolInputSelectorWidget.h,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:22:18 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.6 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -43,7 +43,7 @@ class vvToolInputSelectorWidget: public QWidget, private Ui::vvToolInputSelector
   vvToolInputSelectorWidget(QWidget * parent=0, Qt::WindowFlags f=0);
   ~vvToolInputSelectorWidget() {}
   
-  void AddInputSelector(const std::vector<vvSlicerManager*> & l, int index);  
+  void AddInputSelector(QString & s, const std::vector<vvSlicerManager*> & l, int index, bool allowSkip=false);  
   void Initialize();
   std::vector<vvSlicerManager*> & GetSelectedInputs();
   void AnImageIsBeingClosed(vvSlicerManager * m);
@@ -52,6 +52,7 @@ class vvToolInputSelectorWidget: public QWidget, private Ui::vvToolInputSelector
  public slots:
   void accept(); // to change ! in something like acceptOneMoreInput
   void reject();
+  void skip();
 
  signals:
   void accepted();
@@ -66,6 +67,7 @@ class vvToolInputSelectorWidget: public QWidget, private Ui::vvToolInputSelector
   vvSlicerManager * mCurrentSliceManager;
   int mNumberOfAcceptedInputs;
   std::vector<vvToolSimpleInputSelectorWidget *> mListOfSimpleInputWidget;
+  std::vector<bool> mSkipInput;
 }; // end class vvToolInputSelectorWidget
 //------------------------------------------------------------------------------
 
index 70700fc93c975d83da9255197820e95fa123a157..fcc1361814f36939f679258bd3e6650f3367732b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolSimpleInputSelectorWidget.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:23:46 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.2 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -30,6 +30,7 @@
 
 #include "vvToolSimpleInputSelectorWidget.h"
 #include "vvSlicerManager.h"
+#include <QAbstractButton>
 
 //------------------------------------------------------------------------------
 vvToolSimpleInputSelectorWidget::vvToolSimpleInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
@@ -47,20 +48,36 @@ void vvToolSimpleInputSelectorWidget::Initialize() {
   connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
   connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
   connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int)));  
-  DD("vvToolSimpleInputSelectorWidget::Initialize");
-  DD(mSlicerManagerList.size());
+  changeInput(0);
   if (mSlicerManagerList.size() == 1) {
-    DD("Initialize::accept");
-    accept();
+    if (!mAllowSkip) accept();
   }
 }
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvToolSimpleInputSelectorWidget::SetText(QString & s) {
+  mGroupBox->setTitle(s);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolSimpleInputSelectorWidget::EnableAllowSkip(bool b) {
+  mAllowSkip = b;
+  if (mAllowSkip) {
+    mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Discard);
+    connect(mInputSelectionButtonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(skip(QAbstractButton*)));
+  }
+  else 
+    mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvToolSimpleInputSelectorWidget::SetInputList(const std::vector<vvSlicerManager*> & l, int index) {
-  DD("vvToolSimpleInputSelectorWidget::SetInputList");
-  DD(index);
   mInputSequenceBox->clear();
   for(unsigned int i=0; i<l.size(); i++)
     mSlicerManagerList.push_back(l[i]);
@@ -96,18 +113,23 @@ void vvToolSimpleInputSelectorWidget::accept() {
 //------------------------------------------------------------------------------
 
 
+
 //------------------------------------------------------------------------------
 void vvToolSimpleInputSelectorWidget::reject() {
-  DD("vvToolSimpleInputSelectorWidget::reject()");
   emit rejected();
 }
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvToolSimpleInputSelectorWidget::skip(QAbstractButton* b) {
+  if (b->text() == "Discard") emit sigskip();
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvToolSimpleInputSelectorWidget::changeInput(int index) {
-  DD("changeInput");
-  DD(index);
   if (index<0) return;
   mCurrentIndex = index;
   vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
index 4410b0d910dec4d1ec0edde1c8ea772ed82530c7..bde29c8c1806f61e30cd0a30f37eb34718104f14 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolSimpleInputSelectorWidget.h,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:23:45 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.2 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -46,15 +46,19 @@ class vvToolSimpleInputSelectorWidget: public QWidget, private Ui::vvToolSimpleI
   void Initialize();
   int GetSelectedInputIndex() { return mCurrentIndex; }
   vvSlicerManager * GetSelectedInput();
+  void SetText(QString & s);
+  void EnableAllowSkip(bool b);
 
  public slots:
   void accept();
   void reject();
   void setEnabled(bool b);
+  void skip(QAbstractButton*);
 
  signals:
   void accepted();
   void rejected();
+  void sigskip();
 
  protected slots:
   void changeInput(int i);
@@ -64,6 +68,7 @@ class vvToolSimpleInputSelectorWidget: public QWidget, private Ui::vvToolSimpleI
   std::vector<vvSlicerManager*> mSlicerManagerList;
   int mCurrentIndex;
   vvSlicerManager * mCurrentSliceManager;
+  bool mAllowSkip;
 
 }; // end class vvToolSimpleInputSelectorWidget
 //------------------------------------------------------------------------------
index e08d54f9b3b6ef85a1cb38f497b84d2caefe38a3..28270dca5a13aa5a5d8a089ca2fe6e45a4eebf54 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolWidgetBase.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:22:18 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.4 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2008
@@ -28,6 +28,7 @@
 #include "vvToolWidgetBase.h"
 #include "vvMainWindowBase.h"
 #include "vvSlicerManager.h"
+#include <QMessageBox>
 
 //------------------------------------------------------------------------------
 vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f)
@@ -77,15 +78,15 @@ vvToolWidgetBase::~vvToolWidgetBase() {
 
 
 //------------------------------------------------------------------------------
-void vvToolWidgetBase::AddInputSelector(clitk::ImageToImageGenericFilterBase * f) {
-  DD("AddInputSelector with filter");
-  DD(mMainWindowBase->GetSlicerManagers().size());
+void vvToolWidgetBase::AddInputSelector(QString s, clitk::ImageToImageGenericFilterBase * f, bool allowSkip) {
+  // DD("AddInputSelector with filter");
+  //   DD(mMainWindowBase->GetSlicerManagers().size());
   int j=0;
   mFilter = f;
   mSlicerManagersCompatible.clear();
   //  mToolInputSelectionWidget->setToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str()));
   for(unsigned int i=0; i<mMainWindowBase->GetSlicerManagers().size(); i++) {
-    DD(i);
+    // DD(i);
     vvImage * s = mMainWindowBase->GetSlicerManagers()[i]->GetImage();
     if (mFilter->CheckImageType(s->GetNumberOfDimensions(), 
                                s->GetNumberOfScalarComponents(), 
@@ -95,40 +96,50 @@ void vvToolWidgetBase::AddInputSelector(clitk::ImageToImageGenericFilterBase * f
       j++;
     }
   }
-  mToolInputSelectionWidget->AddInputSelector(mSlicerManagersCompatible, mCurrentCompatibleIndex);
+  if (mSlicerManagersCompatible.size() == 0) {
+    QMessageBox::information(this, "No image","Sorry, could not perform operation. No compatible opened image type.");
+    close();
+    return;
+  }
+  mToolInputSelectionWidget->AddInputSelector(s, mSlicerManagersCompatible, mCurrentCompatibleIndex, allowSkip);
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvToolWidgetBase::AddInputSelector() {
-  DD("AddInput without filter");
-  DD(mMainWindowBase->GetSlicerManagers().size());
+void vvToolWidgetBase::AddInputSelector(QString s, bool allowSkip) {
+  // DD("AddInput without filter");
+  //   DD(mMainWindowBase->GetSlicerManagers().size());
   mSlicerManagersCompatible.clear();
   for(unsigned int i=0; i<mMainWindowBase->GetSlicerManagers().size(); i++) {
     mSlicerManagersCompatible.push_back(mMainWindowBase->GetSlicerManagers()[i]);
   }
-  mToolInputSelectionWidget->AddInputSelector(mMainWindowBase->GetSlicerManagers(),
-                                             mMainWindowBase->GetSlicerManagerCurrentIndex());
+  if (mMainWindowBase->GetSlicerManagers().size() == 0) {
+    QMessageBox::information(this, "No image","Sorry, could not perform operation. No opened image type.");
+    close();
+    return;
+  }
+  mToolInputSelectionWidget->AddInputSelector(s, mMainWindowBase->GetSlicerManagers(),
+                                             mMainWindowBase->GetSlicerManagerCurrentIndex(), allowSkip);
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
 void vvToolWidgetBase::show() {
- if (!mIsInitialized) {
-   DD("show -> init");
-   mToolInputSelectionWidget->Initialize();
-   mIsInitialized = true;
- }
- QDialog::show();
 if (!mIsInitialized) {
+    //  DD("show -> init");
+    mToolInputSelectionWidget->Initialize();
+    mIsInitialized = true;
 }
 QDialog::show();
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
 bool vvToolWidgetBase::close() {
-  DD("vvToolWidgetBase::close()");
+  // DD("vvToolWidgetBase::close()");
   return QDialog::close();
 }
 //------------------------------------------------------------------------------
@@ -136,7 +147,7 @@ bool vvToolWidgetBase::close() {
 
 //------------------------------------------------------------------------------
 void vvToolWidgetBase::AnImageIsBeingClosed(vvSlicerManager * m) {
-   mToolInputSelectionWidget->AnImageIsBeingClosed(m);
+  mToolInputSelectionWidget->AnImageIsBeingClosed(m);
   if (m == mCurrentSlicerManager) {
     close();
   }
@@ -147,27 +158,27 @@ void vvToolWidgetBase::AnImageIsBeingClosed(vvSlicerManager * m) {
 //------------------------------------------------------------------------------
 void vvToolWidgetBase::InitializeInputs() {
   /*
-  if (mFilter) {
+    if (mFilter) {
     int j=0;
     mToolInputSelectionWidget->setToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str()));
     for(unsigned int i=0; i<mMainWindowBase->GetSlicerManagers().size(); i++) {
-      vvImage * s = mMainWindowBase->GetSlicerManagers()[i]->GetImage();
-      if (mFilter->CheckImageType(s->GetNumberOfDimensions(), 
-                                 s->GetNumberOfScalarComponents(), 
-                                 s->GetScalarTypeAsString())) {
-       mSlicerManagersCompatible.push_back(mMainWindowBase->GetSlicerManagers()[i]);
-       if ((int)i == mMainWindowBase->GetSlicerManagerCurrentIndex()) mCurrentCompatibleIndex = j;
-       j++;
-      }
+    vvImage * s = mMainWindowBase->GetSlicerManagers()[i]->GetImage();
+    if (mFilter->CheckImageType(s->GetNumberOfDimensions(), 
+    s->GetNumberOfScalarComponents(), 
+    s->GetScalarTypeAsString())) {
+    mSlicerManagersCompatible.push_back(mMainWindowBase->GetSlicerManagers()[i]);
+    if ((int)i == mMainWindowBase->GetSlicerManagerCurrentIndex()) mCurrentCompatibleIndex = j;
+    j++;
     }
-  }
-  else {
+    }
+    }
+    else {
     mSlicerManagersCompatible = mMainWindowBase->GetSlicerManagers();
     mCurrentCompatibleIndex = mMainWindowBase->GetSlicerManagerCurrentIndex();
-  }
-  mToolInputSelectionWidget->Initialize(mSlicerManagersCompatible, 
-                                       mCurrentCompatibleIndex);
-  mIsInitialized = true;
+    }
+    mToolInputSelectionWidget->Initialize(mSlicerManagersCompatible, 
+    mCurrentCompatibleIndex);
+    mIsInitialized = true;
   */
 }
 //------------------------------------------------------------------------------
@@ -183,7 +194,7 @@ void vvToolWidgetBase::InitializeInputs() {
 
 //------------------------------------------------------------------------------
 void vvToolWidgetBase::InputIsSelected() {
-  DD("InputIsSelected");
+  // DD("InputIsSelected");
   buttonBox->setEnabled(true);
   std::vector<vvSlicerManager*> & l = mToolInputSelectionWidget->GetSelectedInputs();
   mCurrentSlicerManager = l[0];
@@ -207,12 +218,12 @@ void vvToolWidgetBase::InputIsSelected(vvSlicerManager * m) {
 //------------------------------------------------------------------------------
 void vvToolWidgetBase::InputIsSelected(std::vector<vvSlicerManager*> & l) {
   buttonBox->setEnabled(true);
-  DD("InputIsSelected(vector)");
-  DD(l.size());
+  // DD("InputIsSelected(vector)");
+  //   DD(l.size());
   if (l.size() == 1) InputIsSelected(l[0]);
   else {
-  std::cerr << "You MUST overwrite this method vvToolWidgetBase::InputIsSelected(vector<vvSlicerManager *> m) if you use several input" << std::endl;
-  exit(0);
+    std::cerr << "You MUST overwrite this method vvToolWidgetBase::InputIsSelected(vector<vvSlicerManager *> m) if you use several input" << std::endl;
+    exit(0);
   }
 }
 //------------------------------------------------------------------------------
index 6f8e23fa92324f1c9a7b20ffb6ebb9000b85fb41..f5aff73f36cfa7a33b610a8c6abd9d0962611e31 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolWidgetBase.h,v $
   Language:  C++
-  Date:      $Date: 2010/03/17 11:22:18 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2010/03/24 10:48:18 $
+  Version:   $Revision: 1.4 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -46,8 +46,8 @@ class vvToolWidgetBase:
 
   virtual void InputIsSelected(vvSlicerManager *m);
   virtual void InputIsSelected(std::vector<vvSlicerManager*> & l);
-  void AddInputSelector(clitk::ImageToImageGenericFilterBase * f);
-  void AddInputSelector();
+  void AddInputSelector(QString s, clitk::ImageToImageGenericFilterBase * f, bool allowSkip=false);
+  void AddInputSelector(QString s, bool allowSkip=false);
 
 public slots:
   virtual void apply() = 0;