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"
26 /** \class FlexibleBinaryFunctorImageFilter
27 * \brief Implements pixel-wise generic operation of two images.
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.
37 * \sa UnaryFunctorImageFilter BinaryFunctorImageFilter TernaryFunctorImageFilter
39 * \ingroup IntensityImageFilters Multithreaded
41 template <class TInputImage1, class TInputImage2,
42 class TOutputImage, class TFunction >
43 class ITK_EXPORT FlexibleBinaryFunctorImageFilter :
44 public InPlaceImageFilter<TInputImage1,TOutputImage>
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;
53 /** Method for creation through the object factory. */
56 /** Run-time type information (and related methods). */
57 itkTypeMacro(FlexibleBinaryFunctorImageFilter, InPlaceImageFilter);
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;
66 typedef TInputImage2 Input2ImageType;
67 typedef typename Input2ImageType::ConstPointer Input2ImagePointer;
68 typedef typename Input2ImageType::RegionType Input2ImageRegionType;
69 typedef typename Input2ImageType::PixelType Input2ImagePixelType;
71 typedef TOutputImage OutputImageType;
72 typedef typename OutputImageType::Pointer OutputImagePointer;
73 typedef typename OutputImageType::RegionType OutputImageRegionType;
74 typedef typename OutputImageType::PixelType OutputImagePixelType;
76 /** Connect one of the operands for pixel-wise addition */
77 void SetInput1( const TInputImage1 * image1);
79 /** Connect one of the operands for pixel-wise addition */
80 void SetInput2( const TInputImage2 * image2);
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
86 FunctorType& GetFunctor() { return m_Functor; }
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
92 const FunctorType& GetFunctor() const
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
103 void SetFunctor(const FunctorType& functor)
105 if (m_Functor != functor)
112 virtual void GenerateOutputInformation();
113 virtual void GenerateInputRequestedRegion();
115 /** ImageDimension constants */
117 InputImage1Dimension, unsigned int, TInputImage1::ImageDimension);
119 InputImage2Dimension, unsigned int, TInputImage2::ImageDimension);
121 OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
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 */
135 FlexibleBinaryFunctorImageFilter();
136 virtual ~FlexibleBinaryFunctorImageFilter() {}
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"
146 * \sa ImageToImageFilter::ThreadedGenerateData(),
147 * ImageToImageFilter::GenerateData() */
148 #if ITK_VERSION_MAJOR >= 4
149 void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
150 itk::ThreadIdType threadId );
152 void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
157 FlexibleBinaryFunctorImageFilter(const Self&); //purposely not implemented
158 void operator=(const Self&); //purposely not implemented
160 FunctorType m_Functor;
161 Input2ImagePointer m_Input2;
164 } // end namespace itk
166 #ifndef ITK_MANUAL_INSTANTIATION
167 #include "itkFlexibleBinaryFunctorImageFilter.txx"