diff --git a/Modules/Core/ImageBase/include/otbNoDataHelper.h b/Modules/Core/ImageBase/include/otbNoDataHelper.h index d626e49f296e87a9bb2fda4aa56016df063e2eff..0ae88dfe9d2586d1ba42c1661579aa44b5f68411 100644 --- a/Modules/Core/ImageBase/include/otbNoDataHelper.h +++ b/Modules/Core/ImageBase/include/otbNoDataHelper.h @@ -22,8 +22,26 @@ #include "vnl/vnl_math.h" #include <itkVariableLengthVector.h> +namespace itk +{ +class MetaDataDictionary; +} + namespace otb { + +/** + * Reads no data flag from the MetaDataDictionnary dict to flags and values + * vectors. Returns true upon success. + */ +bool ReadNoDataFlags(const itk::MetaDataDictionary& dict, std::vector<bool> & flags, std::vector<double> & values); + +/** + * Write no data flags to the MetaDataDictionnary dict from flags and values + * vectors. Returns true upon success. + */ +void 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. @@ -139,7 +157,6 @@ template <typename T> itk::VariableLengthVector<T> ChangeNoData(const itk::Varia } return outPixel; - } diff --git a/Modules/Core/ImageBase/src/CMakeLists.txt b/Modules/Core/ImageBase/src/CMakeLists.txt index d8017b85bd5968864da3a251b005f9b333859583..168521bf73d1b9f9894033f1a747131cc10d675e 100644 --- a/Modules/Core/ImageBase/src/CMakeLists.txt +++ b/Modules/Core/ImageBase/src/CMakeLists.txt @@ -1,5 +1,6 @@ set(OTBImageBase_SRC otbImageIOBase.cxx + otbNoDataHelper.cxx ) add_library(OTBImageBase ${OTBImageBase_SRC}) diff --git a/Modules/Core/ImageBase/src/otbNoDataHelper.cxx b/Modules/Core/ImageBase/src/otbNoDataHelper.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b5edf9dc49145ba6aae8e5089cc7a11335bf7037 --- /dev/null +++ b/Modules/Core/ImageBase/src/otbNoDataHelper.cxx @@ -0,0 +1,43 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#include "otbNoDataHelper.h" + +#include "itkMetaDataDictionary.h" +#include "itkMetaDataObject.h" +#include "otbMetaDataKey.h" + +namespace otb +{ + +bool ReadNoDataFlags(const itk::MetaDataDictionary& dict, std::vector<bool> & flags, std::vector<double> & values) +{ + bool ret = itk::ExposeMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,flags); + + if (ret) + ret = itk::ExposeMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,values); + + return ret; +} + +void WriteNoDataFlags(const std::vector<bool> & flags, const std::vector<double> & values, itk::MetaDataDictionary& dict) +{ + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,flags); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,values); +} + +} // End namespace otb