]> Creatis software - clitk.git/blob - itk/clitkBooleanOperatorLabelImageFilter.h
e7d1b73113fb99918b1dd001308373f76a880b87
[clitk.git] / itk / clitkBooleanOperatorLabelImageFilter.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 CLITKBOOLEANOPERATORLABELIMAGEFILTER_H
20 #define CLITKBOOLEANOPERATORLABELIMAGEFILTER_H
21
22 #include "itkInPlaceImageFilter.h"
23 #include "itkImageRegionIteratorWithIndex.h"
24
25 namespace clitk {
26   
27   //--------------------------------------------------------------------
28   /*
29     Perform boolan operation between two mask images. Like itkAnd and
30     others, but take care of:
31     - origin of the images (spacing must be equal)
32     - in place or not output
33     - Binary or Label images as inputs. Label i BG only ; Binary is FG only
34
35     - NO THREAD -> I dont know how (yet) to manage two different inputRegionForThread 
36
37   */
38   //--------------------------------------------------------------------
39   
40   template <class TInputImage1, class TInputImage2=TInputImage1, class TOutputImage=TInputImage1>
41   class ITK_EXPORT BooleanOperatorLabelImageFilter: 
42     public itk::InPlaceImageFilter<TInputImage1, TOutputImage> {
43
44   public:
45     /** Standard class typedefs. */
46     typedef BooleanOperatorLabelImageFilter                     Self;
47     typedef itk::InPlaceImageFilter<TInputImage1,TOutputImage>  Superclass;
48     typedef itk::SmartPointer<Self>                             Pointer;
49     typedef itk::SmartPointer<const Self>                       ConstPointer;
50     
51     /** Method for creation through the object factory. */
52     itkNewMacro(Self);
53     
54     /** Run-time type information (and related methods). */
55     itkTypeMacro(BooleanOperatorLabelImageFilter, InPlaceImageFilter);
56
57     /** Some convenient typedefs. */
58     typedef TInputImage1                           Input1ImageType;
59     typedef typename Input1ImageType::ConstPointer Input1ImageConstPointer;
60     typedef typename Input1ImageType::Pointer      Input1ImagePointer;
61     typedef typename Input1ImageType::RegionType   Input1ImageRegionType; 
62     typedef typename Input1ImageType::PixelType    Input1ImagePixelType; 
63     
64     typedef TInputImage2                           Input2ImageType;
65     typedef typename Input2ImageType::ConstPointer Input2ImageConstPointer;
66     typedef typename Input2ImageType::Pointer      Input2ImagePointer;
67     typedef typename Input2ImageType::RegionType   Input2ImageRegionType; 
68     typedef typename Input2ImageType::PixelType    Input2ImagePixelType; 
69     
70     typedef TOutputImage                           OutputImageType;
71     typedef typename OutputImageType::Pointer      OutputImagePointer;
72     typedef typename OutputImageType::RegionType   OutputImageRegionType;
73     typedef typename OutputImageType::PixelType    OutputImagePixelType;
74     
75     /** Connect one of the operands for pixel-wise addition */
76     void SetInput1( const TInputImage1 * image1);
77     
78     /** Connect one of the operands for pixel-wise addition */
79     void SetInput2( const TInputImage2 * image2);
80     
81     // Set type of operation
82     typedef enum {
83       And = 0, 
84       AndNot = 1, 
85       Or = 2
86     } OperationTypeEnumeration;
87     itkGetMacro(OperationType, OperationTypeEnumeration);
88     itkSetMacro(OperationType, OperationTypeEnumeration);
89
90     // LabelImage information (BG and FG)
91     void SetBackgroundValue1(Input1ImagePixelType p);
92     void SetBackgroundValue2(Input2ImagePixelType p);
93     void SetBackgroundValue(OutputImagePixelType p);
94     void SetForegroundValue(OutputImagePixelType p);
95
96     /** ImageDimension constants */
97     itkStaticConstMacro(InputImage1Dimension, unsigned int, TInputImage1::ImageDimension);
98     itkStaticConstMacro(InputImage2Dimension, unsigned int, TInputImage2::ImageDimension);
99     itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
100
101     // I dont want to verify inputs information
102     virtual void VerifyInputInformation() ITK_OVERRIDE { }
103     
104   protected:
105     BooleanOperatorLabelImageFilter();
106     virtual ~BooleanOperatorLabelImageFilter() {}
107     
108     virtual void GenerateOutputInformation() ITK_OVERRIDE;
109     virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
110     virtual void GenerateData() ITK_OVERRIDE;
111     
112     // Do not release date to keep input in memory and continue ... 
113     virtual void ReleaseInputs() ITK_OVERRIDE { }
114     
115     Input1ImagePixelType mBackgroundValue1;
116     Input2ImagePixelType mBackgroundValue2;
117     OutputImagePixelType mBackgroundValue;
118     OutputImagePixelType mForegroundValue;
119     
120     Input1ImageRegionType input1Region;
121     Input2ImageRegionType input2Region;
122     OutputImageRegionType outputRegion;
123     
124     OperationTypeEnumeration m_OperationType;
125     
126     template<class Iter1, class Iter2> void LoopAndNot(Iter1 it1, Iter1 it2, Iter2 ot);
127     template<class Iter1, class Iter2> void LoopAnd(Iter1 it1, Iter1 it2, Iter2 ot);
128     template<class Iter1, class Iter2> void LoopOr(Iter1 it1, Iter1 it2, Iter2 ot);
129     
130   private:
131     BooleanOperatorLabelImageFilter(const Self&); //purposely not implemented
132     void operator=(const Self&); //purposely not implemented
133     
134   }; // end class
135   //--------------------------------------------------------------------
136
137 } // end namespace clitk
138 //--------------------------------------------------------------------
139
140 #ifndef ITK_MANUAL_INSTANTIATION
141 #include "clitkBooleanOperatorLabelImageFilter.txx"
142 #endif
143
144 #endif