ITK  5.2.0
Insight Toolkit
itkChangeLabelImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
51 namespace Functor
52 {
53 template <typename TInput, typename TOutput>
54 class ITK_TEMPLATE_EXPORT ChangeLabel
55 {
56 public:
57  ChangeLabel() = default;
58  ~ChangeLabel() = default;
60 
61  using ChangeMapType = std::map<TInput, TOutput>;
62 
63  bool
64  operator!=(const ChangeLabel & other) const
65  {
66  if (m_ChangeMap != other.m_ChangeMap)
67  {
68  return true;
69  }
70  return false;
71  }
72 
73  bool
74  operator==(const ChangeLabel & other) const
75  {
76  return !(*this != other);
77  }
78 
79  TOutput
80  GetChange(const TInput & original)
81  {
82  return m_ChangeMap[original];
83  }
84 
85  void
86  SetChange(const TInput & original, const TOutput & result)
87  {
88  m_ChangeMap[original] = result;
89  }
90 
91  void
92  SetChangeMap(const ChangeMapType & changeMap)
93  {
94  m_ChangeMap = changeMap;
95  }
96 
97  void
99  {
100  m_ChangeMap.clear();
101  }
102 
103  inline TOutput
104  operator()(const TInput & A) const
105  {
106  const typename ChangeMapType::const_iterator it = m_ChangeMap.find(A);
107  if (it != m_ChangeMap.end())
108  {
109  return it->second;
110  }
111  return A;
112  }
113 
114 private:
116 };
117 } // namespace Functor
118 
119 template <typename TInputImage, typename TOutputImage>
120 class ITK_TEMPLATE_EXPORT ChangeLabelImageFilter
121  : public UnaryFunctorImageFilter<
122  TInputImage,
123  TOutputImage,
124  Functor::ChangeLabel<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
125 {
126 public:
127  ITK_DISALLOW_COPY_AND_MOVE(ChangeLabelImageFilter);
128 
131  using Superclass =
132  UnaryFunctorImageFilter<TInputImage,
133  TOutputImage,
135 
138 
140  itkNewMacro(Self);
141 
144 
146  using InputPixelType = typename TInputImage::PixelType;
147  using OutputPixelType = typename TOutputImage::PixelType;
148 
150  using ChangeMapType = std::map<InputPixelType, OutputPixelType>;
151 
153  void
154  SetChange(const InputPixelType & original, const OutputPixelType & result);
155 
157  void
158  SetChangeMap(const ChangeMapType & changeMap);
159 
161  void
162  ClearChangeMap();
163 
164 #ifdef ITK_USE_CONCEPT_CHECKING
165  // Begin concept checking
168  // End concept checking
169 #endif
170 
171 protected:
172  ChangeLabelImageFilter() = default;
173  ~ChangeLabelImageFilter() override = default;
174  void
175  PrintSelf(std::ostream & os, Indent indent) const override;
176 };
177 } // end namespace itk
178 
179 #ifndef ITK_MANUAL_INSTANTIATION
180 # include "itkChangeLabelImageFilter.hxx"
181 #endif
182 
183 #endif
itk::Functor::ChangeLabel::operator()
TOutput operator()(const TInput &A) const
Definition: itkChangeLabelImageFilter.h:104
itkUnaryFunctorImageFilter.h
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::Functor::ChangeLabel::SetChangeMap
void SetChangeMap(const ChangeMapType &changeMap)
Definition: itkChangeLabelImageFilter.h:92
itkConceptChecking.h
itk::Functor::ChangeLabel< TInputImage::PixelType, TOutputImage::PixelType >::ChangeMapType
std::map< TInputImage::PixelType, TOutputImage::PixelType > ChangeMapType
Definition: itkChangeLabelImageFilter.h:61
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Functor::ChangeLabel::SetChange
void SetChange(const TInput &original, const TOutput &result)
Definition: itkChangeLabelImageFilter.h:86
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::ChangeLabelImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkChangeLabelImageFilter.h:146
itk::Functor::ChangeLabel::operator==
bool operator==(const ChangeLabel &other) const
Definition: itkChangeLabelImageFilter.h:74
itk::Functor::ChangeLabel::m_ChangeMap
ChangeMapType m_ChangeMap
Definition: itkChangeLabelImageFilter.h:115
itk::Functor::ChangeLabel
Definition: itkChangeLabelImageFilter.h:54
itk::ChangeLabelImageFilter
Change Sets of Labels.
Definition: itkChangeLabelImageFilter.h:120
itk::Functor::ChangeLabel::GetChange
TOutput GetChange(const TInput &original)
Definition: itkChangeLabelImageFilter.h:80
itk::ChangeLabelImageFilter::ChangeMapType
std::map< InputPixelType, OutputPixelType > ChangeMapType
Definition: itkChangeLabelImageFilter.h:150
itk::Functor::ChangeLabel::ClearChangeMap
void ClearChangeMap()
Definition: itkChangeLabelImageFilter.h:98
itk::Concept::Comparable
Definition: itkConceptChecking.h:330
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itk::Functor::ChangeLabel::operator!=
bool operator!=(const ChangeLabel &other) const
Definition: itkChangeLabelImageFilter.h:64
itkSimpleDataObjectDecorator.h
itk::ChangeLabelImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkChangeLabelImageFilter.h:147