Commit 6b3d55f7 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: setup base classes for image metadata

parent 32b26f4c
Pipeline #3440 failed with stage
in 8 minutes and 29 seconds
/*
* 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 otbBandMetadata_h
#define otbBandMetadata_h
#include <string>
#include <vector>
#include "OTBMetadataExport.h"
#include "otbMetaDataKey.h"
namespace otb
{
/** \class BandMetadata
*
* \brief Generic structure containing channel specific metadatas
*
* \ingroup OTBMetadata
*/
struct OTBMetadata_EXPORT BandMetadata
{
// ----------- static part -------------------------
std::string Name;
std::string EnhancedName;
bool NoDataFlag = false;
double NoDataValue = 0.0;
// --------- dynamic part ----------------------------
std::map<MetaData::NumericKeyType, double> NumericKeys;
std::map<MetaData::StringKeyType, std::string> StringKeys;
std::map<MetaData::LUT1DKeyType, MetaData::LUT1D > LUT1DKeys;
std::map<MetaData::LUT2DKeyType, MetaData::LUT2D > LUT2DKeys;
};
} // 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;
}
#endif
/*
* 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 otbImageMetadata_h
#define otbImageMetadata_h
#include "otbBandMetadata.h"
//#include "otbGeometryMetadata.h"
#include "otbMetaDataKey.h"
#include "OTBMetadataExport.h"
#include <boost/any.hpp>
#include <vector>
#include <string>
#include <ctime>
namespace otb
{
/** \class ImageMetadata
*
* \brief Generic class containing image metadatas used in OTB
*
* \ingroup OTBMetadata
*/
struct OTBMetadata_EXPORT ImageMetadata
{
// ------------------------------ static part ----------------------------------
std::string ProjectionRef;
std::string GCPProjection;
std::vector<OTB_GCP> GCPs;
double GeoTransform[6] = {0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
std::string SensorID;
double PixelSizeX = 0.0;
double PixelSizeY = 0.0;
/** Acquisition date */
struct tm AcquisitionDate;
/** Production date */
struct tm ProductionDate;
/** Corners coordinate */
double ULX = 0.0;
double ULY = 0.0;
double URX = 0.0;
double URY = 0.0;
double LLX = 0.0;
double LLY = 0.0;
double LRX = 0.0;
double LRY = 0.0;
/** Band-specific metadatas */
std::vector<BandMetadata> Bands;
/** Sensor model geometry */
boost::any SensorGeometry;
// ------------------------------ dynamic part ---------------------------------
std::map<MetaData::NumericKeyType, double> NumericKeys;
std::map<MetaData::StringKeyType, std::string> StringKeys;
std::map<MetaData::LUT1DKeyType, MetaData::LUT1D > LUT1DKeys;
std::map<MetaData::LUT2DKeyType, MetaData::LUT2D > LUT2DKeys;
};
} // 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;
}
#endif
......@@ -27,6 +27,7 @@
#include "itkMetaDataDictionary.h"
#include "otbMetaDataKey.h"
#include "itkImageBase.h"
#include "otbImageMetadata.h"
#include "OTBMetadataExport.h"
......@@ -79,6 +80,16 @@ public:
return m_MetaDataDictionary;
}
void SetImageMetadata(const ImageMetadata& imd)
{
m_ImageMetadata = imd;
}
const ImageMetadata& GetImageMetadata() const
{
return m_ImageMetadata;
}
/** Get the projection coordinate system of the image. */
std::string GetProjectionRef() const;
......@@ -209,6 +220,9 @@ public:
virtual bool CanRead() const = 0;
// TODO : find the correct interface ...
virtual bool Parse() const = 0;
static void PrintMetadata(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType& dict);
protected:
......@@ -221,6 +235,8 @@ protected:
MetaDataDictionaryType m_MetaDataDictionary;
ImageMetadata m_ImageMetadata;
private:
ImageMetadataInterfaceBase(const Self&) = delete;
void operator=(const Self&) = delete;
......
......@@ -155,6 +155,92 @@ public:
void Print(std::ostream& os) const;
};
namespace MetaData
{
enum class NumericKeyType
{
// optical section
PhysicalGain,
PhysicalBias,
SolarIrradiance,
SunElevation,
SunAzimuth,
SatElevation,
SatAzimuth,
FirstWavelength,
LastWavelength,
SpectralStep,
SpectralMin,
SpectralMax,
// SAR section
CalScale,
PRF,
RSF,
RadarFrequency,
CenterIndicenceAngle,
RescalingFactor,
AntennaPatternNewGainPolyDegX,
AntennaPatternNewGainPolyDegY,
AntennaPatternOldGainPolyDegX,
AntennaPatternOldGainPolyDegY,
IncidenceAnglePolyDegX,
IncidenceAnglePolyDegY,
RangeSpreadLossPolyDegX,
RangeSpreadLossPolyDegY,
NoisePolyDegX,
NoisePolyDegY
};
enum class StringKeyType
{
Instrument,
ProductType,
Polarization
// ...
};
enum class LUT1DKeyType
{
SpectralSensitivity
};
enum class LUT2DKeyType
{
// Sar calibration lut ...
};
struct Time : tm
{
double frac_sec;
};
struct LUTAxis
{
/** number of measurements on this axis */
int Size;
/** start value on the axis */
double Origin;
/** spacing between measurements (if regular sampling) */
double Spacing;
/** list of measurements (if irregular sampling) */
std::vector<double> Values;
};
template <unsigned int VDim> class LUT
{
public:
LUTAxis Axes[VDim];
std::vector<double> Array;
};
typedef LUT<1> LUT1D;
typedef LUT<2> LUT2D;
} // end namespace MetaData
} // end namespace otb
#endif
......@@ -31,6 +31,7 @@ otbDefaultImageMetadataInterface.cxx
otbImageMetadataInterfaceTest2.cxx
otbNoDataHelperTest.cxx
otbSarCalibrationLookupDataTest.cxx
otbImageMetadataTest.cxx
)
add_executable(otbMetadataTestDriver ${OTBMetadataTests})
......@@ -356,3 +357,6 @@ otb_add_test(NAME ioTvSarCalibrationLookupDataTest_RADARSAT2 COMMAND otbMetadata
${INPUTDATA}/RADARSAT2_ALTONA_300_300_VV.tif?&geom=${INPUTDATA}/RADARSAT2_ALTONA_300_300_VV.geom
${TEMP}/ioTvSarCalibrationLookupDataTest_RADARSAT2.txt
)
otb_add_test(NAME coreImageMetadataTest
COMMAND otbMetadataTestDriver otbImageMetadataTest)
/*
* 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.
*/
#include "otbImageMetadata.h"
#include <iostream>
int otbImageMetadataTest(int, char*[])
{
using namespace otb;
ImageMetadata md;
md.SensorID = "PHR";
md.ProjectionRef = "UTM projRef";
BandMetadata bmd;
bmd.Name = "B3";
bmd.NumericKeys[MetaData::NumericKeyType::PhysicalGain] = 2.0;
bmd.NumericKeys[MetaData::NumericKeyType::PhysicalBias] = 1.0;
md.Bands.push_back(bmd);
bmd.Name = "B2";
bmd.NumericKeys[MetaData::NumericKeyType::PhysicalGain] = 3.0;
bmd.NumericKeys[MetaData::NumericKeyType::PhysicalBias] = 2.0;
md.Bands.push_back(bmd);
bmd.Name = "B1";
bmd.NoDataFlag = true;
bmd.NoDataValue = -10000.0;
bmd.NumericKeys[MetaData::NumericKeyType::PhysicalGain] = 4.0;
bmd.NumericKeys[MetaData::NumericKeyType::PhysicalBias] = 3.0;
md.Bands.push_back(bmd);
ImageMetadata md2;
md2 = md;
md.ProjectionRef = "Lambert projRef";
std::cout << "md2: "<< md2 << "\n";
return 0;
}
......@@ -31,4 +31,5 @@ void RegisterTests()
REGISTER_TEST(otbImageMetadataInterfaceTest2);
REGISTER_TEST(otbNoDataHelperTest);
REGISTER_TEST(otbSarCalibrationLookupDataTest);
REGISTER_TEST(otbImageMetadataTest);
}
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