ITK  6.0.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  using ChangeMapType = std::map<TInput, TOutput>;
58 
59 
60  bool
61  operator==(const ChangeLabel & other) const
62  {
63  return m_ChangeMap == other.m_ChangeMap;
64  }
65 
66  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ChangeLabel);
67 
68  TOutput
69  GetChange(const TInput & original)
70  {
71  return m_ChangeMap[original];
72  }
73 
74  void
75  SetChange(const TInput & original, const TOutput & result)
76  {
77  m_ChangeMap[original] = result;
78  }
79 
80  void
81  SetChangeMap(const ChangeMapType & changeMap)
82  {
83  m_ChangeMap = changeMap;
84  }
85 
86  void
88  {
89  m_ChangeMap.clear();
90  }
91 
92  inline TOutput
93  operator()(const TInput & A) const
94  {
95  const typename ChangeMapType::const_iterator it = m_ChangeMap.find(A);
96  if (it != m_ChangeMap.end())
97  {
98  return it->second;
99  }
100  return A;
101  }
102 
103 private:
105 };
106 } // namespace Functor
107 
108 template <typename TInputImage, typename TOutputImage>
109 class ITK_TEMPLATE_EXPORT ChangeLabelImageFilter
110  : public UnaryFunctorImageFilter<
111  TInputImage,
112  TOutputImage,
113  Functor::ChangeLabel<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
114 {
115 public:
116  ITK_DISALLOW_COPY_AND_MOVE(ChangeLabelImageFilter);
117 
120  using Superclass =
121  UnaryFunctorImageFilter<TInputImage,
122  TOutputImage,
124 
127 
129  itkNewMacro(Self);
130 
132  itkOverrideGetNameOfClassMacro(ChangeLabelImageFilter);
133 
135  using InputPixelType = typename TInputImage::PixelType;
136  using OutputPixelType = typename TOutputImage::PixelType;
137 
139  using ChangeMapType = std::map<InputPixelType, OutputPixelType>;
140 
142  void
143  SetChange(const InputPixelType & original, const OutputPixelType & result);
144 
146  void
147  SetChangeMap(const ChangeMapType & changeMap);
148 
150  void
151  ClearChangeMap();
152 
153 #ifdef ITK_USE_CONCEPT_CHECKING
154  // Begin concept checking
157  // End concept checking
158 #endif
159 
160 protected:
161  ChangeLabelImageFilter() = default;
162  ~ChangeLabelImageFilter() override = default;
163  void
164  PrintSelf(std::ostream & os, Indent indent) const override;
165 };
166 } // end namespace itk
167 
168 #ifndef ITK_MANUAL_INSTANTIATION
169 # include "itkChangeLabelImageFilter.hxx"
170 #endif
171 
172 #endif
itk::Functor::ChangeLabel::operator()
TOutput operator()(const TInput &A) const
Definition: itkChangeLabelImageFilter.h:93
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:81
itkConceptChecking.h
itk::Functor::ChangeLabel< TInputImage::PixelType, TOutputImage::PixelType >::ChangeMapType
std::map< TInputImage::PixelType, TOutputImage::PixelType > ChangeMapType
Definition: itkChangeLabelImageFilter.h:57
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:75
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:135
itk::Functor::ChangeLabel::operator==
bool operator==(const ChangeLabel &other) const
Definition: itkChangeLabelImageFilter.h:61
itk::Functor::ChangeLabel::m_ChangeMap
ChangeMapType m_ChangeMap
Definition: itkChangeLabelImageFilter.h:104
itk::Functor::ChangeLabel
Definition: itkChangeLabelImageFilter.h:54
itk::ChangeLabelImageFilter
Change Sets of Labels.
Definition: itkChangeLabelImageFilter.h:109
itk::Functor::ChangeLabel::GetChange
TOutput GetChange(const TInput &original)
Definition: itkChangeLabelImageFilter.h:69
itk::ChangeLabelImageFilter::ChangeMapType
std::map< InputPixelType, OutputPixelType > ChangeMapType
Definition: itkChangeLabelImageFilter.h:139
itk::Functor::ChangeLabel::ClearChangeMap
void ClearChangeMap()
Definition: itkChangeLabelImageFilter.h:87
itk::Concept::Comparable
Definition: itkConceptChecking.h:331
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
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:136