/usr/include/OTB-5.8/otbNoDataHelper.h is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbNoDataHelper_h
#define otbNoDataHelper_h
#include <vector>
#include <cassert>
#include "vnl/vnl_math.h"
#include <itkVariableLengthVector.h>
#include "OTBMetadataExport.h"
namespace itk
{
class MetaDataDictionary;
}
namespace otb
{
/**
* Reads no data flag from the MetaDataDictionary dict to flags and values
* vectors. Returns true upon success.
*/
bool OTBMetadata_EXPORT ReadNoDataFlags(const itk::MetaDataDictionary& dict, std::vector<bool> & flags, std::vector<double> & values);
/**
* Write no data flags to the MetaDataDictionary dict from flags and values
* vectors. Returns true upon success.
*/
void OTBMetadata_EXPORT WriteNoDataFlags(const std::vector<bool> & flags, const std::vector<double> & values, itk::MetaDataDictionary& dict);
/**
* Test if the pixel corresponds to a no data pixel according to a
* vector of no data flags, and a vector of no data values.
* \param pixel The pixel to test
* \param flags A vector of size > 1 containing a flag per band to
* indicate if a no data value is available for this band
* \param values A vector of size > 1 corresponding to the no data
* value for each band. If flag is 0, the value will be ignored.
* \param nanIsNoData If true, NaN values will be reported as no-data.
*/
template<typename T> bool IsNoData(const T & pixel, const
std::vector<bool> & flags, const std::vector<double> & values, bool nanIsNoData = false) {
assert(flags.size()>0);
assert(values.size()>0);
if(nanIsNoData && vnl_math_isnan(values[0]))
return true;
if(flags[0])
{
return (pixel == values[0]);
}
else
{
return false;
}
}
/**
* Reads a pixel and change the no data value if it is found. No data
* value is changed either if the pixel value is NaN or if the pixel
* value equals the no data value and flag is true.
*
* \param pixel The pixel to process \param flags A vector of size > 1
* containing a flag per band to indicate if a no data value is
* available for this band
* \param values A vector of size > 1 corresponding to the current no data
* value for each band. If flag is 0, the value will be ignored.
* \param newValues A vector of size > 1 corresponding to the new no data
* value for each band. If flag is 0, the value will be ignored
* \param nanIsNoData If true, NaN values will be considered as no-data
* and changed as well.
*
*/
template<typename T> T ChangeNoData(const T & pixel, const
std::vector<bool> & flags,
const std::vector<double> & values,
const std::vector<double> & newValues,
bool nanIsNoData = false) {
assert(flags.size()>0);
assert(values.size()>0);
assert(newValues.size()>0);
if(nanIsNoData && vnl_math_isnan(pixel))
{
return static_cast<T>(newValues[0]);
}
if(flags[0] && pixel == values[0])
{
return static_cast<T>(newValues[0]);
}
return pixel;
}
/**
* Specialization of IsNoData function to handle itk::VariableLengthVector
*/
template <typename T> bool IsNoData(const itk::VariableLengthVector<T> & pixel, const std::vector<bool> & flags, const std::vector<double> & values, bool nanIsNoData = false)
{
assert(flags.size()>=pixel.Size());
assert(values.size()>=pixel.Size());
for(unsigned int i = 0; i < pixel.Size();++i)
{
if((nanIsNoData && vnl_math_isnan(pixel[i])) || (flags[i] && (pixel[i] == values[i])))
{
return true;
}
}
return false;
}
/**
* Specialization of ChangeNoData function to handle itk::VariableLengthVector
*/
template <typename T> itk::VariableLengthVector<T> ChangeNoData(const itk::VariableLengthVector<T> & pixel,
const std::vector<bool> & flags,
const std::vector<double> & values,
const std::vector<double> & newValues,
bool nanIsNoData = false)
{
assert(flags.size()>=pixel.Size());
assert(values.size()>=pixel.Size());
assert(newValues.size()>=pixel.Size());
itk::VariableLengthVector<T> outPixel(pixel.Size());
for(unsigned int i = 0; i < pixel.Size();++i)
{
if((nanIsNoData && vnl_math_isnan(pixel[i])) || (flags[i] && (pixel[i] == values[i])))
{
outPixel[i] = newValues[i];
}
else
{
outPixel[i] = pixel[i];
}
}
return outPixel;
}
} // End namespace otb
#endif
|