ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkChangeLabelImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkChangeLabelImageFilter_h
19 #define __itkChangeLabelImageFilter_h
20 
22 #include "itkConceptChecking.h"
24 
25 namespace itk
26 {
49 #include <map>
50 
51 namespace Functor
52 {
53 template< class TInput, class TOutput >
55 {
56 public:
59 
60  typedef std::map< TInput, TOutput > ChangeMapType;
61 
62  bool operator!=(const ChangeLabel & other) const
63  {
64  if ( m_ChangeMap != other.m_ChangeMap )
65  {
66  return true;
67  }
68  return false;
69  }
70 
71  bool operator==(const ChangeLabel & other) const
72  {
73  return !( *this != other );
74  }
75 
76  TOutput GetChange(const TInput & original)
77  {
78  return m_ChangeMap[original];
79  }
80 
81  void SetChange(const TInput & original, const TOutput & result)
82  {
83  m_ChangeMap[original] = result;
84  }
85 
86  void SetChangeMap(const ChangeMapType & changeMap)
87  {
88  m_ChangeMap = changeMap;
89  }
90 
92  {
93  m_ChangeMap.clear();
94  }
95 
96  inline TOutput operator()(const TInput & A) const
97  {
98  const typename ChangeMapType::const_iterator it = m_ChangeMap.find(A);
99  if ( it != m_ChangeMap.end() )
100  {
101  return it->second;
102  }
103  return A;
104  }
105 
106 private:
108 };
109 }
110 
111 template< class TInputImage, class TOutputImage >
112 class ITK_EXPORT ChangeLabelImageFilter:
113  public
114  UnaryFunctorImageFilter< TInputImage, TOutputImage,
115  Functor::ChangeLabel<
116  typename TInputImage::PixelType,
117  typename TOutputImage::PixelType > >
118 {
119 public:
122  typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
124  typename TInputImage::PixelType,
125  typename TOutputImage::PixelType >
127 
130 
132  itkNewMacro(Self);
133 
136 
138  typedef typename TInputImage::PixelType InputPixelType;
139  typedef typename TOutputImage::PixelType OutputPixelType;
140 
142  typedef std::map< InputPixelType, OutputPixelType > ChangeMapType;
143 
145  void SetChange(const InputPixelType & original, const OutputPixelType & result);
146 
148  void SetChangeMap(const ChangeMapType & changeMap);
149 
151  void ClearChangeMap();
152 
153 #ifdef ITK_USE_CONCEPT_CHECKING
154 
155  itkConceptMacro( InputConvertibleToOutputCheck,
157  itkConceptMacro( PixelTypeComparable,
159 
161 #endif
162 protected:
165  void PrintSelf(std::ostream & os, Indent indent) const;
167 
168 private:
169  ChangeLabelImageFilter(const Self &); //purposely not implemented
170  void operator=(const Self &); //purposely not implemented
171 };
172 } // end namespace itk
173 
174 #ifndef ITK_MANUAL_INSTANTIATION
175 #include "itkChangeLabelImageFilter.hxx"
176 #endif
177 
178 #endif
179