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 __itkMaskNegatedImageFilter_h 00019 #define __itkMaskNegatedImageFilter_h 00020 00021 #include "itkBinaryFunctorImageFilter.h" 00022 #include "itkNumericTraits.h" 00023 00024 namespace itk 00025 { 00026 namespace Functor 00027 { 00033 template< class TInput, class TMask, class TOutput = TInput > 00034 class MaskNegatedInput 00035 { 00036 public: 00037 typedef typename NumericTraits< TInput >::AccumulateType AccumulatorType; 00038 00039 MaskNegatedInput():m_OutsideValue(NumericTraits< TOutput >::Zero) {} 00040 ~MaskNegatedInput() {} 00041 bool operator!=(const MaskNegatedInput &) const 00042 { 00043 return false; 00044 } 00045 00046 bool operator==(const MaskNegatedInput & other) const 00047 { 00048 return !( *this != other ); 00049 } 00050 00051 inline TOutput operator()(const TInput & A, const TMask & B) const 00052 { 00053 if ( B != NumericTraits< TMask >::ZeroValue() ) 00054 { 00055 return m_OutsideValue; 00056 } 00057 else 00058 { 00059 return static_cast< TOutput >( A ); 00060 } 00061 } 00062 00064 void SetOutsideValue(const TOutput & outsideValue) 00065 { 00066 m_OutsideValue = outsideValue; 00067 } 00068 00070 const TOutput & GetOutsideValue() const 00071 { 00072 return m_OutsideValue; 00073 } 00074 00075 private: 00076 TOutput m_OutsideValue; 00077 }; 00078 } 00112 template< class TInputImage, class TMaskImage, class TOutputImage = TInputImage > 00113 class ITK_EXPORT MaskNegatedImageFilter: 00114 public 00115 BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage, 00116 Functor::MaskNegatedInput< 00117 typename TInputImage::PixelType, 00118 typename TMaskImage::PixelType, 00119 typename TOutputImage::PixelType > > 00120 00121 { 00122 public: 00124 typedef MaskNegatedImageFilter Self; 00125 typedef BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage, 00126 Functor::MaskNegatedInput< 00127 typename TInputImage::PixelType, 00128 typename TMaskImage::PixelType, 00129 typename TOutputImage::PixelType > 00130 > Superclass; 00131 00132 typedef SmartPointer< Self > Pointer; 00133 typedef SmartPointer< const Self > ConstPointer; 00134 00136 itkNewMacro(Self); 00137 00139 itkTypeMacro(MaskNegatedImageFilter, 00140 BinaryFunctorImageFilter); 00141 00143 typedef TMaskImage MaskImageType; 00144 00146 void SetOutsideValue(const typename TOutputImage::PixelType & outsideValue) 00147 { 00148 if ( this->GetOutsideValue() != outsideValue ) 00149 { 00150 this->Modified(); 00151 this->GetFunctor().SetOutsideValue(outsideValue); 00152 } 00153 } 00155 00156 const typename TOutputImage::PixelType & GetOutsideValue() const 00157 { 00158 return this->GetFunctor().GetOutsideValue(); 00159 } 00160 00165 void SetMaskImage(const MaskImageType *maskImage) 00166 { 00167 // Process object is not const-correct so the const casting is required. 00168 this->SetNthInput( 1, const_cast< MaskImageType * >( maskImage ) ); 00169 } 00170 00171 const MaskImageType * GetMaskImage() 00172 { 00173 return static_cast<const MaskImageType*>(this->ProcessObject::GetInput(1)); 00174 } 00175 00176 #ifdef ITK_USE_CONCEPT_CHECKING 00177 00178 itkConceptMacro( MaskEqualityComparableCheck, 00179 ( Concept::EqualityComparable< typename TMaskImage::PixelType > ) ); 00180 itkConceptMacro( InputConvertibleToOutputCheck, 00181 ( Concept::Convertible< typename TInputImage::PixelType, 00182 typename TOutputImage::PixelType > ) ); 00183 00185 #endif 00186 protected: 00187 MaskNegatedImageFilter() {} 00188 virtual ~MaskNegatedImageFilter() {} 00190 00191 void PrintSelf(std::ostream & os, Indent indent) const 00192 { 00193 Superclass::PrintSelf(os, indent); 00194 os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl; 00195 } 00196 00197 private: 00198 MaskNegatedImageFilter(const Self &); //purposely not implemented 00199 void operator=(const Self &); //purposely not implemented 00200 }; 00201 } // end namespace itk 00202 00203 #endif 00204