ITK  5.3.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  * https://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;
61  using ChangeMapType = std::map<TInput, TOutput>;
62 
63 
64  bool
65  operator==(const ChangeLabel & other) const
66  {
67  return m_ChangeMap == other.m_ChangeMap;
68  }
69 
70  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ChangeLabel);
71 
72  TOutput
73  GetChange(const TInput & original)
74  {
75  return m_ChangeMap[original];
76  }
77 
78  void
79  SetChange(const TInput & original, const TOutput & result)
80  {
81  m_ChangeMap[original] = result;
82  }
83 
84  void
85  SetChangeMap(const ChangeMapType & changeMap)
86  {
87  m_ChangeMap = changeMap;
88  }
89 
90  void
92  {
93  m_ChangeMap.clear();
94  }
95 
96  inline TOutput
97  operator()(const TInput & A) const
98  {
99  const typename ChangeMapType::const_iterator it = m_ChangeMap.find(A);
100  if (it != m_ChangeMap.end())
101  {
102  return it->second;
103  }
104  return A;
105  }
106 
107 private:
109 };
110 } // namespace Functor
111 
112 template <typename TInputImage, typename TOutputImage>
113 class ITK_TEMPLATE_EXPORT ChangeLabelImageFilter
114  : public UnaryFunctorImageFilter<
115  TInputImage,
116  TOutputImage,
117  Functor::ChangeLabel<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
118 {
119 public:
120  ITK_DISALLOW_COPY_AND_MOVE(ChangeLabelImageFilter);
121 
124  using Superclass =
125  UnaryFunctorImageFilter<TInputImage,
126  TOutputImage,
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
147  SetChange(const InputPixelType & original, const OutputPixelType & result);
148 
150  void
151  SetChangeMap(const ChangeMapType & changeMap);
152 
154  void
155  ClearChangeMap();
156 
157 #ifdef ITK_USE_CONCEPT_CHECKING
158  // Begin concept checking
161  // End concept checking
162 #endif
163 
164 protected:
165  ChangeLabelImageFilter() = default;
166  ~ChangeLabelImageFilter() override = default;
167  void
168  PrintSelf(std::ostream & os, Indent indent) const override;
169 };
170 } // end namespace itk
171 
172 #ifndef ITK_MANUAL_INSTANTIATION
173 # include "itkChangeLabelImageFilter.hxx"
174 #endif
175 
176 #endif
itk::Functor::ChangeLabel::operator()
TOutput operator()(const TInput &A) const
Definition: itkChangeLabelImageFilter.h:97
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:85
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:79
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:139
itk::Functor::ChangeLabel::operator==
bool operator==(const ChangeLabel &other) const
Definition: itkChangeLabelImageFilter.h:65
itk::Functor::ChangeLabel::m_ChangeMap
ChangeMapType m_ChangeMap
Definition: itkChangeLabelImageFilter.h:108
itk::Functor::ChangeLabel
Definition: itkChangeLabelImageFilter.h:54
itk::ChangeLabelImageFilter
Change Sets of Labels.
Definition: itkChangeLabelImageFilter.h:113
itk::Functor::ChangeLabel::GetChange
TOutput GetChange(const TInput &original)
Definition: itkChangeLabelImageFilter.h:73
itk::ChangeLabelImageFilter::ChangeMapType
std::map< InputPixelType, OutputPixelType > ChangeMapType
Definition: itkChangeLabelImageFilter.h:143
itk::Functor::ChangeLabel::ClearChangeMap
void ClearChangeMap()
Definition: itkChangeLabelImageFilter.h:91
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:139
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itkSimpleDataObjectDecorator.h
itk::ChangeLabelImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkChangeLabelImageFilter.h:140