]> Creatis software - clitk.git/blob - itk/clitkCropLikeImageFilter.h
Change some SetInputData into SetInputConnection to be consistent with algorithm...
[clitk.git] / itk / clitkCropLikeImageFilter.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 #ifndef CLITKCROPLIKEIMAGEFILTER_H
20 #define CLITKCROPLIKEIMAGEFILTER_H
21
22 // clitk
23 #include "clitkBoundingBoxUtils.h"
24
25 // itk
26 #include <itkImageToImageFilter.h>
27
28 namespace clitk {
29   
30   //--------------------------------------------------------------------
31   /*
32     Perform various cropping operation on a image
33   */
34   //--------------------------------------------------------------------
35   
36   template <class ImageType>
37   class ITK_EXPORT CropLikeImageFilter: public itk::ImageToImageFilter<ImageType, ImageType> {
38   public:
39     /** Standard class typedefs. */
40     typedef CropLikeImageFilter                            Self;
41     typedef itk::ImageToImageFilter<ImageType, ImageType>  Superclass;
42     typedef itk::SmartPointer<Self>                        Pointer;
43     typedef itk::SmartPointer<const Self>                  ConstPointer;
44     
45     /** Method for creation through the object factory. */
46     itkNewMacro(Self);
47     
48     /** Run-time type information (and related methods). */
49     itkTypeMacro(CropLikeImageFilter, ImageToImageFilter);
50
51     /** Some convenient typedefs. */
52     typedef typename ImageType::ConstPointer ImageConstPointer;
53     typedef typename ImageType::Pointer      ImagePointer;
54     typedef typename ImageType::PixelType    PixelType;
55     typedef typename ImageType::RegionType   RegionType;
56     typedef typename ImageType::PointType    PointType;
57     typedef typename ImageType::IndexType    IndexType;
58     typedef typename ImageType::SizeType     SizeType;
59
60     /** Image filename for Crop Like */
61     void SetCropLikeFilename(std::string f);
62     void SetCropLikeImage(const itk::ImageBase<ImageType::ImageDimension> * like);
63     void SetCropLikeImage(const itk::ImageBase<ImageType::ImageDimension> * like, int axe);
64
65     // Set Background if 'like' is greater than input
66     itkSetMacro(BackgroundValue, PixelType);
67     itkGetConstMacro(BackgroundValue, PixelType); 
68
69     /** ImageDimension constants */
70     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
71
72     // I dont want to verify inputs information
73     virtual void VerifyInputInformation() { }
74
75   protected:
76     CropLikeImageFilter();
77     virtual ~CropLikeImageFilter() {}
78     
79     virtual void GenerateOutputInformation();
80     virtual void GenerateData();
81     virtual void GenerateInputRequestedRegion();
82     
83     PixelType m_BackgroundValue;
84     RegionType m_OutputRegion;
85     RegionType m_Region;
86     std::string m_LikeFilename;
87     bool m_LikeFilenameIsGiven;
88     PointType m_Origin;
89     const itk::ImageBase<ImageDimension> * m_LikeImage;
90     std::vector<bool> m_CropAlongThisDimension;
91     
92     PointType m_StartPoint;         // start point in physical world
93     IndexType m_StartSourceIndex;   // start index in "source" image 
94     IndexType m_StartDestIndex;     // start index in "destination" image 
95     
96     PointType m_StopPoint;         // stop point in physical world
97     IndexType m_StopSourceIndex;   // stop index in "source" image 
98     IndexType m_StopDestIndex;     // stop index in "destination" image 
99     
100   private:
101     CropLikeImageFilter(const Self&); //purposely not implemented
102     void operator=(const Self&); //purposely not implemented
103     
104   }; // end class
105   //--------------------------------------------------------------------
106
107
108   //--------------------------------------------------------------------
109   // Convenient function 
110   template<class ImageType>
111   typename ImageType::Pointer
112   ResizeImageLike(const ImageType * input,
113                   const itk::ImageBase<ImageType::ImageDimension> * like, 
114                   typename ImageType::PixelType BG);
115
116   template<class ImageType>
117   typename ImageType::Pointer
118   ResizeImageLike(const ImageType * input,
119                   typename itk::ImageBase<ImageType::ImageDimension>::RegionType * like, 
120                   typename ImageType::PixelType BG);
121
122   template<class ImageType>
123   typename ImageType::Pointer
124   ResizeImageLike(const ImageType * input, 
125                   typename itk::BoundingBox<unsigned long, ImageType::ImageDimension>::Pointer bb, 
126                   typename ImageType::PixelType BG);
127
128
129 } // end namespace clitk
130 //--------------------------------------------------------------------
131
132 #ifndef ITK_MANUAL_INSTANTIATION
133 #include "clitkCropLikeImageFilter.txx"
134 #endif
135
136 #endif // # CROPLIKEIMAGEFILTER