ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
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 __itkBinaryNotImageFilter_h 00019 #define __itkBinaryNotImageFilter_h 00020 00021 #include "itkUnaryFunctorImageFilter.h" 00022 #include "itkNumericTraits.h" 00023 00024 00025 namespace itk 00026 { 00027 00054 namespace Functor { 00055 00056 template< class TPixel > 00057 class BinaryNot 00058 { 00059 public: 00060 BinaryNot() {}; 00061 ~BinaryNot() {}; 00062 bool operator!=( const BinaryNot & ) const 00063 { 00064 return false; 00065 } 00066 bool operator==( const BinaryNot & other ) const 00067 { 00068 return !(*this != other); 00069 } 00070 inline TPixel operator()( const TPixel & A ) 00071 { 00072 bool a = ( A == m_ForegroundValue ); 00073 if( !a ) 00074 { 00075 return m_ForegroundValue; 00076 } 00077 return m_BackgroundValue; 00078 } 00079 00080 TPixel m_ForegroundValue; 00081 TPixel m_BackgroundValue; 00082 }; 00083 00084 } 00085 template <class TImage> 00086 class ITK_EXPORT BinaryNotImageFilter : 00087 public 00088 UnaryFunctorImageFilter<TImage, TImage, 00089 Functor::BinaryNot< typename TImage::PixelType > > 00090 00091 00092 { 00093 public: 00095 typedef BinaryNotImageFilter Self; 00096 typedef UnaryFunctorImageFilter<TImage, TImage, 00097 Functor::BinaryNot< typename TImage::PixelType> > Superclass; 00098 typedef SmartPointer<Self> Pointer; 00099 typedef SmartPointer<const Self> ConstPointer; 00100 00102 itkNewMacro(Self); 00103 00105 itkTypeMacro(BinaryNotImageFilter, 00106 ImageToImageFilter); 00107 00108 typedef typename TImage::PixelType PixelType; 00109 00112 itkSetMacro(ForegroundValue, PixelType); 00113 itkGetConstMacro(ForegroundValue, PixelType); 00115 00118 itkSetMacro(BackgroundValue, PixelType); 00119 00122 itkGetConstMacro(BackgroundValue, PixelType); 00123 00124 00125 protected: 00126 BinaryNotImageFilter() 00127 { 00128 m_ForegroundValue = NumericTraits<PixelType>::max(); 00129 m_BackgroundValue = NumericTraits<PixelType>::NonpositiveMin(); 00130 } 00131 virtual ~BinaryNotImageFilter() {} 00132 00133 void PrintSelf(std::ostream& os, Indent indent) const 00134 { 00135 Superclass::PrintSelf(os,indent); 00136 00137 typedef typename NumericTraits<PixelType>::PrintType 00138 PixelPrintType; 00139 00140 os << indent << "ForegroundValue: " 00141 << static_cast< PixelPrintType > (m_ForegroundValue) 00142 << std::endl; 00143 00144 os << indent << "BackgroundValue: " 00145 << static_cast< PixelPrintType > (m_BackgroundValue) 00146 << std::endl; 00147 } 00148 00149 void GenerateData() 00150 { 00151 this->GetFunctor().m_ForegroundValue = m_ForegroundValue; 00152 this->GetFunctor().m_BackgroundValue = m_BackgroundValue; 00153 Superclass::GenerateData(); 00154 } 00155 00156 private: 00157 BinaryNotImageFilter(const Self&); //purposely not implemented 00158 void operator=(const Self&); //purposely not implemented 00159 00160 PixelType m_ForegroundValue; 00161 PixelType m_BackgroundValue; 00162 00163 }; 00164 00165 } // end namespace itk 00166 00167 00168 #endif 00169