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"
26 #include <itkImageToImageFilter.h>
30 //--------------------------------------------------------------------
32 Perform various cropping operation on a image
34 //--------------------------------------------------------------------
36 template <class ImageType>
37 class ITK_EXPORT CropLikeImageFilter: public itk::ImageToImageFilter<ImageType, ImageType> {
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;
45 /** Method for creation through the object factory. */
48 /** Run-time type information (and related methods). */
49 itkTypeMacro(CropLikeImageFilter, ImageToImageFilter);
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;
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);
65 // Set Background if 'like' is greater than input
66 itkSetMacro(BackgroundValue, PixelType);
67 itkGetConstMacro(BackgroundValue, PixelType);
69 /** ImageDimension constants */
70 itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
72 // I dont want to verify inputs information
73 virtual void VerifyInputInformation() { }
76 CropLikeImageFilter();
77 virtual ~CropLikeImageFilter() {}
79 virtual void GenerateOutputInformation();
80 virtual void GenerateData();
81 virtual void GenerateInputRequestedRegion();
83 PixelType m_BackgroundValue;
84 RegionType m_OutputRegion;
86 std::string m_LikeFilename;
87 bool m_LikeFilenameIsGiven;
89 const itk::ImageBase<ImageDimension> * m_LikeImage;
90 std::vector<bool> m_CropAlongThisDimension;
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
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
101 CropLikeImageFilter(const Self&); //purposely not implemented
102 void operator=(const Self&); //purposely not implemented
105 //--------------------------------------------------------------------
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);
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);
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);
129 } // end namespace clitk
130 //--------------------------------------------------------------------
132 #ifndef ITK_MANUAL_INSTANTIATION
133 #include "clitkCropLikeImageFilter.txx"
136 #endif // # CROPLIKEIMAGEFILTER