ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryFunctorImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkBinaryFunctorImageFilter_h
00019 #define __itkBinaryFunctorImageFilter_h
00020 
00021 #include "itkInPlaceImageFilter.h"
00022 #include "itkSimpleDataObjectDecorator.h"
00023 
00024 namespace itk
00025 {
00049 template< class TInputImage1, class TInputImage2,
00050           class TOutputImage, class TFunction    >
00051 class ITK_EXPORT BinaryFunctorImageFilter:
00052   public InPlaceImageFilter< TInputImage1, TOutputImage >
00053 {
00054 public:
00056   typedef BinaryFunctorImageFilter                         Self;
00057   typedef InPlaceImageFilter< TInputImage1, TOutputImage > Superclass;
00058   typedef SmartPointer< Self >                             Pointer;
00059   typedef SmartPointer< const Self >                       ConstPointer;
00060 
00062   itkNewMacro(Self);
00063 
00065   itkTypeMacro(BinaryFunctorImageFilter, InPlaceImageFilter);
00066 
00068   typedef TFunction                              FunctorType;
00069   typedef TInputImage1                           Input1ImageType;
00070   typedef typename Input1ImageType::ConstPointer Input1ImagePointer;
00071   typedef typename Input1ImageType::RegionType   Input1ImageRegionType;
00072   typedef typename Input1ImageType::PixelType    Input1ImagePixelType;
00073   typedef SimpleDataObjectDecorator<Input1ImagePixelType>
00074                                                  DecoratedInput1ImagePixelType;
00075 
00076   typedef TInputImage2                           Input2ImageType;
00077   typedef typename Input2ImageType::ConstPointer Input2ImagePointer;
00078   typedef typename Input2ImageType::RegionType   Input2ImageRegionType;
00079   typedef typename Input2ImageType::PixelType    Input2ImagePixelType;
00080   typedef SimpleDataObjectDecorator<Input2ImagePixelType>
00081                                                  DecoratedInput2ImagePixelType;
00082 
00083   typedef TOutputImage                         OutputImageType;
00084   typedef typename OutputImageType::Pointer    OutputImagePointer;
00085   typedef typename OutputImageType::RegionType OutputImageRegionType;
00086   typedef typename OutputImageType::PixelType  OutputImagePixelType;
00087 
00089   virtual void SetInput1(const TInputImage1 *image1);
00090   virtual void SetInput1(const DecoratedInput1ImagePixelType *input1);
00091   virtual void SetInput1(const Input1ImagePixelType &input1);
00093 
00095   virtual void SetConstant1(const Input1ImagePixelType &input1);
00096 
00100   virtual const Input1ImagePixelType & GetConstant1() const;
00101 
00103   virtual void SetInput2(const TInputImage2 *image2);
00104   virtual void SetInput2(const DecoratedInput2ImagePixelType *input2);
00105   virtual void SetInput2(const Input2ImagePixelType &input2);
00107 
00109   virtual void SetConstant2(const Input2ImagePixelType &input2);
00110   void SetConstant(Input2ImagePixelType ct)
00111   {
00112     this->SetConstant2(ct);
00113   }
00114   const Input2ImagePixelType & GetConstant() const
00115   {
00116     return this->GetConstant2();
00117   }
00119 
00123   virtual const Input2ImagePixelType & GetConstant2() const;
00124 
00129   FunctorType & GetFunctor() { return m_Functor; }
00130 
00135   const FunctorType & GetFunctor() const
00136   {
00137     return m_Functor;
00138   }
00139 
00146   void SetFunctor(const FunctorType & functor)
00147   {
00148     if ( m_Functor != functor )
00149       {
00150       m_Functor = functor;
00151       this->Modified();
00152       }
00153   }
00155 
00157   itkStaticConstMacro(
00158     InputImage1Dimension, unsigned int, TInputImage1::ImageDimension);
00159   itkStaticConstMacro(
00160     InputImage2Dimension, unsigned int, TInputImage2::ImageDimension);
00161   itkStaticConstMacro(
00162     OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
00164 
00165 #ifdef ITK_USE_CONCEPT_CHECKING
00166 
00167   itkConceptMacro( SameDimensionCheck1,
00168                    ( Concept::SameDimension< itkGetStaticConstMacro(InputImage1Dimension),
00169                                              itkGetStaticConstMacro(InputImage2Dimension) > ) );
00170   itkConceptMacro( SameDimensionCheck2,
00171                    ( Concept::SameDimension< itkGetStaticConstMacro(InputImage1Dimension),
00172                                              itkGetStaticConstMacro(OutputImageDimension) > ) );
00173 
00175 #endif
00176 protected:
00177   BinaryFunctorImageFilter();
00178   virtual ~BinaryFunctorImageFilter() {}
00179 
00190   void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
00191                             ThreadIdType threadId);
00192 
00193   // needed to take the image information from the 2nd input, if the first one is
00194   // a simple decorated object
00195   virtual void GenerateOutputInformation();
00196 
00197 private:
00198   BinaryFunctorImageFilter(const Self &); //purposely not implemented
00199   void operator=(const Self &);           //purposely not implemented
00200 
00201   FunctorType m_Functor;
00202 };
00203 } // end namespace itk
00204 
00205 #ifndef ITK_MANUAL_INSTANTIATION
00206 #include "itkBinaryFunctorImageFilter.hxx"
00207 #endif
00208 
00209 #endif
00210