OTB  9.0.0
Orfeo Toolbox
otbChangeNoDataValueFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 otbChangeNoDataValueFilter_h
22 #define otbChangeNoDataValueFilter_h
23 
24 #include "itkUnaryFunctorImageFilter.h"
25 #include "itkMetaDataObject.h"
26 #include "otbMetaDataKey.h"
27 #include "otbNoDataHelper.h"
28 
29 namespace otb
30 {
31 namespace Functor
32 {
39 template <typename TInputPixel, typename TOutputPixel>
41 {
42 public:
44  {
45  }
46 
47  virtual ~ChangeNoDataFunctor() = default;
48 
49  inline TOutputPixel operator()(const TInputPixel& in) const
50  {
52  }
53 
54  std::vector<bool> m_Flags;
55  std::vector<double> m_Values;
56  std::vector<double> m_NewValues;
58 };
59 
60 } // End namespace Functor
61 
96 template <typename TInputImage, typename TOutputImage>
98  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
99  Functor::ChangeNoDataFunctor<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
100 {
101 public:
103 
105  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, FunctorType> Superclass;
106  typedef itk::SmartPointer<Self> Pointer;
107  typedef itk::SmartPointer<const Self> ConstPointer;
108 
110  itkNewMacro(Self);
111 
113  itkTypeMacro(ChangeNoDataValueFilter, itk::ImageToImageFilter);
114 
120  void SetNewNoDataValues(std::vector<double>& newValues)
121  {
122  this->GetFunctor().m_NewValues = newValues;
123  }
124 
130  void SetNaNIsNoData(bool nanIsNoData)
131  {
132  this->GetFunctor().m_NaNIsNoData = nanIsNoData;
133  }
134 
135 protected:
136  ChangeNoDataValueFilter() = default;
137 
138  ~ChangeNoDataValueFilter() override = default;
139 
141  {
142  Superclass::GenerateOutputInformation();
143 
144  std::vector<bool> noDataValueAvailable;
145  std::vector<double> noDataValues;
146 
147  bool ret = ReadNoDataFlags(this->GetInput()->GetImageMetadata(), noDataValueAvailable, noDataValues);
148 
149  if (!ret)
150  {
151  noDataValueAvailable.resize(this->GetInput()->GetNumberOfComponentsPerPixel(), false);
152  noDataValues.resize(this->GetInput()->GetNumberOfComponentsPerPixel(), 0);
153  }
154 
155  this->GetFunctor().m_Flags = noDataValueAvailable;
156  this->GetFunctor().m_Values = noDataValues;
157 
158  std::vector<bool> flags = noDataValueAvailable;
159 
160  if ((this->GetFunctor().m_NaNIsNoData) || (!ret))
161  {
162  flags = std::vector<bool>(flags.size(), true);
163  }
164 
165  WriteNoDataFlags(flags, this->GetFunctor().m_NewValues, this->GetOutput()->GetImageMetadata());
166  }
167 
168 private:
169  ChangeNoDataValueFilter(const Self&) = delete;
170  void operator=(const Self&) = delete;
171 };
172 
173 } // End namespace otb
174 
175 
176 #endif
otb::Functor::ChangeNoDataFunctor::~ChangeNoDataFunctor
virtual ~ChangeNoDataFunctor()=default
otb::Functor::ChangeNoDataFunctor::m_NaNIsNoData
bool m_NaNIsNoData
Definition: otbChangeNoDataValueFilter.h:57
otb::WriteNoDataFlags
void OTBMetadata_EXPORT WriteNoDataFlags(const std::vector< bool > &flags, const std::vector< double > &values, ImageMetadata &imd)
otb::ChangeNoDataValueFilter::FunctorType
Functor::ChangeNoDataFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: otbChangeNoDataValueFilter.h:102
otb::ChangeNoDataValueFilter::ChangeNoDataValueFilter
ChangeNoDataValueFilter()=default
otb::ChangeNoDataValueFilter
Change no-data flags and values and replace them in image.
Definition: otbChangeNoDataValueFilter.h:97
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ChangeNoDataValueFilter::Superclass
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, FunctorType > Superclass
Definition: otbChangeNoDataValueFilter.h:105
otb::ChangeNoData
T ChangeNoData(const T &pixel, const std::vector< bool > &flags, const std::vector< double > &values, const std::vector< double > &newValues, bool nanIsNoData=false)
Definition: otbNoDataHelper.h:89
otb::ReadNoDataFlags
bool OTBMetadata_EXPORT ReadNoDataFlags(const ImageMetadata &imd, std::vector< bool > &flags, std::vector< double > &values)
otb::Functor::ChangeNoDataFunctor::m_Flags
std::vector< bool > m_Flags
Definition: otbChangeNoDataValueFilter.h:54
otb::ChangeNoDataValueFilter::~ChangeNoDataValueFilter
~ChangeNoDataValueFilter() override=default
otb::Functor::ChangeNoDataFunctor
Functor used by ChangeNoDataValueFilter.
Definition: otbChangeNoDataValueFilter.h:40
otbNoDataHelper.h
otb::ChangeNoDataValueFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbChangeNoDataValueFilter.h:140
otb::Functor::ChangeNoDataFunctor::operator()
TOutputPixel operator()(const TInputPixel &in) const
Definition: otbChangeNoDataValueFilter.h:49
otb::ChangeNoDataValueFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbChangeNoDataValueFilter.h:106
otb::ChangeNoDataValueFilter::operator=
void operator=(const Self &)=delete
otb::ChangeNoDataValueFilter::Self
ChangeNoDataValueFilter Self
Definition: otbChangeNoDataValueFilter.h:104
otb::Functor::ChangeNoDataFunctor::m_Values
std::vector< double > m_Values
Definition: otbChangeNoDataValueFilter.h:55
otb::ChangeNoDataValueFilter::SetNaNIsNoData
void SetNaNIsNoData(bool nanIsNoData)
Definition: otbChangeNoDataValueFilter.h:130
otbMetaDataKey.h
otb::Functor::ChangeNoDataFunctor::m_NewValues
std::vector< double > m_NewValues
Definition: otbChangeNoDataValueFilter.h:56
otb::Functor::ChangeNoDataFunctor::ChangeNoDataFunctor
ChangeNoDataFunctor()
Definition: otbChangeNoDataValueFilter.h:43
otb::ChangeNoDataValueFilter::SetNewNoDataValues
void SetNewNoDataValues(std::vector< double > &newValues)
Definition: otbChangeNoDataValueFilter.h:120
otb::ChangeNoDataValueFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbChangeNoDataValueFilter.h:107