Skip to content
Snippets Groups Projects
Commit b6ec5032 authored by Julien Osman's avatar Julien Osman
Browse files

REFAC: Implemented the LUT conversion for ImageMetadataBase::ToKeywordlist

parent 3b68272a
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@ md3_append: {{"Extra.Comment": "Test Extrakeys",
"ProjectionEPSG": "4326",
"ProjectionWKT": "UTM projRef",
"ProjectionProj": "+proj=longlat +datum=WGS84 +no_defs ",
"SpectralSensitivity": "{"Axes": [{"Size": "3", "Origin": "0", "Spacing": "1", "Values": []}, ], "Array": [1, 2, 3, ]}",
"RPC": "{"LineOffset": "0", "SampleOffset": "0", "LatOffset": "0", "LonOffset": "0", "HeightOffset": "0", "LineScale": "0", "SampleScale": "0", "LatScale": "0", "LonScale": "0", "HeightScale": "0", "LineNum": [ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", ], "LineDen": [ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", ], "SampleNum": [ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", ], "SampleDen": [ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", ], }",
"ProductionDate": "2009-08-10T10:30:08.142149Z",
"GCP": "{"Projection": "", [{"GCP_Id": "", "GCP_Info": "", "GCP_Row": "0", "GCP_Col": "0", "GCP_X": "0", "GCP_Y": "0", "GCP_Z": "0", }, ]}",
......
......@@ -233,6 +233,8 @@ struct LUTAxis
double Spacing;
/** list of measurements (if irregular sampling) */
std::vector<double> Values;
/** Export to JSON */
std::string ToJSON(bool multiline=false) const;
};
template <unsigned int VDim> class LUT
......@@ -241,6 +243,8 @@ public:
LUTAxis Axes[VDim];
std::vector<double> Array;
std::string ToJSON(bool multiline=false) const;
};
typedef LUT<1> LUT1D;
......
......@@ -253,9 +253,15 @@ void ImageMetadataBase::ToKeywordlist(Keywordlist& kwl) const
kwl.emplace(MetaData::MDNumNames[kv.first], oss.str());
}
// Converting the LUT1DKeys
// TODO : LUT1D
for (const auto& kv : LUT1DKeys)
{
kwl.emplace(MetaData::MDL1DNames[kv.first], kv.second.ToJSON());
}
// Convereting the LUT2DKeys
// TODO : LUT2D
for (const auto& kv : LUT2DKeys)
{
kwl.emplace(MetaData::MDL2DNames[kv.first], kv.second.ToJSON());
}
// Converting the TimeKeys
for (const auto& kv : TimeKeys)
{
......
......@@ -187,6 +187,49 @@ std::istream& operator>>(std::istream& is, Time& val)
#undef _OTB_ISTREAM_EXPECT
std::string LUTAxis::ToJSON(bool multiline) const
{
std::ostringstream oss;
std::string sep;
if (multiline)
{
sep = "\n";
}
oss << "{"
<< "\"Size\": \"" << Size << "\", " << sep
<< "\"Origin\": \"" << Origin << "\", " << sep
<< "\"Spacing\": \"" << Spacing << "\", " << sep
<< "\"Values\": [";
for (const auto& value : Values)
oss << value << ", ";
oss << "]}";
return oss.str();
}
template <unsigned int VDim>
std::string LUT<VDim>::ToJSON(bool multiline) const
{
std::ostringstream oss;
std::string sep;
if (multiline)
{
sep = "\n";
}
oss << "{"
<< "\"Axes\": [";
for (unsigned int loop = 0 ; loop < VDim ; loop++)
oss << Axes[loop].ToJSON(multiline) << ", ";
oss << "], " << sep
<< "\"Array\": [";
for (const auto& value : Array)
oss << value << ", ";
oss << "]}";
return oss.str();
}
template class LUT<1>;
template class LUT<2>;
// array<pair<> >
// boost::flat_map<>
std::map<MDNum, std::string> MDNumNames = {
......
......@@ -198,6 +198,13 @@ int otbImageMetadataTest(int argc, char* argv[])
Projection::GCPParam gcpStruct;
gcpStruct.GCPs.push_back(OTB_GCP());
md4.Add(MDGeom::GCP, gcpStruct);
MetaData::LUT1D lut1d;
lut1d.Axes[0].Size = 3;
lut1d.Axes[0].Origin = 0;
lut1d.Axes[0].Spacing = 1;
std::vector<double>array({1.0, 2.0, 3.0});
lut1d.Array = array;
md4.Add(MDL1D::SpectralSensitivity, lut1d);
bmd.Add(MDStr::BandName, "B4");
md4.Bands.push_back(bmd);
md3.append(md4);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment