ITK  5.0.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 #include <map>
26 
27 namespace itk
28 {
50 namespace Functor
51 {
52 template< typename TInput, typename TOutput >
53 class ITK_TEMPLATE_EXPORT ChangeLabel
54 {
55 public:
56  ChangeLabel() = default;
57  ~ChangeLabel() = default;
58 
59  using ChangeMapType = std::map< TInput, TOutput >;
60 
61  bool operator!=(const ChangeLabel & other) const
62  {
63  if ( m_ChangeMap != other.m_ChangeMap )
64  {
65  return true;
66  }
67  return false;
68  }
69 
70  bool operator==(const ChangeLabel & other) const
71  {
72  return !( *this != other );
73  }
74 
75  TOutput GetChange(const TInput & original)
76  {
77  return m_ChangeMap[original];
78  }
79 
80  void SetChange(const TInput & original, const TOutput & result)
81  {
82  m_ChangeMap[original] = result;
83  }
84 
85  void SetChangeMap(const ChangeMapType & changeMap)
86  {
87  m_ChangeMap = changeMap;
88  }
89 
91  {
92  m_ChangeMap.clear();
93  }
94 
95  inline TOutput operator()(const TInput & A) const
96  {
97  const typename ChangeMapType::const_iterator it = m_ChangeMap.find(A);
98  if ( it != m_ChangeMap.end() )
99  {
100  return it->second;
101  }
102  return A;
103  }
104 
105 private:
107 };
108 }
109 
110 template< typename TInputImage, typename TOutputImage >
111 class ITK_TEMPLATE_EXPORT ChangeLabelImageFilter:
112  public
113  UnaryFunctorImageFilter< TInputImage, TOutputImage,
114  Functor::ChangeLabel<
115  typename TInputImage::PixelType,
116  typename TOutputImage::PixelType > >
117 {
118 public:
119  ITK_DISALLOW_COPY_AND_ASSIGN(ChangeLabelImageFilter);
120 
123  using Superclass = UnaryFunctorImageFilter< TInputImage, TOutputImage,
125  typename TInputImage::PixelType,
126  typename TOutputImage::PixelType >
127  >;
128 
131 
133  itkNewMacro(Self);
134 
137 
139  using InputPixelType = typename TInputImage::PixelType;
140  using OutputPixelType = typename TOutputImage::PixelType;
141 
143  using ChangeMapType = std::map< InputPixelType, OutputPixelType >;
144 
146  void SetChange(const InputPixelType & original, const OutputPixelType & result);
147 
149  void SetChangeMap(const ChangeMapType & changeMap);
150 
152  void ClearChangeMap();
153 
154 #ifdef ITK_USE_CONCEPT_CHECKING
155  // Begin concept checking
156  itkConceptMacro( InputConvertibleToOutputCheck,
158  itkConceptMacro( PixelTypeComparable,
160  // End concept checking
161 #endif
162 
163 protected:
164  ChangeLabelImageFilter() = default;
165  ~ChangeLabelImageFilter() override = default;
166  void PrintSelf(std::ostream & os, Indent indent) const override;
167 };
168 } // end namespace itk
169 
170 #ifndef ITK_MANUAL_INSTANTIATION
171 #include "itkChangeLabelImageFilter.hxx"
172 #endif
173 
174 #endif
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
void SetChangeMap(const ChangeMapType &changeMap)
Base class for all process objects that output image data.
std::map< TInputImage::PixelType, TOutputImage::PixelType > ChangeMapType
void SetChange(const TInput &original, const TOutput &result)
TOutput operator()(const TInput &A) const
typename TInputImage::PixelType InputPixelType
TOutput GetChange(const TInput &original)
std::map< InputPixelType, OutputPixelType > ChangeMapType
Implements pixel-wise generic operation on one image.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
#define itkConceptMacro(name, concept)
bool operator==(const ChangeLabel &other) const
bool operator!=(const ChangeLabel &other) const
typename TOutputImage::PixelType OutputPixelType