Commit 995e2e16 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: setup base classes for new metadata parsing

parent 6b3d55f7
Pipeline #3459 passed with stages
in 20 minutes and 35 seconds
This diff is collapsed.
......@@ -59,14 +59,6 @@ struct OTBMetadata_EXPORT BandMetadata
} // end namespace otb
std::ostream& operator<<(std::ostream& os, const otb::BandMetadata& bmd)
{
os << "[Name:"<< bmd.Name
<< ";NoDataFlag:"<<bmd.NoDataFlag
<< ";NoDataValue:"<<bmd.NoDataValue
<< "]";
// TODO: finish printing other fields
return os;
}
extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::BandMetadata& bmd);
#endif
......@@ -93,33 +93,6 @@ struct OTBMetadata_EXPORT ImageMetadata
} // end namespace otb
std::ostream& operator<<(std::ostream& os, const otb::ImageMetadata& imd)
{
os << "ImageMetadata [";
os << "SensorID:'" << imd.SensorID << "';";
os << "ProjectionRef:'"<<imd.ProjectionRef<<"';";
os << "GCPProjection:'"<<imd.GCPProjection<<"';";
os << "GCPs[";
for (auto &gcp : imd.GCPs)
{
gcp.Print(os);
}
os << "];";
os << "GeoTransform: ["
<< imd.GeoTransform[0] << ","
<< imd.GeoTransform[1] << ","
<< imd.GeoTransform[2] << ","
<< imd.GeoTransform[3] << ","
<< imd.GeoTransform[4] << ","
<< imd.GeoTransform[5] << "]";
os << "Bands[";
for (auto &band : imd.Bands)
{
os << band << ",";
}
os << "]";
// TODO : finish printing other fields
return os;
}
extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadata& imd);
#endif
......@@ -28,6 +28,7 @@
#include "otbMetaDataKey.h"
#include "itkImageBase.h"
#include "otbImageMetadata.h"
#include "otbMetadataSupplierInterface.h"
#include "OTBMetadataExport.h"
......@@ -220,8 +221,10 @@ public:
virtual bool CanRead() const = 0;
// TODO : find the correct interface ...
virtual bool Parse() const = 0;
virtual bool Parse(const MetadataSupplierInterface *) const
{
return false;
}
static void PrintMetadata(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType& dict);
......
......@@ -23,6 +23,7 @@
#include "itkObject.h"
#include "otbImageMetadataInterfaceBase.h"
#include "otbMetadataSupplierInterface.h"
namespace otb
{
......@@ -56,6 +57,9 @@ public:
/** Create the appropriate ImageMetadataInterfaceFactory depending on the particulars of the file. */
static ImageMetadataInterfaceBasePointerType CreateIMI(const MetaDataDictionaryType& dict);
/** Create the appropriate IMI based on a MetadataSupplier */
static ImageMetadataInterfaceBasePointerType CreateIMI(const MetadataSupplierInterface *mds);
/** Register Built-in factories */
static void RegisterBuiltInFactories();
......
/*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbMetadataSupplierInterface_h
#define otbMetadataSupplierInterface_h
#include "OTBMetadataExport.h"
#include <vector>
#include <string>
#include "otbStringUtilities.h"
namespace otb
{
/** \class MetadataSupplierInterface
*
* \brief Base class to access metadata information in files/images
*
* \ingroup OTBMetadata
*/
class OTBMetadata_EXPORT MetadataSupplierInterface
{
public:
virtual std::vector<std::string> GetResourceFiles() = 0;
virtual bool HasValue(const char * path) = 0;
virtual otb::string_view GetValue(const char * path) = 0;
// probably not needed
//~ virtual std::vector<std::string> GetValuesList(const std::string& path) = 0;
// TODO: use string_view instead ?
};
} // end namespace otb
#endif
......@@ -68,6 +68,9 @@ set(OTBMetadata_SRC
otbNoDataHelper.cxx
otbFilterFunctionValues.cxx
otbMetaDataKey.cxx
otbImageMetadata.cxx
otbBandMetadata.cxx
)
add_library(OTBMetadata ${OTBMetadata_SRC})
......
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbBandMetadata.h"
std::ostream& operator<<(std::ostream& os, const otb::BandMetadata& bmd)
{
os << "[Name:"<< bmd.Name
<< ";NoDataFlag:"<<bmd.NoDataFlag
<< ";NoDataValue:"<<bmd.NoDataValue
<< "]";
// TODO: finish printing other fields
return os;
}
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbImageMetadata.h"
std::ostream& operator<<(std::ostream& os, const otb::ImageMetadata& imd)
{
os << "ImageMetadata [";
os << "SensorID:'" << imd.SensorID << "';";
os << "ProjectionRef:'"<<imd.ProjectionRef<<"';";
os << "GCPProjection:'"<<imd.GCPProjection<<"';";
os << "GCPs[";
for (auto &gcp : imd.GCPs)
{
gcp.Print(os);
}
os << "];";
os << "GeoTransform: ["
<< imd.GeoTransform[0] << ","
<< imd.GeoTransform[1] << ","
<< imd.GeoTransform[2] << ","
<< imd.GeoTransform[3] << ","
<< imd.GeoTransform[4] << ","
<< imd.GeoTransform[5] << "]";
os << "Bands[";
for (auto &band : imd.Bands)
{
os << band << ",";
}
os << "]";
// TODO : finish printing other fields
return os;
}
......@@ -87,6 +87,40 @@ ImageMetadataInterfaceFactory::ImageMetadataInterfaceBasePointerType ImageMetada
return dynamic_cast<ImageMetadataInterfaceBase*>(static_cast<DefaultImageMetadataInterface*>(defaultIMI));
}
ImageMetadataInterfaceFactory::ImageMetadataInterfaceBasePointerType
ImageMetadataInterfaceFactory
::CreateIMI(const MetadataSupplierInterface *mds)
{
RegisterBuiltInFactories();
std::list<itk::LightObject::Pointer> allOpticalObjects = itk::ObjectFactoryBase::CreateAllInstance("OpticalImageMetadataInterface");
std::list<itk::LightObject::Pointer> allSarObjects = itk::ObjectFactoryBase::CreateAllInstance("SarImageMetadataInterface");
std::list<itk::LightObject::Pointer> allObjects;
std::copy(allOpticalObjects.begin(), allOpticalObjects.end(), std::back_inserter(allObjects));
std::copy(allSarObjects.begin(), allSarObjects.end(), std::back_inserter(allObjects));
for (std::list<itk::LightObject::Pointer>::iterator i = allObjects.begin(); i != allObjects.end(); ++i)
{
ImageMetadataInterfaceBase* io = dynamic_cast<ImageMetadataInterfaceBase*>(i->GetPointer());
if (io)
{
if (io->Parse(mds))
{
return io;
}
}
else
{
itkGenericExceptionMacro(<< "Error ImageMetadataInterface factory did not return an ImageMetadataInterfaceBase: " << (*i)->GetNameOfClass());
}
}
DefaultImageMetadataInterface::Pointer defaultIMI = DefaultImageMetadataInterface::New();
//~ defaultIMI->SetMetaDataDictionary(dict);
return dynamic_cast<ImageMetadataInterfaceBase*>(static_cast<DefaultImageMetadataInterface*>(defaultIMI));
}
void ImageMetadataInterfaceFactory::RegisterBuiltInFactories()
{
static bool firstTime = true;
......
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