OTB  6.7.0
Orfeo Toolbox
otbChangeLabelImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbChangeLabelImageFilter_h
22 #define otbChangeLabelImageFilter_h
23 
25 #include "itkConceptChecking.h"
27 
28 #include <map>
29 
30 namespace otb
31 {
32 
43 namespace Functor {
44 
45 template<class TInput, class TOutput>
47 {
48 public:
49  typedef typename TOutput::ValueType ValueType;
50 
52  virtual ~VectorChangeLabel() {}
53 
54  typedef std::map<TInput, TOutput> ChangeMapType;
55 
56  void SetNumberOfComponentsPerPixel(unsigned int nb)
57  {
59  }
61  {
63  }
64  bool operator !=(const VectorChangeLabel& other) const
65  {
66  if (m_ChangeMap != other.m_ChangeMap)
67  {
68  return true;
69  }
70  return false;
71  }
72  bool operator ==(const VectorChangeLabel& other) const
73  {
74  return !(*this != other);
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)
97  {
98  TOutput out;
99  out.SetSize(m_NumberOfComponentsPerPixel);
100 
101  if (m_ChangeMap.find(A) != m_ChangeMap.end())
102  {
103  out = m_ChangeMap[A];
104  }
105  else
106  {
107  out.Fill(static_cast<ValueType>(A));
108  }
109  return out;
110  }
111 
112 private:
115 };
116 }
117 
118 template <class TInputImage, class TOutputImage>
119 class ITK_EXPORT ChangeLabelImageFilter :
120  public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
121  Functor::VectorChangeLabel<typename TInputImage::PixelType,
122  typename TOutputImage::PixelType> >
123 {
124 public:
127  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
129  typename TInputImage::PixelType,
130  typename TOutputImage::PixelType>
134 
136  itkNewMacro(Self);
137 
140 
142  typedef typename TInputImage::PixelType InputPixelType;
143  typedef typename TOutputImage::PixelType OutputPixelType;
144 
146  typedef std::map<InputPixelType, OutputPixelType> ChangeMapType;
147 
149  void SetChange(const InputPixelType& original, const OutputPixelType& result);
150 
152  void SetChangeMap(const ChangeMapType& changeMap);
153 
155  void ClearChangeMap();
156 
158  void SetNumberOfComponentsPerPixel(unsigned int nb)
159  {
160  m_NumberOfComponentsPerPixel = nb;
161  this->GetFunctor().SetNumberOfComponentsPerPixel(m_NumberOfComponentsPerPixel);
162  this->Modified();
163  }
164  itkGetMacro(NumberOfComponentsPerPixel, unsigned int);
166 
167 protected:
171  void GenerateOutputInformation() override;
172 
173  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
174 
175 private:
176  ChangeLabelImageFilter(const Self &) = delete;
177  void operator =(const Self&) = delete;
178 
181 };
182 
183 } // end namespace otb
184 
185 #ifndef OTB_MANUAL_INSTANTIATION
187 #endif
188 
189 #endif
itk::SmartPointer< const Self > ConstPointer
bool operator==(const VectorChangeLabel &other) const
bool operator!=(const VectorChangeLabel &other) const
void SetChangeMap(const ChangeMapType &changeMap)
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::VectorChangeLabel< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
void SetChange(const TInput &original, const TOutput &result)
TOutputImage::PixelType OutputPixelType
std::map< InputPixelType, OutputPixelType > ChangeMapType
unsigned int m_NumberOfComponentsPerPixel
Number of components per pixel.
TOutput GetChange(const TInput &original)
std::map< TInput, TOutput > ChangeMapType
void SetNumberOfComponentsPerPixel(unsigned int nb)
itk::SmartPointer< Self > Pointer
void SetNumberOfComponentsPerPixel(unsigned int nb)