1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #ifndef CLITKCROPLIKEIMAGEFILTER_H
20 #define CLITKCROPLIKEIMAGEFILTER_H
23 #include "clitkBoundingBoxUtils.h"
24 #include "clitkImageCommon.h"
27 #include <itkImageToImageFilter.h>
31 //--------------------------------------------------------------------
33 Perform various cropping operation on a image
35 //--------------------------------------------------------------------
37 template <class ImageType>
38 class ITK_EXPORT CropLikeImageFilter: public itk::ImageToImageFilter<ImageType, ImageType> {
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;
46 /** Method for creation through the object factory. */
49 /** Run-time type information (and related methods). */
50 itkTypeMacro(CropLikeImageFilter, ImageToImageFilter);
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;
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);
66 // Set Background if 'like' is greater than input
67 itkSetMacro(BackgroundValue, PixelType);
68 itkGetConstMacro(BackgroundValue, PixelType);
70 /** ImageDimension constants */
71 itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
73 // I dont want to verify inputs information
74 #if ITK_VERSION_MAJOR <= 4
75 virtual void VerifyInputInformation() ITK_OVERRIDE { }
77 virtual void VerifyInputInformation() const ITK_OVERRIDE { }
81 CropLikeImageFilter();
82 virtual ~CropLikeImageFilter() {}
84 virtual void GenerateOutputInformation() ITK_OVERRIDE;
85 virtual void GenerateData() ITK_OVERRIDE;
86 virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
88 PixelType m_BackgroundValue;
89 RegionType m_OutputRegion;
91 std::string m_LikeFilename;
92 bool m_LikeFilenameIsGiven;
94 const itk::ImageBase<ImageDimension> * m_LikeImage;
95 std::vector<bool> m_CropAlongThisDimension;
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
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
106 CropLikeImageFilter(const Self&); //purposely not implemented
107 void operator=(const Self&); //purposely not implemented
110 //--------------------------------------------------------------------
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);
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);
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);
134 } // end namespace clitk
135 //--------------------------------------------------------------------
137 #ifndef ITK_MANUAL_INSTANTIATION
138 #include "clitkCropLikeImageFilter.txx"
141 #endif // # CROPLIKEIMAGEFILTER