]> Creatis software - clitk.git/blob - itk/clitkCropLikeImageFilter.h
With ITK 5.0, itk::ProcessObject::VerifyInputInformation are now declared const
[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 #if ITK_VERSION_MAJOR <= 4
75     virtual void VerifyInputInformation() ITK_OVERRIDE { }
76 #else
77     virtual void VerifyInputInformation() const ITK_OVERRIDE { }
78 #endif
79
80   protected:
81     CropLikeImageFilter();
82     virtual ~CropLikeImageFilter() {}
83
84     virtual void GenerateOutputInformation() ITK_OVERRIDE;
85     virtual void GenerateData() ITK_OVERRIDE;
86     virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
87
88     PixelType m_BackgroundValue;
89     RegionType m_OutputRegion;
90     RegionType m_Region;
91     std::string m_LikeFilename;
92     bool m_LikeFilenameIsGiven;
93     PointType m_Origin;
94     const itk::ImageBase<ImageDimension> * m_LikeImage;
95     std::vector<bool> m_CropAlongThisDimension;
96
97     PointType m_StartPoint;         // start point in physical world
98     IndexType m_StartSourceIndex;   // start index in "source" image
99     IndexType m_StartDestIndex;     // start index in "destination" image
100
101     PointType m_StopPoint;         // stop point in physical world
102     IndexType m_StopSourceIndex;   // stop index in "source" image
103     IndexType m_StopDestIndex;     // stop index in "destination" image
104
105   private:
106     CropLikeImageFilter(const Self&); //purposely not implemented
107     void operator=(const Self&); //purposely not implemented
108
109   }; // end class
110   //--------------------------------------------------------------------
111
112
113   //--------------------------------------------------------------------
114   // Convenient function
115   template<class ImageType>
116   typename ImageType::Pointer
117   ResizeImageLike(const ImageType * input,
118                   const itk::ImageBase<ImageType::ImageDimension> * like,
119                   typename ImageType::PixelType BG);
120
121   template<class ImageType>
122   typename ImageType::Pointer
123   ResizeImageLike(const ImageType * input,
124                   typename itk::ImageBase<ImageType::ImageDimension>::RegionType * like,
125                   typename ImageType::PixelType BG);
126
127   template<class ImageType>
128   typename ImageType::Pointer
129   ResizeImageLike(const ImageType * input,
130                   typename itk::BoundingBox<unsigned long, ImageType::ImageDimension>::Pointer bb,
131                   typename ImageType::PixelType BG);
132
133
134 } // end namespace clitk
135 //--------------------------------------------------------------------
136
137 #ifndef ITK_MANUAL_INSTANTIATION
138 #include "clitkCropLikeImageFilter.txx"
139 #endif
140
141 #endif // # CROPLIKEIMAGEFILTER