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 __itkChangeLabelImageFilter_h 00019 #define __itkChangeLabelImageFilter_h 00020 00021 #include "itkUnaryFunctorImageFilter.h" 00022 #include "itkConceptChecking.h" 00023 #include "itkSimpleDataObjectDecorator.h" 00024 00025 namespace itk 00026 { 00049 #include <map> 00050 00051 namespace Functor 00052 { 00053 template< class TInput, class TOutput > 00054 class ChangeLabel 00055 { 00056 public: 00057 ChangeLabel() {} 00058 ~ChangeLabel() {} 00059 00060 typedef std::map< TInput, TOutput > ChangeMapType; 00061 00062 bool operator!=(const ChangeLabel & other) const 00063 { 00064 if ( m_ChangeMap != other.m_ChangeMap ) 00065 { 00066 return true; 00067 } 00068 return false; 00069 } 00070 00071 bool operator==(const ChangeLabel & other) const 00072 { 00073 return !( *this != other ); 00074 } 00075 00076 TOutput GetChange(const TInput & original) 00077 { 00078 return m_ChangeMap[original]; 00079 } 00080 00081 void SetChange(const TInput & original, const TOutput & result) 00082 { 00083 m_ChangeMap[original] = result; 00084 } 00085 00086 void SetChangeMap(const ChangeMapType & changeMap) 00087 { 00088 m_ChangeMap = changeMap; 00089 } 00090 00091 void ClearChangeMap() 00092 { 00093 m_ChangeMap.clear(); 00094 } 00095 00096 inline TOutput operator()(const TInput & A) const 00097 { 00098 const typename ChangeMapType::const_iterator it = m_ChangeMap.find(A); 00099 if ( it != m_ChangeMap.end() ) 00100 { 00101 return it->second; 00102 } 00103 return A; 00104 } 00105 00106 private: 00107 ChangeMapType m_ChangeMap; 00108 }; 00109 } 00110 00111 template< class TInputImage, class TOutputImage > 00112 class ITK_EXPORT ChangeLabelImageFilter: 00113 public 00114 UnaryFunctorImageFilter< TInputImage, TOutputImage, 00115 Functor::ChangeLabel< 00116 typename TInputImage::PixelType, 00117 typename TOutputImage::PixelType > > 00118 { 00119 public: 00121 typedef ChangeLabelImageFilter Self; 00122 typedef UnaryFunctorImageFilter< TInputImage, TOutputImage, 00123 Functor::ChangeLabel< 00124 typename TInputImage::PixelType, 00125 typename TOutputImage::PixelType > 00126 > Superclass; 00127 00128 typedef SmartPointer< Self > Pointer; 00129 typedef SmartPointer< const Self > ConstPointer; 00130 00132 itkNewMacro(Self); 00133 00135 itkTypeMacro(ChangeLabelImageFilter, UnaryFunctorImageFilter); 00136 00138 typedef typename TInputImage::PixelType InputPixelType; 00139 typedef typename TOutputImage::PixelType OutputPixelType; 00140 00142 typedef std::map< InputPixelType, OutputPixelType > ChangeMapType; 00143 00145 void SetChange(const InputPixelType & original, const OutputPixelType & result); 00146 00148 void SetChangeMap(const ChangeMapType & changeMap); 00149 00151 void ClearChangeMap(); 00152 00153 #ifdef ITK_USE_CONCEPT_CHECKING 00154 00155 itkConceptMacro( InputConvertibleToOutputCheck, 00156 ( Concept::Convertible< InputPixelType, OutputPixelType > ) ); 00157 itkConceptMacro( PixelTypeComparable, 00158 ( Concept::Comparable< InputPixelType > ) ); 00159 00161 #endif 00162 protected: 00163 ChangeLabelImageFilter(); 00164 virtual ~ChangeLabelImageFilter() {} 00165 void PrintSelf(std::ostream & os, Indent indent) const; 00167 00168 private: 00169 ChangeLabelImageFilter(const Self &); //purposely not implemented 00170 void operator=(const Self &); //purposely not implemented 00171 }; 00172 } // end namespace itk 00173 00174 #ifndef ITK_MANUAL_INSTANTIATION 00175 #include "itkChangeLabelImageFilter.hxx" 00176 #endif 00177 00178 #endif 00179