]> Creatis software - clitk.git/blob - itk/clitkBooleanOperatorLabelImageFilter.h
add 'OR' operation
[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://oncora1.lyon.fnclcc.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   protected:
102     BooleanOperatorLabelImageFilter();
103     virtual ~BooleanOperatorLabelImageFilter() {}
104     
105     virtual void GenerateOutputInformation();
106     virtual void GenerateInputRequestedRegion();
107     virtual void GenerateData();
108     
109     // Do not release date to keep input in memory and continue ... 
110     virtual void ReleaseInputs() { } 
111     
112     Input1ImagePixelType mBackgroundValue1;
113     Input2ImagePixelType mBackgroundValue2;
114     OutputImagePixelType mBackgroundValue;
115     OutputImagePixelType mForegroundValue;
116     
117     Input1ImageRegionType input1Region;
118     Input2ImageRegionType input2Region;
119     OutputImageRegionType outputRegion;
120     
121     OperationTypeEnumeration m_OperationType;
122     
123     template<class Iter1, class Iter2> void LoopAndNot(Iter1 it1, Iter1 it2, Iter2 ot);
124     template<class Iter1, class Iter2> void LoopAnd(Iter1 it1, Iter1 it2, Iter2 ot);
125     template<class Iter1, class Iter2> void LoopOr(Iter1 it1, Iter1 it2, Iter2 ot);
126     
127   private:
128     BooleanOperatorLabelImageFilter(const Self&); //purposely not implemented
129     void operator=(const Self&); //purposely not implemented
130     
131   }; // end class
132   //--------------------------------------------------------------------
133
134 } // end namespace clitk
135 //--------------------------------------------------------------------
136
137 #ifndef ITK_MANUAL_INSTANTIATION
138 #include "clitkBooleanOperatorLabelImageFilter.txx"
139 #endif
140
141 #endif