1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: itkFlexibleBinaryFunctorImageFilter.h,v $
6 Date: $Date: 2012-02-17 11:01:02 $
7 Version: $Revision: 1.37 $
9 Copyright (c) Insight Software Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
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.
16 =========================================================================*/
17 #ifndef __itkFlexibleBinaryFunctorImageFilter_h
18 #define __itkFlexibleBinaryFunctorImageFilter_h
20 #include "itkInPlaceImageFilter.h"
21 #include "itkImageRegionIteratorWithIndex.h"
23 #include "clitkCommon.h"
28 /** \class FlexibleBinaryFunctorImageFilter
29 * \brief Implements pixel-wise generic operation of two images.
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.
39 * \sa UnaryFunctorImageFilter BinaryFunctorImageFilter TernaryFunctorImageFilter
41 * \ingroup IntensityImageFilters Multithreaded
43 template <class TInputImage1, class TInputImage2,
44 class TOutputImage, class TFunction >
45 class ITK_EXPORT FlexibleBinaryFunctorImageFilter :
46 public InPlaceImageFilter<TInputImage1,TOutputImage>
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;
55 /** Method for creation through the object factory. */
58 /** Run-time type information (and related methods). */
59 itkTypeMacro(FlexibleBinaryFunctorImageFilter, InPlaceImageFilter);
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;
68 typedef TInputImage2 Input2ImageType;
69 typedef typename Input2ImageType::ConstPointer Input2ImagePointer;
70 typedef typename Input2ImageType::RegionType Input2ImageRegionType;
71 typedef typename Input2ImageType::PixelType Input2ImagePixelType;
73 typedef TOutputImage OutputImageType;
74 typedef typename OutputImageType::Pointer OutputImagePointer;
75 typedef typename OutputImageType::RegionType OutputImageRegionType;
76 typedef typename OutputImageType::PixelType OutputImagePixelType;
78 /** Connect one of the operands for pixel-wise addition */
79 void SetInput1( const TInputImage1 * image1);
81 /** Connect one of the operands for pixel-wise addition */
82 void SetInput2( const TInputImage2 * image2);
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
88 FunctorType& GetFunctor() { return m_Functor; }
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
94 const FunctorType& GetFunctor() const
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
105 void SetFunctor(const FunctorType& functor)
107 if (m_Functor != functor)
114 virtual void GenerateOutputInformation() ITK_OVERRIDE;
115 virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
117 /** ImageDimension constants */
119 InputImage1Dimension, unsigned int, TInputImage1::ImageDimension);
121 InputImage2Dimension, unsigned int, TInputImage2::ImageDimension);
123 OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
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 */
137 FlexibleBinaryFunctorImageFilter();
138 virtual ~FlexibleBinaryFunctorImageFilter() {}
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"
148 * \sa ImageToImageFilter::ThreadedGenerateData(),
149 * ImageToImageFilter::GenerateData() */
150 void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
151 itk::ThreadIdType threadId ) ITK_OVERRIDE;
154 FlexibleBinaryFunctorImageFilter(const Self&); //purposely not implemented
155 void operator=(const Self&); //purposely not implemented
157 FunctorType m_Functor;
158 Input2ImagePointer m_Input2;
161 } // end namespace itk
163 #ifndef ITK_MANUAL_INSTANTIATION
164 #include "itkFlexibleBinaryFunctorImageFilter.txx"