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