Commit 7c6de401 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

Merge branch '2237-add_GetSize_to_ImageMetadata' into 'develop'

Implement a GetSize() function for the ImageMetadata class

Closes #2237

See merge request !872
parents 1e2292d8 c3b8d6c4
Pipeline #9280 passed with stage
in 22 minutes and 48 seconds
SensorID PHR
ProductionDate 2009-08-10T10:30:08.142149Z
ProjectionWKT UTM projRef
Comment Test Extrakeys
BandName B0
NoData -10000
PhysicalGain 2
PhysicalBias 1
BandName B1
NoData -10000
PhysicalGain 3
PhysicalBias 2
BandName B2
NoData -10000
PhysicalGain 4
PhysicalBias 3
size band 1: 4
size all: 16
\ No newline at end of file
......@@ -240,6 +240,9 @@ public:
* If no information is available the default order (0,1,2) is returned instead */
std::vector<unsigned int> GetDefaultDisplay() const;
/** Return the number of elements in the ImageMetadataBase */
int GetSize() const;
};
......@@ -325,6 +328,9 @@ public:
/** Return a vector containing the name of each band of the ImageMetadata or an empty
* vector if at least one band name is missing */
std::vector<std::string> GetEnhancedBandNames() const;
/** Return the number of elements in the ImageMetadata */
int GetSize() const;
};
extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadataBase& imd);
......
......@@ -489,6 +489,12 @@ std::vector<unsigned int> ImageMetadataBase::GetDefaultDisplay() const
return {redChannel, greenChannel, blueChannel};
}
int ImageMetadataBase::GetSize() const
{
return GeometryKeys.size() + NumericKeys.size() + StringKeys.size() + LUT1DKeys.size()
+ LUT2DKeys.size() + TimeKeys.size() + ExtraKeys.size();
}
// ----------------------- [ImageMetadata] ------------------------------
......@@ -746,7 +752,13 @@ std::vector<std::string> ImageMetadata::GetEnhancedBandNames() const
return GetBandInfo(MDStr::EnhancedBandName, *this);
}
int ImageMetadata::GetSize() const
{
int size = this->ImageMetadataBase::GetSize();
for (const auto &band : this->Bands)
size += band.GetSize();
return size;
}
// printing
std::ostream& operator<<(std::ostream& os, const otb::ImageMetadataBase& imd)
......
......@@ -87,6 +87,14 @@ otb_add_test(NAME ioTuImageMetadataCompactTest COMMAND otbMetadataTestDriver
otbImageMetadataCompactTest
${TEMP}/ioTuImageMetadataCompactTest.txt
)
otb_add_test(NAME ioTuImageMetadataGetSizeTest COMMAND otbMetadataTestDriver
--compare-ascii ${NOTOL} ${BASELINE_FILES}/ioTuImageMetadataGetSizeTest.txt
${TEMP}/ioTuImageMetadataGetSizeTest.txt
otbImageMetadataTest
otbImageMetadataGetSizeTest
${TEMP}/ioTuImageMetadataGetSizeTest.txt
)
otb_add_test(NAME ioTuImageMetadataAppendTest COMMAND otbMetadataTestDriver
--compare-ascii ${NOTOL} ${BASELINE_FILES}/ioTuImageMetadataAppendTest.txt
......@@ -210,4 +218,4 @@ if (Boost_UNIT_TEST_FRAMEWORK_FOUND)
COMMAND otbDateTest --
)
endif()
\ No newline at end of file
endif()
......@@ -283,6 +283,20 @@ void otbImageMetadataCompactTest(char* argv[])
outfile.close();
}
void otbImageMetadataGetSizeTest(char* argv[])
{
using namespace otb;
const char* outFileName = argv[2];
std::ofstream outfile(outFileName);
ImageMetadata md;
SetUpImageMetadata(md, 3);
otb::testtools::PrintMetadata(md, outfile);
outfile << "\nsize band 1: " << md.Bands[1].GetSize() << "\n";
outfile << "\nsize all: " << md.GetSize();
}
int otbImageMetadataTest(int argc, char* argv[])
{
if (argc < 2)
......@@ -301,6 +315,8 @@ int otbImageMetadataTest(int argc, char* argv[])
otbImageMetadataToFromKeywordlistTest(argv);
else if (testName == "otbImageMetadataCompactTest")
otbImageMetadataCompactTest(argv);
else if (testName == "otbImageMetadataGetSizeTest")
otbImageMetadataGetSizeTest(argv);
else
{
std::cout << "Unknown test name " << testName;
......
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