]> Creatis software - clitk.git/blob - itk/clitkCropLikeImageFilter.h
47ae445a2b2312c53b6e8521b684110f0449e205
[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 #include "clitkImageCommon.h"
25
26 // itk
27 #include <itkImageToImageFilter.h>
28
29 namespace clitk {
30
31   //--------------------------------------------------------------------
32   /*
33     Perform various cropping operation on a image
34   */
35   //--------------------------------------------------------------------
36
37   template <class ImageType>
38   class ITK_EXPORT CropLikeImageFilter: public itk::ImageToImageFilter<ImageType, ImageType> {
39   public:
40     /** Standard class typedefs. */
41     typedef CropLikeImageFilter                            Self;
42     typedef itk::ImageToImageFilter<ImageType, ImageType>  Superclass;
43     typedef itk::SmartPointer<Self>                        Pointer;
44     typedef itk::SmartPointer<const Self>                  ConstPointer;
45
46     /** Method for creation through the object factory. */
47     itkNewMacro(Self);
48
49     /** Run-time type information (and related methods). */
50     itkTypeMacro(CropLikeImageFilter, ImageToImageFilter);
51
52     /** Some convenient typedefs. */
53     typedef typename ImageType::ConstPointer ImageConstPointer;
54     typedef typename ImageType::Pointer      ImagePointer;
55     typedef typename ImageType::PixelType    PixelType;
56     typedef typename ImageType::RegionType   RegionType;
57     typedef typename ImageType::PointType    PointType;
58     typedef typename ImageType::IndexType    IndexType;
59     typedef typename ImageType::SizeType     SizeType;
60
61     /** Image filename for Crop Like */
62     void SetCropLikeFilename(std::string f);
63     void SetCropLikeImage(const itk::ImageBase<ImageType::ImageDimension> * like);
64     void SetCropLikeImage(const itk::ImageBase<ImageType::ImageDimension> * like, int axe);
65
66     // Set Background if 'like' is greater than input
67     itkSetMacro(BackgroundValue, PixelType);
68     itkGetConstMacro(BackgroundValue, PixelType);
69
70     /** ImageDimension constants */
71     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
72
73     // I dont want to verify inputs information
74     virtual void VerifyInputInformation() ITK_OVERRIDE { }
75
76   protected:
77     CropLikeImageFilter();
78     virtual ~CropLikeImageFilter() {}
79
80     virtual void GenerateOutputInformation() ITK_OVERRIDE;
81     virtual void GenerateData() ITK_OVERRIDE;
82     virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
83
84     PixelType m_BackgroundValue;
85     RegionType m_OutputRegion;
86     RegionType m_Region;
87     std::string m_LikeFilename;
88     bool m_LikeFilenameIsGiven;
89     PointType m_Origin;
90     const itk::ImageBase<ImageDimension> * m_LikeImage;
91     std::vector<bool> m_CropAlongThisDimension;
92
93     PointType m_StartPoint;         // start point in physical world
94     IndexType m_StartSourceIndex;   // start index in "source" image
95     IndexType m_StartDestIndex;     // start index in "destination" image
96
97     PointType m_StopPoint;         // stop point in physical world
98     IndexType m_StopSourceIndex;   // stop index in "source" image
99     IndexType m_StopDestIndex;     // stop index in "destination" image
100
101   private:
102     CropLikeImageFilter(const Self&); //purposely not implemented
103     void operator=(const Self&); //purposely not implemented
104
105   }; // end class
106   //--------------------------------------------------------------------
107
108
109   //--------------------------------------------------------------------
110   // Convenient function
111   template<class ImageType>
112   typename ImageType::Pointer
113   ResizeImageLike(const ImageType * input,
114                   const itk::ImageBase<ImageType::ImageDimension> * like,
115                   typename ImageType::PixelType BG);
116
117   template<class ImageType>
118   typename ImageType::Pointer
119   ResizeImageLike(const ImageType * input,
120                   typename itk::ImageBase<ImageType::ImageDimension>::RegionType * like,
121                   typename ImageType::PixelType BG);
122
123   template<class ImageType>
124   typename ImageType::Pointer
125   ResizeImageLike(const ImageType * input,
126                   typename itk::BoundingBox<unsigned long, ImageType::ImageDimension>::Pointer bb,
127                   typename ImageType::PixelType BG);
128
129
130 } // end namespace clitk
131 //--------------------------------------------------------------------
132
133 #ifndef ITK_MANUAL_INSTANTIATION
134 #include "clitkCropLikeImageFilter.txx"
135 #endif
136
137 #endif // # CROPLIKEIMAGEFILTER