OTB  9.0.0
Orfeo Toolbox
otbImageToNoDataMaskFilter.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 otbImageToNoDataMaskFilter_h
22 #define otbImageToNoDataMaskFilter_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 ~NoDataFunctor() = 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  TOutputPixel m_OutsideValue;
57  TOutputPixel m_InsideValue;
59 };
60 
61 } // End namespace Functor
62 
63 
80 template <typename TInputImage, typename TOutputImage>
82  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, Functor::NoDataFunctor<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
83 {
84 public:
86 
88  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, FunctorType> Superclass;
89  typedef itk::SmartPointer<Self> Pointer;
90  typedef itk::SmartPointer<const Self> ConstPointer;
91 
93  itkNewMacro(Self);
94 
96  itkTypeMacro(SpectralAngleDistanceImageFilter, itk::ImageToImageFilter);
97 
102  void SetInsideValue(const typename TOutputImage::PixelType& value)
103  {
104  this->GetFunctor().m_InsideValue = value;
105  }
106 
111  void SetOutsideValue(const typename TOutputImage::PixelType& value)
112  {
113  this->GetFunctor().m_OutsideValue = value;
114  }
115 
121  void SetNaNIsNoData(bool nanIsNoData)
122  {
123  this->GetFunctor().m_NaNIsNoData = nanIsNoData;
124  }
125 
126 protected:
127  ImageToNoDataMaskFilter() = default;
128 
129  ~ImageToNoDataMaskFilter() = default;
130 
132  {
133  std::vector<bool> noDataValueAvailable;
134  std::vector<double> noDataValues;
135 
136  ReadNoDataFlags(this->GetInput()->GetImageMetadata(), noDataValueAvailable, noDataValues);
137 
138  // don't pass empty containers to the functor
139  if (noDataValueAvailable.empty() || noDataValues.empty())
140  {
141  const TInputImage* input = this->GetInput();
142  noDataValueAvailable.assign(input->GetNumberOfComponentsPerPixel(), false);
143  noDataValues.assign(input->GetNumberOfComponentsPerPixel(), 0.0);
144  }
145 
146  this->GetFunctor().m_Flags = noDataValueAvailable;
147  this->GetFunctor().m_Values = noDataValues;
148  }
149 
150 private:
151  ImageToNoDataMaskFilter(const Self&) = delete;
152  void operator=(const Self&) = delete;
153 };
154 
155 } // End namespace otb
156 
157 
158 #endif
otb::ImageToNoDataMaskFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageToNoDataMaskFilter.h:90
otb::ImageToNoDataMaskFilter::~ImageToNoDataMaskFilter
~ImageToNoDataMaskFilter()=default
otb::Functor::NoDataFunctor::~NoDataFunctor
virtual ~NoDataFunctor()=default
otb::ImageToNoDataMaskFilter::Self
ImageToNoDataMaskFilter Self
Definition: otbImageToNoDataMaskFilter.h:87
otb::Functor::NoDataFunctor::operator()
TOutputPixel operator()(const TInputPixel &in) const
Definition: otbImageToNoDataMaskFilter.h:49
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ReadNoDataFlags
bool OTBMetadata_EXPORT ReadNoDataFlags(const ImageMetadata &imd, std::vector< bool > &flags, std::vector< double > &values)
otb::SpectralAngleDistanceImageFilter
This filter implements the computation of the spectral angle distance with respect to a reference pix...
Definition: otbSpectralAngleDistanceImageFilter.h:55
otb::ImageToNoDataMaskFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: otbImageToNoDataMaskFilter.h:131
otb::Functor::NoDataFunctor::m_OutsideValue
TOutputPixel m_OutsideValue
Definition: otbImageToNoDataMaskFilter.h:56
otb::Functor::NoDataFunctor::m_NaNIsNoData
bool m_NaNIsNoData
Definition: otbImageToNoDataMaskFilter.h:58
otb::ImageToNoDataMaskFilter::FunctorType
Functor::NoDataFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: otbImageToNoDataMaskFilter.h:85
otbNoDataHelper.h
otb::IsNoData
bool IsNoData(const T &pixel, const std::vector< bool > &flags, const std::vector< double > &values, bool nanIsNoData=false)
Definition: otbNoDataHelper.h:63
otb::ImageToNoDataMaskFilter::ImageToNoDataMaskFilter
ImageToNoDataMaskFilter()=default
otb::Functor::NoDataFunctor
Functor used by ImageToNoDataMaskFilter.
Definition: otbImageToNoDataMaskFilter.h:40
otb::ImageToNoDataMaskFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageToNoDataMaskFilter.h:89
otb::Functor::NoDataFunctor::m_Flags
std::vector< bool > m_Flags
Definition: otbImageToNoDataMaskFilter.h:54
otbMetaDataKey.h
otb::Functor::NoDataFunctor::NoDataFunctor
NoDataFunctor()
Definition: otbImageToNoDataMaskFilter.h:43
otb::ImageToNoDataMaskFilter
Builds a no-data mask image from no-data flags and values.
Definition: otbImageToNoDataMaskFilter.h:81
otb::Functor::NoDataFunctor::m_InsideValue
TOutputPixel m_InsideValue
Definition: otbImageToNoDataMaskFilter.h:57
otb::ImageToNoDataMaskFilter::SetOutsideValue
void SetOutsideValue(const typename TOutputImage::PixelType &value)
Definition: otbImageToNoDataMaskFilter.h:111
otb::ImageToNoDataMaskFilter::Superclass
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, FunctorType > Superclass
Definition: otbImageToNoDataMaskFilter.h:88
otb::ImageToNoDataMaskFilter::SetInsideValue
void SetInsideValue(const typename TOutputImage::PixelType &value)
Definition: otbImageToNoDataMaskFilter.h:102
otb::Functor::NoDataFunctor::m_Values
std::vector< double > m_Values
Definition: otbImageToNoDataMaskFilter.h:55
otb::ImageToNoDataMaskFilter::operator=
void operator=(const Self &)=delete
otb::ImageToNoDataMaskFilter::SetNaNIsNoData
void SetNaNIsNoData(bool nanIsNoData)
Definition: otbImageToNoDataMaskFilter.h:121