Commit 4875efa9 authored by Julien Osman's avatar Julien Osman

FIX: Simplify IMI initialization

parent e875eebb
Pipeline #6066 passed with stages
in 152 minutes and 1 second
......@@ -678,8 +678,7 @@ void GDALImageIO::InternalReadImageInformation()
itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
// Initialize the ImageMetadata structure
ImageMetadata imd;
m_Imd = imd;
m_Imd = ImageMetadata();
// Report the typical block size if possible
if (dataset->GetRasterCount() > 0)
......@@ -1811,7 +1810,7 @@ int GDALImageIO::GetNbBands() const
return m_Dataset->GetDataSet()->GetRasterCount();
}
std::string GDALImageIO::GetResourceFile(std::string str) const
std::string GDALImageIO::GetResourceFile(std::string const& str) const
{
if (str.empty())
return m_FileName;
......@@ -1833,7 +1832,7 @@ std::vector<std::string> GDALImageIO::GetResourceFiles() const
return result;
}
std::string GDALImageIO::GetMetadataValue(const std::string path, bool& hasValue, int band) const
std::string GDALImageIO::GetMetadataValue(std::string const& path, bool& hasValue, int band) const
{
// detect namespace if any
std::string domain("");
......
......@@ -38,6 +38,7 @@
#include "otbImageKeywordlist.h"
#include "otbExtendedFilenameToReaderOptions.h"
#include "otbImageFileReaderException.h"
#include "otbMetadataSupplierInterface.h"
#include <string>
namespace otb
......@@ -151,6 +152,8 @@ private:
// Retrieve the real source file name if derived dataset */
std::string GetDerivedDatasetSourceFileName(const std::string& filename) const;
void UpdateImdWithImiAndMds(ImageMetadata& imd, MetadataSupplierInterface* mds);
ImageFileReader(const Self&) = delete;
void operator=(const Self&) = delete;
......
......@@ -478,37 +478,28 @@ void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformatio
}
// NEW METADATA FRAMEWORK
// This unique_ptr is used to keep the reference to the GeomMetadataSupplier (if any)
std::unique_ptr<MetadataSupplierInterface> unique_ptr_mds;
// This pointer is used to receive the selected supplier
MetadataSupplierInterface* mds;
std::string DerivatedFileName = GetDerivedDatasetSourceFileName(m_FileName);
std::string extension = itksys::SystemTools::GetFilenameLastExtension(DerivatedFileName);
std::string attachedGeom = DerivatedFileName.substr(0, DerivatedFileName.size() - extension.size()) + std::string(".geom");
// Case 1: external geom supplied through extended filename
if (!m_FilenameHelper->GetSkipGeom() && m_FilenameHelper->ExtGEOMFileNameIsSet())
{
unique_ptr_mds = std::make_unique<GeomMetadataSupplier>(m_FilenameHelper->GetExtGEOMFileName());
mds = unique_ptr_mds.get();
GeomMetadataSupplier geomSupplier(m_FilenameHelper->GetExtGEOMFileName());
UpdateImdWithImiAndMds(imd, &geomSupplier);
}
// Case 2: attached geom (if present)
else if (!m_FilenameHelper->GetSkipGeom() && itksys::SystemTools::FileExists(attachedGeom))
{
unique_ptr_mds = std::make_unique<GeomMetadataSupplier>(attachedGeom);
mds = unique_ptr_mds.get();
GeomMetadataSupplier geomSupplier(m_FilenameHelper->GetExtGEOMFileName());
UpdateImdWithImiAndMds(imd, &geomSupplier);
}
// Case 3: tags in file
else
mds = dynamic_cast<MetadataSupplierInterface*>(m_ImageIO.GetPointer());
if (mds)
{
ImageMetadataInterfaceBase::Pointer imi = ImageMetadataInterfaceFactory::CreateIMI(imd, mds);
// update 'imd' with the parsed metadata
imd = imi->GetImageMetadata();
auto gdalSupplierPointer = dynamic_cast<MetadataSupplierInterface*>(m_ImageIO.GetPointer());
UpdateImdWithImiAndMds(imd, gdalSupplierPointer);
}
// If Skip ProjectionRef is activated, remove ProjRef from dict
if (m_FilenameHelper->GetSkipCarto())
{
......@@ -587,6 +578,17 @@ void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformatio
output->SetLargestPossibleRegion(region);
}
template <class TOutputImage, class ConvertPixelTraits>
void ImageFileReader<TOutputImage, ConvertPixelTraits>::UpdateImdWithImiAndMds(ImageMetadata& imd, MetadataSupplierInterface* mds)
{
if(mds)
{
ImageMetadataInterfaceBase::Pointer imi = ImageMetadataInterfaceFactory::CreateIMI(imd, mds);
// update 'imd' with the parsed metadata
imd = imi->GetImageMetadata();
}
}
template <class TOutputImage, class ConvertPixelTraits>
std::string ImageFileReader<TOutputImage, ConvertPixelTraits>::GetDerivedDatasetSourceFileName(const std::string& filename) const
{
......
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