Skip to content

Commit

Permalink
Implemented xml read for statistics object
Browse files Browse the repository at this point in the history
  • Loading branch information
acpaquette committed Jan 12, 2024
1 parent 3fa54cf commit e2dcece
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
79 changes: 79 additions & 0 deletions isis/src/base/objs/Statistics/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find files of those names at the top level of this repository. **/
#include <QString>
#include <QUuid>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>

#include <float.h>

Expand All @@ -31,6 +32,84 @@ namespace Isis {
Reset(); // initialize
}

Statistics::Statistics(QXmlStreamReader *xmlReader, QObject *parent) { // TODO: does xml stuff need project???
// m_id = NULL;
SetValidRange();
Reset(); // initialize
readStatistics(xmlReader);
}

void Statistics::readStatistics(QXmlStreamReader *xmlReader) {
Q_ASSERT(xmlReader->name() == "statistics");
while (xmlReader->readNextStartElement()) {
if (xmlReader->qualifiedName() == "sum") {
m_sum = toDouble(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "sumSquares") {
m_sumsum = toDouble(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "range") {
while (xmlReader->readNextStartElement()) {
if (xmlReader->qualifiedName() == "minimum") {
m_minimum = toDouble(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "maximum") {
m_maximum = toDouble(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "validMinimum") {
m_validMinimum = toDouble(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "validMaximum") {
m_validMaximum = toDouble(xmlReader->readElementText());
}
else {
xmlReader->skipCurrentElement();
}
}
}
else if (xmlReader->qualifiedName() == "pixelCounts") {
while (xmlReader->readNextStartElement()) {
if (xmlReader->qualifiedName() == "totalPixels") {
m_totalPixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "validPixels") {
m_validPixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "nullPixels") {
m_nullPixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "lisPixels") {
m_lisPixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "lrsPixels") {
m_lrsPixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "hisPixels") {
m_hisPixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "hrsPixels") {
m_hrsPixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "underRangePixels") {
m_underRangePixels = toBigInt(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "overRangePixels") {
m_overRangePixels = toBigInt(xmlReader->readElementText());
}
else {
xmlReader->skipCurrentElement();
}
}
}
else if (xmlReader->qualifiedName() == "removedData") {
m_removedData = toBool(xmlReader->readElementText());
}
else {
xmlReader->skipCurrentElement();
}
}
}

/**
* Constructs a Statistics object from an input Pvl
*
Expand Down
3 changes: 3 additions & 0 deletions isis/src/base/objs/Statistics/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ find files of those names at the top level of this repository. **/
class QDataStream;
class QUuid;
class QXmlStreamWriter;
class QXmlStreamReader;

namespace Isis {
class Project;// ??? does xml stuff need project???
Expand Down Expand Up @@ -93,6 +94,8 @@ namespace Isis {
Q_OBJECT
public:
Statistics(QObject *parent = 0);
Statistics(QXmlStreamReader *xmlReader, QObject *parent = 0);
void readStatistics(QXmlStreamReader *xmlReader);
Statistics(const PvlGroup &inStats, QObject *parent = 0);
// TODO: does xml read/write stuff need Project input???
Statistics(const Statistics &other);
Expand Down

0 comments on commit e2dcece

Please sign in to comment.