OTB  6.7.0
Orfeo Toolbox
otbImageToNoDataMaskFilter.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 otbImageToNoDataMaskFilter_h
22 #define otbImageToNoDataMaskFilter_h
23 
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  m_Flags(),
45  m_Values(),
46  m_OutsideValue(0),
47  m_InsideValue(1),
48  m_NaNIsNoData(false)
49  {}
50  virtual ~NoDataFunctor(){}
51 
52  inline TOutputPixel operator()(const TInputPixel& in) const
53  {
55  }
56 
57  std::vector<bool> m_Flags;
58  std::vector<double> m_Values;
59  TOutputPixel m_OutsideValue;
60  TOutputPixel m_InsideValue;
62 };
63 
64 } // End namespace Functor
65 
66 
83 template <typename TInputImage, typename TOutputImage>
85  : public itk::UnaryFunctorImageFilter<TInputImage,
86  TOutputImage,
87  Functor::NoDataFunctor<typename TInputImage::PixelType,
88  typename TOutputImage::PixelType> >
89 {
90 public:
92 
94  typedef itk::UnaryFunctorImageFilter<TInputImage,
95  TOutputImage,
99 
101  itkNewMacro(Self);
102 
105 
110  void SetInsideValue(const typename TOutputImage::PixelType & value)
111  {
112  this->GetFunctor().m_InsideValue = value;
113  }
114 
119  void SetOutsideValue(const typename TOutputImage::PixelType & value)
120  {
121  this->GetFunctor().m_OutsideValue = value;
122  }
123 
129  void SetNaNIsNoData(bool nanIsNoData)
130  {
131  this->GetFunctor().m_NaNIsNoData=nanIsNoData;
132  }
133 
134 protected:
136  {}
137 
139  {}
140 
142  {
143  std::vector<bool> noDataValueAvailable;
144  std::vector<double> noDataValues;
145 
146  ReadNoDataFlags(this->GetInput()->GetMetaDataDictionary(),noDataValueAvailable,noDataValues);
147 
148  // don't pass empty containers to the functor
149  if (noDataValueAvailable.empty() || noDataValues.empty())
150  {
151  const TInputImage* input = this->GetInput();
152  noDataValueAvailable.assign(input->GetNumberOfComponentsPerPixel(),false);
153  noDataValues.assign(input->GetNumberOfComponentsPerPixel(),0.0);
154  }
155 
156  this->GetFunctor().m_Flags = noDataValueAvailable;
157  this->GetFunctor().m_Values = noDataValues;
158  }
159 
160 private:
161  ImageToNoDataMaskFilter(const Self&) = delete;
162  void operator =(const Self&) = delete;
163 };
164 
165 } // End namespace otb
166 
167 
168 
169 #endif
This filter implements the computation of the spectral angle distance with respect to a reference pix...
void operator=(const Self &)=delete
void SetOutsideValue(const typename TOutputImage::PixelType &value)
Functor::NoDataFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
bool OTBMetadata_EXPORT ReadNoDataFlags(const itk::MetaDataDictionary &dict, std::vector< bool > &flags, std::vector< double > &values)
MetaDataDictionary & GetMetaDataDictionary()
Functor used by ImageToNoDataMaskFilter.
bool IsNoData(const T &pixel, const std::vector< bool > &flags, const std::vector< double > &values, bool nanIsNoData=false)
const InputImageType * GetInput() const
TOutputPixel operator()(const TInputPixel &in) const
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, FunctorType > Superclass
void SetInsideValue(const typename TOutputImage::PixelType &value)
Builds a no-data mask image from no-data flags and values.
itk::SmartPointer< const Self > ConstPointer