ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryThresholdImageFunction.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 __itkBinaryThresholdImageFunction_h
00019 #define __itkBinaryThresholdImageFunction_h
00020 
00021 #include "itkImageFunction.h"
00022 
00023 namespace itk
00024 {
00042 template< class TInputImage, class TCoordRep = float >
00043 class ITK_EXPORT BinaryThresholdImageFunction:
00044   public ImageFunction< TInputImage, bool, TCoordRep >
00045 {
00046 public:
00048   typedef BinaryThresholdImageFunction                  Self;
00049   typedef ImageFunction< TInputImage, bool, TCoordRep > Superclass;
00050   typedef SmartPointer< Self >                          Pointer;
00051   typedef SmartPointer< const Self >                    ConstPointer;
00052 
00054   itkTypeMacro(BinaryThresholdImageFunction, ImageFunction);
00055 
00057   itkNewMacro(Self);
00058 
00060   typedef typename Superclass::InputImageType InputImageType;
00061 
00063   typedef typename TInputImage::PixelType PixelType;
00064 
00066   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00067 
00069   typedef typename Superclass::PointType PointType;
00070 
00072   typedef typename Superclass::IndexType IndexType;
00073 
00075   typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00076 
00086   virtual bool Evaluate(const PointType & point) const
00087   {
00088     IndexType index;
00089 
00090     this->ConvertPointToNearestIndex(point, index);
00091     return ( this->EvaluateAtIndex(index) );
00092   }
00093 
00102   virtual bool EvaluateAtContinuousIndex(
00103     const ContinuousIndexType & index) const
00104   {
00105     IndexType nindex;
00106 
00107     this->ConvertContinuousIndexToNearestIndex (index, nindex);
00108     return this->EvaluateAtIndex(nindex);
00109   }
00110 
00119   virtual bool EvaluateAtIndex(const IndexType & index) const
00120   {
00121     PixelType value = this->GetInputImage()->GetPixel(index);
00122 
00123     return ( m_Lower <= value && value <= m_Upper );
00124   }
00125 
00127   itkGetConstReferenceMacro(Lower, PixelType);
00128 
00130   itkGetConstReferenceMacro(Upper, PixelType);
00131 
00133   void ThresholdAbove(PixelType thresh);
00134 
00136   void ThresholdBelow(PixelType thresh);
00137 
00139   void ThresholdBetween(PixelType lower, PixelType upper);
00140 
00141 protected:
00142   BinaryThresholdImageFunction();
00143   ~BinaryThresholdImageFunction(){}
00144   void PrintSelf(std::ostream & os, Indent indent) const;
00145 
00146 private:
00147   BinaryThresholdImageFunction(const Self &); //purposely not implemented
00148   void operator=(const Self &);               //purposely not implemented
00149 
00150   PixelType m_Lower;
00151   PixelType m_Upper;
00152 };
00153 } // end namespace itk
00154 
00155 // Define instantiation macro for this template.
00156 #define ITK_TEMPLATE_BinaryThresholdImageFunction(_, EXPORT, TypeX, TypeY)     \
00157   namespace itk                                                                \
00158   {                                                                            \
00159   _( 2 ( class EXPORT BinaryThresholdImageFunction< ITK_TEMPLATE_2 TypeX > ) ) \
00160   namespace Templates                                                          \
00161   {                                                                            \
00162   typedef BinaryThresholdImageFunction< ITK_TEMPLATE_2 TypeX >                 \
00163   BinaryThresholdImageFunction##TypeY;                                       \
00164   }                                                                            \
00165   }
00166 
00167 #if ITK_TEMPLATE_EXPLICIT
00168 #include "Templates/itkBinaryThresholdImageFunction+-.h"
00169 #endif
00170 
00171 #if ITK_TEMPLATE_TXX
00172 #include "itkBinaryThresholdImageFunction.hxx"
00173 #endif
00174 
00175 #endif
00176