21 #ifndef otbNoDataHelper_h
22 #define otbNoDataHelper_h
25 #include "vnl/vnl_math.h"
26 #include <itkVariableLengthVector.h>
27 #include "OTBMetadataExport.h"
33 class MetaDataDictionary;
42 bool OTBMetadata_EXPORT
ReadNoDataFlags(
const ImageMetadata & imd, std::vector<bool>& flags, std::vector<double>& values);
48 void OTBMetadata_EXPORT
WriteNoDataFlags(
const std::vector<bool>& flags,
const std::vector<double>& values, ImageMetadata & imd);
63 bool IsNoData(
const T& pixel,
const std::vector<bool>& flags,
const std::vector<double>& values,
bool nanIsNoData =
false)
65 assert(flags.size() > 0);
66 assert(values.size() > 0);
69 return ((nanIsNoData && vnl_math_isnan(pixel)) || (flags[0] && (pixel == values[0])));
89 T
ChangeNoData(
const T& pixel,
const std::vector<bool>& flags,
const std::vector<double>& values,
const std::vector<double>& newValues,
90 bool nanIsNoData =
false)
92 assert(flags.size() > 0);
93 assert(values.size() > 0);
94 assert(newValues.size() > 0);
97 if (nanIsNoData && vnl_math_isnan(pixel))
99 return static_cast<T
>(newValues[0]);
102 if (flags[0] && pixel == values[0])
104 return static_cast<T
>(newValues[0]);
113 template <
typename T>
114 bool IsNoData(
const itk::VariableLengthVector<T>& pixel,
const std::vector<bool>& flags,
const std::vector<double>& values,
bool nanIsNoData =
false)
116 assert(flags.size() >= pixel.Size());
117 assert(values.size() >= pixel.Size());
120 for (
unsigned int i = 0; i < pixel.Size(); ++i)
122 if ((nanIsNoData && vnl_math_isnan(pixel[i])) || (flags[i] && (pixel[i] == values[i])))
134 template <
typename T>
135 itk::VariableLengthVector<T>
ChangeNoData(
const itk::VariableLengthVector<T>& pixel,
const std::vector<bool>& flags,
const std::vector<double>& values,
136 const std::vector<double>& newValues,
bool nanIsNoData =
false)
138 assert(flags.size() >= pixel.Size());
139 assert(values.size() >= pixel.Size());
140 assert(newValues.size() >= pixel.Size());
143 itk::VariableLengthVector<T> outPixel(pixel.Size());
145 for (
unsigned int i = 0; i < pixel.Size(); ++i)
147 if ((nanIsNoData && vnl_math_isnan(pixel[i])) || (flags[i] && (pixel[i] == values[i])))
149 outPixel[i] = newValues[i];
153 outPixel[i] = pixel[i];