Commit d395d481 authored by Julien Osman's avatar Julien Osman
Browse files

BUG: Correct the tests for SarIMI

parent 1973b2db
Pipeline #7453 failed with stages
in 123 minutes and 23 seconds
mytime : 2009-08-10T10:30:08.142149Z
First try size: 464
Second try size: 240
Third try size: 240
First try size: 496
Second try size: 256
Third try size: 256
......@@ -55,6 +55,8 @@ public:
/** Create the appropriate SarImageMetadataInterfaceFactory depending on the particulars of the file. */
static SarImageMetadataInterfacePointerType CreateIMI(const MetaDataDictionaryType& dict);
/** Create the appropriate IMI based on a MetadataSupplier */
static SarImageMetadataInterfacePointerType CreateIMI(ImageMetadata & imd, const MetadataSupplierInterface & mds);
/** Register Built-in factories */
static void RegisterBuiltInFactories();
......
......@@ -340,9 +340,9 @@ void Radarsat2ImageMetadataInterface::ParseGeom(ImageMetadata & imd)
imd.Add(MDStr::ProductType, ProductMS.GetAs<std::string>("product.imageGenerationParameters.generalProcessingInformation.productType"));
auto polarizations = ProductMS.GetAsVector<std::string>("product.sourceAttributes.radarParameters.polarizations");
assert(polarizations.size() == imd.Bands.size());
// TODO assert(polarizations.size() == imd.Bands.size());
SARParam sarParam;
for (int bandId = 0 ; bandId < polarizations.size() ; ++bandId)
for (int bandId = 0 ; bandId < imd.Bands.size() ; ++bandId)
{
imd.Bands[bandId].Add(MDStr::Polarization, polarizations[bandId]);
imd.Bands[bandId].Add(MDGeom::SAR, sarParam);
......
......@@ -64,6 +64,42 @@ SarImageMetadataInterfaceFactory::SarImageMetadataInterfacePointerType SarImageM
return dynamic_cast<SarImageMetadataInterface*>(static_cast<SarDefaultImageMetadataInterface*>(defaultIMI));
}
SarImageMetadataInterfaceFactory::SarImageMetadataInterfacePointerType
SarImageMetadataInterfaceFactory
::CreateIMI(ImageMetadata & imd, const MetadataSupplierInterface & mds)
{
RegisterBuiltInFactories();
auto allObjects = itk::ObjectFactoryBase::CreateAllInstance("SarImageMetadataInterface");
for (auto i = allObjects.begin(); i != allObjects.end(); ++i)
{
SarImageMetadataInterface* io = dynamic_cast<SarImageMetadataInterface*>(i->GetPointer());
if (io)
{
// the static part of ImageMetadata is already filled
io->SetMetadataSupplierInterface(mds);
try
{
io->Parse(imd);
return io;
}
catch(MissingMetadataException& e)
{
// silent catch of MissingMetadataException
// just means that this IMI can't parse the file
}
}
else
{
itkGenericExceptionMacro(<< "Error SarImageMetadataInterface factory did not return an SarImageMetadataInterface: " << (*i)->GetNameOfClass());
}
}
SarDefaultImageMetadataInterface::Pointer defaultIMI = SarDefaultImageMetadataInterface::New();
return dynamic_cast<SarImageMetadataInterface*>(static_cast<SarDefaultImageMetadataInterface*>(defaultIMI));
}
void SarImageMetadataInterfaceFactory::RegisterBuiltInFactories()
{
static bool firstTime = true;
......
......@@ -23,30 +23,65 @@
#include "itkMacro.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbExtendedFilenameToReaderOptions.h"
#include "otbSarImageMetadataInterfaceFactory.h"
#include "otbGeomMetadataSupplier.h"
#include "otbSARMetadata.h"
int otbSarCalibrationLookupDataTest(int argc, char* argv[])
using RealType = double;
using ImageMetadataInterfaceType = otb::SarImageMetadataInterface;
using ImageMetadataInterfaceFactoryType = otb::SarImageMetadataInterfaceFactory;
using LookupDataType = otb::SarCalibrationLookupData;
using InputImageType = otb::Image<double, 2>;
using ImageReaderType = otb::ImageFileReader<InputImageType>;
using MetadataSupplierInterfaceType = otb::MetadataSupplierInterface;
using ImageMetadataType = otb::ImageMetadata;
std::unique_ptr<MetadataSupplierInterfaceType> GetIMI(const char* TheFileName)
{
typedef double RealType;
typedef otb::SarImageMetadataInterface ImageMetadataInterfaceType;
typedef otb::SarCalibrationLookupData LookupDataType;
typedef otb::Image<double, 2> InputImageType;
typedef otb::ImageFileReader<InputImageType> ImageReaderType;
otb::ExtendedFilenameToReaderOptions::Pointer FilenameHelper = otb::ExtendedFilenameToReaderOptions::New();
FilenameHelper->SetExtendedFileName(TheFileName);
std::string DerivatedFileName = ImageReaderType::GetDerivedDatasetSourceFileName(TheFileName);
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 (!FilenameHelper->GetSkipGeom() && FilenameHelper->ExtGEOMFileNameIsSet())
{
return std::make_unique<otb::GeomMetadataSupplier>(FilenameHelper->GetExtGEOMFileName());
}
// Case 2: attached geom (if present)
else if (!FilenameHelper->GetSkipGeom() && itksys::SystemTools::FileExists(attachedGeom))
{
return std::make_unique<otb::GeomMetadataSupplier>(attachedGeom);
}
// Case 3: tags in file
else
{
auto supplierPointer = dynamic_cast<MetadataSupplierInterfaceType*>(
otb::ImageIOFactory::CreateImageIO(TheFileName, otb::ImageIOFactory::ReadMode).GetPointer());
return std::unique_ptr<MetadataSupplierInterfaceType>(supplierPointer);
}
}
int otbSarCalibrationLookupDataTest(int argc, char* argv[])
{
if (argc < 3)
{
std::cerr << "Usage: otbSarCalibationLookupDataTest /path/to/input/file /path/to/output/file !" << std::endl;
return EXIT_FAILURE;
}
ImageReaderType::Pointer reader = ImageReaderType::New();
reader->SetFileName(argv[1]);
const char* inFileName = argv[1];
reader->SetFileName(inFileName);
reader->UpdateOutputInformation();
auto imd = reader->GetOutput()->GetImageMetadata();
const char* outFileName = argv[2];
std::ofstream outfile;
outfile.open(outFileName);
ImageMetadataInterfaceType::Pointer imageMetadataInterface = otb::SarImageMetadataInterfaceFactory::CreateIMI(reader->GetOutput()->GetMetaDataDictionary());
auto supplier = GetIMI(inFileName);
ImageMetadataInterfaceType::Pointer imageMetadataInterface = ImageMetadataInterfaceFactoryType::CreateIMI(imd, *supplier);
if (!imageMetadataInterface.IsNotNull())
{
......@@ -54,22 +89,7 @@ int otbSarCalibrationLookupDataTest(int argc, char* argv[])
return EXIT_FAILURE;
}
const std::string sensorId = imageMetadataInterface->GetSensorID();
outfile << sensorId << std::endl;
LookupDataType::Pointer lookupDataObj; //TODO = imageMetadataInterface->GetCalibrationLookupData(0);
if (!lookupDataObj.IsNotNull())
{
std::cerr << "lookupDataObj is Null" << std::endl;
return EXIT_FAILURE;
}
RealType lutVal = static_cast<RealType>(lookupDataObj->GetValue(10, 19));
//outfile << imageMetadataInterface->HasCalibrationLookupDataFlag() << std::endl; TODO
outfile << lutVal << std::endl;
outfile << imd[otb::MDStr::Instrument] << std::endl;
return EXIT_SUCCESS;
}
......@@ -130,6 +130,9 @@ public:
* Returns: overview info, empty if none.*/
std::vector<std::string> GetOverviewsInfo();
// Retrieve the real source file name if derived dataset */
static std::string GetDerivedDatasetSourceFileName(const std::string& filename);
protected:
ImageFileReader();
~ImageFileReader() override;
......@@ -149,9 +152,6 @@ private:
*/
bool GetGdalReadImageFileName(const std::string& filename, std::string& GdalFileName);
// Retrieve the real source file name if derived dataset */
std::string GetDerivedDatasetSourceFileName(const std::string& filename) const;
ImageFileReader(const Self&) = delete;
void operator=(const Self&) = delete;
......
......@@ -584,15 +584,15 @@ void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformatio
}
template <class TOutputImage, class ConvertPixelTraits>
std::string ImageFileReader<TOutputImage, ConvertPixelTraits>::GetDerivedDatasetSourceFileName(const std::string& filename) const
std::string ImageFileReader<TOutputImage, ConvertPixelTraits>::GetDerivedDatasetSourceFileName(const std::string& filename)
{
const size_t dsds_pos = filename.find(DerivedSubdatasetPrefix);
const size_t dsds_pos = filename.find(otb::DerivedSubdatasetPrefix);
if (dsds_pos != std::string::npos)
{
// Derived subdataset from gdal
const size_t alg_pos = filename.find(":", dsds_pos + DerivedSubdatasetPrefixLength);
const size_t alg_pos = filename.find(":", dsds_pos + otb::DerivedSubdatasetPrefixLength);
if (alg_pos != std::string::npos)
{
std::string sourceFilename = filename.substr(alg_pos + 1, filename.size() - alg_pos);
......
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