Commit 5a111713 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

REFAC: use ImageMetadata instead of itk dictionary to manage no data

parent 20be588e
Pipeline #8915 passed with stages
in 98 minutes and 16 seconds
......@@ -162,10 +162,10 @@ private:
m_MaskFilters.clear();
UInt8ImageType::Pointer maskPtr = this->GetParameterUInt8Image("mode.apply.mask");
unsigned int nbBands = inputPtr->GetNumberOfComponentsPerPixel();
itk::MetaDataDictionary& dict = inputPtr->GetMetaDataDictionary();
const auto & imd = inputPtr->GetImageMetadata();
std::vector<bool> flags;
std::vector<double> values;
bool ret = otb::ReadNoDataFlags(dict, flags, values);
bool ret = otb::ReadNoDataFlags(imd, flags, values);
if (!ret)
{
flags.resize(nbBands, true);
......
......@@ -23,6 +23,7 @@
#include "otbCoordinateToName.h"
#include "otbGroundSpacingImageFunction.h"
#include "vnl/vnl_random.h"
#include "otbNoDataHelper.h"
namespace otb
{
......@@ -272,10 +273,9 @@ private:
ossOutput << "\tData type : " << GetParameterString("datatype") << std::endl;
std::vector<bool> noDataValueAvailable;
bool ret = itk::ExposeMetaData<std::vector<bool>>(inImage->GetMetaDataDictionary(), MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
std::vector<double> noDataValues;
itk::ExposeMetaData<std::vector<double>>(inImage->GetMetaDataDictionary(), MetaDataKey::NoDataValue, noDataValues);
auto ret = ReadNoDataFlags(inImage->GetImageMetadata(), noDataValueAvailable, noDataValues);
ossOutput << "\tNo data flags :";
......
......@@ -465,8 +465,8 @@ private:
std::vector<bool> noDataFlags;
std::vector<double> noDataValues;
itk::MetaDataDictionary& dict = GetParameterFloatVectorImage("in")->GetMetaDataDictionary();
bool ret = otb::ReadNoDataFlags(dict, noDataFlags, noDataValues);
const auto & imd = GetParameterFloatVectorImage("in")->GetImageMetadata();
bool ret = otb::ReadNoDataFlags(imd, noDataFlags, noDataValues);
if (ret)
{
......
......@@ -107,12 +107,6 @@ public:
double GetGCPZ(unsigned int GCPnum) const;
// otbMetadataGetGCPnumMacro(GCPZ, double, GCPnum, unsigned int);
/**
* Get The no data flags if existing
* return False otherwise
*/
bool GetNoDataFlags(std::vector<bool>& flags, std::vector<double>& values) const;
/** Get the six coefficients of affine geoTtransform. */
VectorType GetGeoTransform() const;
......
......@@ -21,7 +21,6 @@
#include "otbImageMetadataInterfaceBase.h"
#include "otbNoDataHelper.h"
#include "otbGeometryMetadata.h"
#include "itkMetaDataObject.h"
#include "itksys/SystemTools.hxx"
......@@ -244,11 +243,6 @@ double ImageMetadataInterfaceBase::GetGCPZ(unsigned int GCPnum) const
return (0);
}
bool ImageMetadataInterfaceBase::GetNoDataFlags(std::vector<bool>& flags, std::vector<double>& values) const
{
return ReadNoDataFlags(this->GetMetaDataDictionary(), flags, values);
}
ImageMetadataInterfaceBase::VectorType ImageMetadataInterfaceBase::GetGeoTransform() const
{
VectorType adfGeoTransform;
......
......@@ -28,10 +28,10 @@ int otbNoDataHelperTest(int itkNotUsed(argc), char* itkNotUsed(argv)[])
std::vector<bool> b1(1, true);
std::vector<double> v1(1, 0);
itk::MetaDataDictionary dict;
otb::ImageMetadata imd;
otb::WriteNoDataFlags(b1, v1, dict);
otb::ReadNoDataFlags(dict, b1, v1);
otb::WriteNoDataFlags(b1, v1, imd);
otb::ReadNoDataFlags(imd, b1, v1);
otbControlConditionTestMacro(otb::IsNoData(10, b1, v1), " wrong output of IsNoData function");
otbControlConditionTestMacro(!otb::IsNoData(0, b1, v1), " wrong output of IsNoData function");
......
......@@ -27,6 +27,7 @@
#include "itkDefaultConvertPixelTraits.h"
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
#include "otbNoDataHelper.h"
namespace otb
{
......@@ -253,19 +254,17 @@ void StreamingWarpImageFilter<TInputImage, TOutputImage, TDisplacementField>::Ge
Superclass::GenerateOutputInformation();
// Set the NoData flag to the edge padding value
itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary();
std::vector<bool> noDataValueAvailable;
bool ret = itk::ExposeMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
if (!ret)
std::vector<double> noDataValue;
auto res = ReadNoDataFlags(this->GetOutput()->GetImageMetadata(), noDataValueAvailable, noDataValue);
if (!res)
{
noDataValueAvailable.resize(this->GetOutput()->GetNumberOfComponentsPerPixel(), false);
}
std::vector<double> noDataValue;
ret = itk::ExposeMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
if (!ret)
{
noDataValue.resize(this->GetOutput()->GetNumberOfComponentsPerPixel(), 0.0);
}
PixelType edgePadding = this->GetEdgePaddingValue();
if (itk::NumericTraits<PixelType>::GetLength(edgePadding) != this->GetOutput()->GetNumberOfComponentsPerPixel())
{
......@@ -280,8 +279,8 @@ void StreamingWarpImageFilter<TInputImage, TOutputImage, TDisplacementField>::Ge
noDataValue[i] = itk::DefaultConvertPixelTraits<PixelType>::GetNthComponent(i, edgePadding);
}
}
itk::EncapsulateMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
itk::EncapsulateMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
WriteNoDataFlags(noDataValueAvailable, noDataValue, this->GetOutput()->GetImageMetadata());
}
template <class TInputImage, class TOutputImage, class TDisplacementField>
......
......@@ -43,9 +43,8 @@ public:
ChangeNoDataFunctor() : m_Flags(), m_Values(), m_NewValues(), m_NaNIsNoData(false)
{
}
virtual ~ChangeNoDataFunctor()
{
}
virtual ~ChangeNoDataFunctor() = default;
inline TOutputPixel operator()(const TInputPixel& in) const
{
......@@ -134,13 +133,9 @@ public:
}
protected:
ChangeNoDataValueFilter()
{
}
ChangeNoDataValueFilter() = default;
~ChangeNoDataValueFilter() override
{
}
~ChangeNoDataValueFilter() override = default;
void GenerateOutputInformation() override
{
......@@ -149,7 +144,7 @@ protected:
std::vector<bool> noDataValueAvailable;
std::vector<double> noDataValues;
bool ret = ReadNoDataFlags(this->GetInput()->GetMetaDataDictionary(), noDataValueAvailable, noDataValues);
bool ret = ReadNoDataFlags(this->GetInput()->GetImageMetadata(), noDataValueAvailable, noDataValues);
if (!ret)
{
......@@ -167,7 +162,7 @@ protected:
flags = std::vector<bool>(flags.size(), true);
}
WriteNoDataFlags(flags, this->GetFunctor().m_NewValues, this->GetOutput()->GetMetaDataDictionary());
WriteNoDataFlags(flags, this->GetFunctor().m_NewValues, this->GetOutput()->GetImageMetadata());
}
private:
......
......@@ -43,9 +43,8 @@ public:
NoDataFunctor() : m_Flags(), m_Values(), m_OutsideValue(0), m_InsideValue(1), m_NaNIsNoData(false)
{
}
virtual ~NoDataFunctor()
{
}
virtual ~NoDataFunctor() = default;
inline TOutputPixel operator()(const TInputPixel& in) const
{
......@@ -123,20 +122,16 @@ public:
}
protected:
ImageToNoDataMaskFilter()
{
}
ImageToNoDataMaskFilter() = default;
~ImageToNoDataMaskFilter() override
{
}
~ImageToNoDataMaskFilter() = default;
void BeforeThreadedGenerateData() override
{
std::vector<bool> noDataValueAvailable;
std::vector<double> noDataValues;
ReadNoDataFlags(this->GetInput()->GetMetaDataDictionary(), noDataValueAvailable, noDataValues);
ReadNoDataFlags(this->GetInput()->GetImageMetadata(), noDataValueAvailable, noDataValues);
// don't pass empty containers to the functor
if (noDataValueAvailable.empty() || noDataValues.empty())
......
......@@ -44,8 +44,7 @@ int otbChangeNoDataValueFilter(int itkNotUsed(argc), char* itkNotUsed(argv)[])
// Write no-data flags to it
std::vector<bool> flags(1, true);
std::vector<double> values(1, -10.);
otb::WriteNoDataFlags(flags, values, img->GetMetaDataDictionary());
otb::WriteNoDataFlags(flags, values, img->GetImageMetadata());
// Fill half of the pixels with no-data values
itk::ImageRegionIterator<ImageType> it(img, region);
unsigned int count = 0;
......@@ -85,7 +84,7 @@ int otbChangeNoDataValueFilter(int itkNotUsed(argc), char* itkNotUsed(argv)[])
}
}
otb::ReadNoDataFlags(filter->GetOutput()->GetMetaDataDictionary(), flags, values);
otb::ReadNoDataFlags(filter->GetOutput()->GetImageMetadata(), flags, values);
if (flags.empty() || !flags[0])
{
......
......@@ -44,7 +44,7 @@ int otbImageToNoDataMaskFilter(int itkNotUsed(argc), char* itkNotUsed(argv)[])
// Write no-data flags to it
std::vector<bool> flags(1, true);
std::vector<double> values(1, -10.);
otb::WriteNoDataFlags(flags, values, img->GetMetaDataDictionary());
otb::WriteNoDataFlags(flags, values, img->GetImageMetadata());
// Fill half of the pixels with no-data values
itk::ImageRegionIterator<ImageType> it(img, region);
......
......@@ -345,7 +345,7 @@ void StreamingMosaicFilterBase<TInputImage, TOutputImage, TInternalValueType>::G
noDataValueAvailable.push_back(true);
noDataValues1.push_back(static_cast<double>(m_NoDataOutputPixel[band]));
}
otb::WriteNoDataFlags(noDataValueAvailable, noDataValues1, this->GetOutput()->GetMetaDataDictionary());
otb::WriteNoDataFlags(noDataValueAvailable, noDataValues1, this->GetOutput()->GetImageMetadata());
// Get min & max values from output pixel type
minOutputPixelValue = static_cast<InternalValueType>(itk::NumericTraits<OutputImageInternalPixelType>::NonpositiveMin());
......
......@@ -29,6 +29,7 @@
#include "itkDefaultConvertPixelTraits.h"
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
#include "otbNoDataHelper.h"
namespace otb
{
......@@ -146,9 +147,8 @@ void NeighborhoodMajorityVotingImageFilter<TInputImage, TOutputImage, TKernel>::
{
noDataValue[i] = itk::DefaultConvertPixelTraits<PixelType>::GetNthComponent(i, m_LabelForNoDataPixels);
}
itk::MetaDataDictionary& dict = outputPtr->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
itk::EncapsulateMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
WriteNoDataFlags(noDataValueAvailable, noDataValue, outputPtr->GetImageMetadata());
}
} // end namespace otb
......
......@@ -23,6 +23,7 @@
#define otbSimpleRcsPanSharpeningFusionImageFilter_hxx
#include "otbSimpleRcsPanSharpeningFusionImageFilter.h"
#include "otbNoDataHelper.h"
namespace otb
{
......@@ -116,9 +117,7 @@ void SimpleRcsPanSharpeningFusionImageFilter<TPanImageType, TXsImageType, TOutpu
bool noDataValuePanAvailable = false;
PanPixelType noDataValuePan = 0;
bool retPan =
itk::ExposeMetaData<std::vector<bool>>(this->GetPanInput()->GetMetaDataDictionary(), MetaDataKey::NoDataValueAvailable, tmpNoDataValuePanAvailable);
retPan &= itk::ExposeMetaData<std::vector<double>>(this->GetPanInput()->GetMetaDataDictionary(), MetaDataKey::NoDataValue, tmpNoDataValuePan);
bool retPan = ReadNoDataFlags(this->GetPanInput()->GetImageMetadata(), tmpNoDataValuePanAvailable, tmpNoDataValuePan);
if (retPan && tmpNoDataValuePanAvailable.size() > 0 && tmpNoDataValuePan.size() > 0)
{
......@@ -126,14 +125,12 @@ void SimpleRcsPanSharpeningFusionImageFilter<TPanImageType, TXsImageType, TOutpu
noDataValuePan = static_cast<PanPixelType>(tmpNoDataValuePan[0]);
}
// Write no-data flags for Xs image
std::vector<bool> noDataValuesXsAvailable;
std::vector<double> tmpNoDataValuesXs;
std::vector<XsPixelType> noDataValuesXs;
bool retXs = itk::ExposeMetaData<std::vector<bool>>(this->GetXsInput()->GetMetaDataDictionary(), MetaDataKey::NoDataValueAvailable, noDataValuesXsAvailable);
retXs &= itk::ExposeMetaData<std::vector<double>>(this->GetXsInput()->GetMetaDataDictionary(), MetaDataKey::NoDataValue, tmpNoDataValuesXs);
bool retXs = ReadNoDataFlags(this->GetXsInput()->GetImageMetadata(), noDataValuesXsAvailable, tmpNoDataValuesXs);
// Check if noData is needed and update noDataValuesAvailable with return function value
if (retPan || retXs)
......
......@@ -1119,12 +1119,6 @@ void GDALImageIO::InternalReadImageInformation()
ImportMetadata();
if (noDataFound)
{
itk::EncapsulateMetaData<MetaDataKey::BoolVectorType>(dict, MetaDataKey::NoDataValueAvailable, isNoDataAvailable);
itk::EncapsulateMetaData<MetaDataKey::VectorType>(dict, MetaDataKey::NoDataValue, noDataValues);
}
// Read AREA_OR_POINT value if present
papszMetadata = dataset->GetMetadata(nullptr);
auto areaOrPoint = CSLFetchNameValue(papszMetadata, "AREA_OR_POINT");
......
......@@ -28,6 +28,8 @@
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
#include "otbNoDataHelper.h"
namespace otb
{
/**
......@@ -92,9 +94,8 @@ void DSFusionOfClassifiersImageFilter<TInputImage, TOutputImage, TMaskImage>::Ge
noDataValueAvailable.push_back(true);
std::vector<double> noDataValue;
noDataValue.push_back(m_LabelForNoDataPixels);
itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
itk::EncapsulateMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
WriteNoDataFlags(noDataValueAvailable, noDataValue, this->GetOutput()->GetImageMetadata());
}
/* ************************************************************************************************************** */
......
......@@ -25,6 +25,7 @@
#include "itkImageRegionIteratorWithIndex.h"
#include "itkImageRegionIterator.h"
#include "otbNoDataHelper.h"
namespace otb
{
......@@ -179,16 +180,11 @@ void DisparityTranslateFilter<TDisparityImage, TGridImage, TSensorImage, TMaskIm
vertiOut->CopyInformation(leftIn);
// Set the NoData value
std::vector<bool> noDataValueAvailable;
noDataValueAvailable.push_back(true);
std::vector<double> noDataValue;
noDataValue.push_back(m_NoDataValue);
itk::MetaDataDictionary& dict = horizOut->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
itk::EncapsulateMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
dict = vertiOut->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
itk::EncapsulateMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
std::vector<bool> noDataValueAvailable = {true};
std::vector<double> noDataValue = {m_NoDataValue};
WriteNoDataFlags(noDataValueAvailable, noDataValue, horizOut->GetImageMetadata());
WriteNoDataFlags(noDataValueAvailable, noDataValue, vertiOut->GetImageMetadata());
}
template <class TDisparityImage, class TGridImage, class TSensorImage, class TMaskImage>
......
......@@ -25,6 +25,7 @@
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkImageRegionIterator.h"
#include "otbStreamingStatisticsVectorImageFilter.h"
#include "otbNoDataHelper.h"
namespace otb
{
......@@ -329,9 +330,8 @@ void Multi3DMapToDEMFilter<T3DImage, TMaskImage, TOutputDEMImage>::GenerateOutpu
noDataValueAvailable.push_back(true);
std::vector<double> noDataValue;
noDataValue.push_back(m_NoDataValue);
itk::MetaDataDictionary& dict = outputPtr->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
itk::EncapsulateMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
WriteNoDataFlags(noDataValueAvailable, noDataValue, outputPtr->GetImageMetadata());
}
template <class T3DImage, class TMaskImage, class TOutputDEMImage>
......
......@@ -28,6 +28,7 @@
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
#include "otbImage.h"
#include "otbNoDataHelper.h"
#include "gdal_alg.h"
#include "stdint.h" //needed for uintptr_t
......@@ -152,9 +153,7 @@ void OGRDataSourceToLabelImageFilter<TOutputImage>::GenerateOutputInformation()
std::vector<double> noDataValue;
noDataValue.resize(nbBands, static_cast<double>(m_BackgroundValue));
itk::MetaDataDictionary& dict = outputPtr->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::vector<bool>>(dict, MetaDataKey::NoDataValueAvailable, noDataValueAvailable);
itk::EncapsulateMetaData<std::vector<double>>(dict, MetaDataKey::NoDataValue, noDataValue);
WriteNoDataFlags(noDataValueAvailable, noDataValue, outputPtr->GetImageMetadata());
}
template <class TOutputImage>
......
......@@ -274,7 +274,7 @@ void VectorImageModel::virtual_BuildModel(void* context)
std::vector<double> values;
std::vector<bool> flags;
bool ret = otb::ReadNoDataFlags(this->ToImageBase()->GetMetaDataDictionary(), flags, values);
bool ret = otb::ReadNoDataFlags(this->GetImageMetadata(), flags, values);
if (ret && !values.empty() && !flags.empty() && flags[0])
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment