OTB  10.0.0
Orfeo Toolbox
otbImageToNoDataMaskFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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:
128 
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
Functor used by ImageToNoDataMaskFilter.
virtual ~NoDataFunctor()=default
TOutputPixel operator()(const TInputPixel &in) const
Builds a no-data mask image from no-data flags and values.
void SetInsideValue(const typename TOutputImage::PixelType &value)
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, FunctorType > Superclass
void operator=(const Self &)=delete
ImageToNoDataMaskFilter(const Self &)=delete
void SetOutsideValue(const typename TOutputImage::PixelType &value)
itk::SmartPointer< const Self > ConstPointer
Functor::NoDataFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
This filter implements the computation of the spectral angle distance with respect to a reference pix...
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
bool OTBMetadata_EXPORT ReadNoDataFlags(const ImageMetadata &imd, std::vector< bool > &flags, std::vector< double > &values)
bool IsNoData(const T &pixel, const std::vector< bool > &flags, const std::vector< double > &values, bool nanIsNoData=false)