]> Creatis software - clitk.git/blob - itk/itkFlexibleBinaryFunctorImageFilter.h
Merge branch 'master' into GammaIndex3D
[clitk.git] / itk / itkFlexibleBinaryFunctorImageFilter.h
1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkFlexibleBinaryFunctorImageFilter.h,v $
5   Language:  C++
6   Date:      $Date: 2012-02-17 11:01:02 $
7   Version:   $Revision: 1.37 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkFlexibleBinaryFunctorImageFilter_h
18 #define __itkFlexibleBinaryFunctorImageFilter_h
19
20 #include "itkInPlaceImageFilter.h"
21 #include "itkImageRegionIteratorWithIndex.h"
22
23 namespace itk
24 {
25   
26 /** \class FlexibleBinaryFunctorImageFilter
27  * \brief Implements pixel-wise generic operation of two images.
28  *
29  * This class is parameterized over the types of the two input images
30  * and the type of the output image.  It is also parameterized by the
31  * operation to be applied.  A Functor style is used. The  main difference
32  * wrt the standard BinaryFunctorImageFilter is that the second input's
33  * dimensions/spacing/origin can differ from those of the first. The 
34  * functor is then only called if the pixel from input1 is inside 
35  * input2's largest region.
36  * 
37  * \sa UnaryFunctorImageFilter BinaryFunctorImageFilter TernaryFunctorImageFilter
38  *
39  * \ingroup IntensityImageFilters   Multithreaded
40  */
41 template <class TInputImage1, class TInputImage2, 
42           class TOutputImage, class TFunction    >
43 class ITK_EXPORT FlexibleBinaryFunctorImageFilter :
44     public InPlaceImageFilter<TInputImage1,TOutputImage> 
45 {
46 public:
47   /** Standard class typedefs. */
48   typedef FlexibleBinaryFunctorImageFilter                       Self;
49   typedef InPlaceImageFilter<TInputImage1,TOutputImage>  Superclass;
50   typedef SmartPointer<Self>                             Pointer;
51   typedef SmartPointer<const Self>                       ConstPointer;
52
53   /** Method for creation through the object factory. */
54   itkNewMacro(Self);
55   
56   /** Run-time type information (and related methods). */
57   itkTypeMacro(FlexibleBinaryFunctorImageFilter, InPlaceImageFilter);
58
59   /** Some convenient typedefs. */
60   typedef TFunction                              FunctorType;
61   typedef TInputImage1                           Input1ImageType;
62   typedef typename Input1ImageType::ConstPointer Input1ImagePointer;
63   typedef typename Input1ImageType::RegionType   Input1ImageRegionType; 
64   typedef typename Input1ImageType::PixelType    Input1ImagePixelType; 
65
66   typedef TInputImage2                           Input2ImageType;
67   typedef typename Input2ImageType::ConstPointer Input2ImagePointer;
68   typedef typename Input2ImageType::RegionType   Input2ImageRegionType; 
69   typedef typename Input2ImageType::PixelType    Input2ImagePixelType; 
70
71   typedef TOutputImage                           OutputImageType;
72   typedef typename OutputImageType::Pointer      OutputImagePointer;
73   typedef typename OutputImageType::RegionType   OutputImageRegionType;
74   typedef typename OutputImageType::PixelType    OutputImagePixelType;
75
76   /** Connect one of the operands for pixel-wise addition */
77   void SetInput1( const TInputImage1 * image1);
78
79   /** Connect one of the operands for pixel-wise addition */
80   void SetInput2( const TInputImage2 * image2);
81
82   /** Get the functor object.  The functor is returned by reference.
83    * (Functors do not have to derive from itk::LightObject, so they do
84    * not necessarily have a reference count. So we cannot return a
85    * SmartPointer.) */
86   FunctorType& GetFunctor() { return m_Functor; }
87
88   /** Get the functor object.  The functor is returned by reference.
89    * (Functors do not have to derive from itk::LightObject, so they do
90    * not necessarily have a reference count. So we cannot return a
91    * SmartPointer.) */
92   const FunctorType& GetFunctor() const
93     {
94     return m_Functor;
95     }
96
97   /** Set the functor object.  This replaces the current Functor with a
98    * copy of the specified Functor. This allows the user to specify a
99    * functor that has ivars set differently than the default functor.
100    * This method requires an operator!=() be defined on the functor
101    * (or the compiler's default implementation of operator!=() being
102    * appropriate). */
103   void SetFunctor(const FunctorType& functor)
104     {
105     if (m_Functor != functor)
106       {
107       m_Functor = functor;
108       this->Modified();
109       }
110     }
111
112   virtual void GenerateOutputInformation();
113   virtual void GenerateInputRequestedRegion();
114
115   /** ImageDimension constants */
116   itkStaticConstMacro(
117     InputImage1Dimension, unsigned int, TInputImage1::ImageDimension);
118   itkStaticConstMacro(
119     InputImage2Dimension, unsigned int, TInputImage2::ImageDimension);
120   itkStaticConstMacro(
121     OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
122
123 #ifdef ITK_USE_CONCEPT_CHECKING
124   /** Begin concept checking */
125   itkConceptMacro(SameDimensionCheck1,
126     (Concept::SameDimension<itkGetStaticConstMacro(InputImage1Dimension),
127                             itkGetStaticConstMacro(InputImage2Dimension)>));
128   itkConceptMacro(SameDimensionCheck2,
129     (Concept::SameDimension<itkGetStaticConstMacro(InputImage1Dimension),
130                             itkGetStaticConstMacro(OutputImageDimension)>));
131   /** End concept checking */
132 #endif
133
134 protected:
135   FlexibleBinaryFunctorImageFilter();
136   virtual ~FlexibleBinaryFunctorImageFilter() {}
137
138   /** FlexibleBinaryFunctorImageFilter can be implemented as a multithreaded filter.
139    * Therefore, this implementation provides a ThreadedGenerateData() routine
140    * which is called for each processing thread. The output image data is
141    * allocated automatically by the superclass prior to calling
142    * ThreadedGenerateData().  ThreadedGenerateData can only write to the
143    * portion of the output image specified by the parameter
144    * "outputRegionForThread"
145    *
146    * \sa ImageToImageFilter::ThreadedGenerateData(),
147    *     ImageToImageFilter::GenerateData()  */
148   void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
149                             itk::ThreadIdType threadId );
150
151 private:
152   FlexibleBinaryFunctorImageFilter(const Self&); //purposely not implemented
153   void operator=(const Self&); //purposely not implemented
154
155   FunctorType m_Functor;
156   Input2ImagePointer m_Input2;
157 };
158
159 } // end namespace itk
160
161 #ifndef ITK_MANUAL_INSTANTIATION
162 #include "itkFlexibleBinaryFunctorImageFilter.txx"
163 #endif
164
165 #endif