]> Creatis software - clitk.git/blobdiff - tools/clitkCropImageGenericFilter.h
add small region
[clitk.git] / tools / clitkCropImageGenericFilter.h
old mode 100755 (executable)
new mode 100644 (file)
index 5347b0b..fef6103
@@ -1,9 +1,9 @@
 /*=========================================================================
   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Authors belong to: 
+  Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-#ifndef clitkCropImageGenericFilter_h
-#define clitkCropImageGenericFilter_h
+===========================================================================**/
 
-/* =================================================
- * @file   clitkCropImageGenericFilter.h
- * @author 
- * @date   
- * 
- * @brief 
- * 
- ===================================================*/
+#ifndef CLITKCROPIMAGEGENERICFILTER_H
+#define CLITKCROPIMAGEGENERICFILTER_H
 
-
-// clitk include
+// clitk
 #include "clitkIO.h"
-#include "clitkCommon.h"
-#include "clitkImageCommon.h"
+#include "clitkImageToImageGenericFilter.h"
+#include "clitkCropLikeImageFilter.h"
+#include "clitkAutoCropFilter.h"
 #include "clitkCropImage_ggo.h"
 
-//itk include
-#include "itkLightObject.h"
-#include "itkCropImageFilter.h"
+// itk
+#include <itkCropImageFilter.h>
 
-namespace clitk 
+//--------------------------------------------------------------------
+namespace clitk
 {
 
-
-  class ITK_EXPORT CropImageGenericFilter : public itk::LightObject
+  class ITK_EXPORT CropImageGenericFilter:
+    public ImageToImageGenericFilter<CropImageGenericFilter>
   {
   public:
-    //----------------------------------------
-    // ITK
-    //----------------------------------------
-    typedef CropImageGenericFilter                   Self;
-    typedef itk::LightObject                   Superclass;
-    typedef itk::SmartPointer<Self>            Pointer;
-    typedef itk::SmartPointer<const Self>      ConstPointer;
-   
-    // Method for creation through the object factory
-    itkNewMacro(Self);  
-
-    // Run-time type information (and related methods)
-    itkTypeMacro( CropImageGenericFilter, LightObject );
-
-
-    //----------------------------------------
-    // Typedefs
-    //----------------------------------------
-
-
-    //----------------------------------------
-    // Set & Get
-    //----------------------------------------    
-    void SetArgsInfo(const args_info_clitkCropImage & a)
-    {
-      m_ArgsInfo=a;
-      m_Verbose=m_ArgsInfo.verbose_flag;
-      m_InputFileName=m_ArgsInfo.input_arg;
-    }
-    
-    
-    //----------------------------------------  
-    // Update
-    //----------------------------------------  
-    void Update();
-
-  protected:
-
-    //----------------------------------------  
-    // Constructor & Destructor
-    //----------------------------------------  
+    //--------------------------------------------------------------------
     CropImageGenericFilter();
-    ~CropImageGenericFilter() {};
-
-    
-    //----------------------------------------  
-    // Templated members
-    //----------------------------------------  
-    template <unsigned int Dimension>  void UpdateWithDim(std::string PixelType, unsigned int Components);
-    template <unsigned int Dimension, class PixelType>  void UpdateWithDimAndPixelType();
 
+    //--------------------------------------------------------------------
+    typedef CropImageGenericFilter   Self;
+    typedef ImageToImageGenericFilter<CropImageGenericFilter> Superclass;
+    typedef itk::SmartPointer<Self>       Pointer;
+    typedef itk::SmartPointer<const Self> ConstPointer;
+    typedef args_info_clitkCropImage       args_info_type;
 
-    //----------------------------------------  
-    // Data members
-    //----------------------------------------
-    args_info_clitkCropImage m_ArgsInfo;
-    bool m_Verbose;
-    std::string m_InputFileName;
+    //--------------------------------------------------------------------
+    itkNewMacro(Self);
+    itkTypeMacro( CropImageGenericFilter, LightObject );
 
-  };
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const args_info_type& a);
 
+    //--------------------------------------------------------------------
+    // Main function called each time the filter is updated
+    template<class ImageType>
+    void UpdateWithInputImageType();
 
+  protected:
+    template <class ImageType>
+    class AutoCrop
+    {
+    public:
+      typedef typename ImageType::Pointer ImagePointer;
+      ImagePointer Do(args_info_type &, ImagePointer);
+    private:
+      template<unsigned int> struct PixelDimType {};
+      template<unsigned int Dim> ImagePointer Do(args_info_type &,ImagePointer, PixelDimType<Dim> *);
+      ImagePointer Do(args_info_type &, ImagePointer, PixelDimType<1> *);
+    };
+
+    template<unsigned int Dim> void InitializeImageType();
+    args_info_type mArgsInfo;
+
+  };// end class
+  //--------------------------------------------------------------------
 } // end namespace clitk
 
-#ifndef ITK_MANUAL_INSTANTIATION
-#include "clitkCropImageGenericFilter.txx"
-#endif
-
-#endif // #define clitkCropImageGenericFilter_h
+#endif // #define CLITKCROPIMAGEGENERICFILTER_H