Skip to content

Commit

Permalink
Fixes to BundleSolution
Browse files Browse the repository at this point in the history
  • Loading branch information
amystamile-usgs committed Jul 17, 2024
1 parent 7651698 commit 0c70005
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 33 deletions.
20 changes: 20 additions & 0 deletions isis/src/control/objs/BundleSettings/BundleSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ namespace Isis {
m_observationSolveSettings.append(defaultSolveSettings);
}

/**
* Construct a BundleSettings object from member data read from an XML file.
*
* @code
* FileName xmlFile("bundleSettingsFileName.xml");
*
* QString xmlPath = xmlFile.expanded();
* QFile file(xmlPath);
* file.open(QFile::ReadOnly);
* QXmlStreamReader reader;
* BundleSettings settings(project, reader);
* @endcode
*
* @param xmlReader The Content handler to parse the BundleSettings XML
*/
BundleSettings::BundleSettings(QXmlStreamReader *xmlReader) {
init();
readBundleSettings(xmlReader);
}

/**
* @brief Set Default vales for a BundleSettings object.
* Note we call the default constructor to initialize the TargetBody information
Expand Down
1 change: 1 addition & 0 deletions isis/src/control/objs/BundleSettings/BundleSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ namespace Isis {
//================ constructors, destructor, operators ================//
//=====================================================================//
BundleSettings();
BundleSettings(QXmlStreamReader *xmlReader);
BundleSettings(const BundleSettings &other);
~BundleSettings();
BundleSettings &operator=(const BundleSettings &other);
Expand Down
63 changes: 44 additions & 19 deletions isis/src/control/objs/BundleSolutionInfo/BundleSolutionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,56 @@ namespace Isis {
}

void BundleSolutionInfo::readBundleSolutionInfo(QXmlStreamReader *xmlReader) {
m_xmlHandlerCharacters = "";

if (xmlReader->readNextStartElement()) {

if (xmlReader->name() == "bundleSettings") {
// m_xmlHandlerBundleSolutionInfo->m_settings =
// BundleSettingsQsp(new BundleSettings(m_xmlHandlerProject, xmlReader));
QString projectRoot;
if (m_xmlHandlerProject) {
projectRoot = m_xmlHandlerProject->projectRoot() + "/";
}
Q_ASSERT(xmlReader->name() == "bundleSolutionInfo");
while(xmlReader->readNextStartElement()) {
std::cout << xmlReader->name() << std::endl;
if (xmlReader->qualifiedName() == "generalAttributes") {
while (xmlReader->readNextStartElement()) {
if (xmlReader->qualifiedName() == "id") {
m_id = new QUuid(xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "name") {
m_name = xmlReader->readElementText();
}
else if (xmlReader->qualifiedName() == "runTime") {
m_runTime = xmlReader->readElementText();
}
else if (xmlReader->qualifiedName() == "inputFileName") {
m_inputControlNetFileName = new FileName(projectRoot + xmlReader->readElementText());
}
else if (xmlReader->qualifiedName() == "bundleOutTXT") {
m_txtBundleOutputFilename = projectRoot + xmlReader->readElementText();
}
else if (xmlReader->qualifiedName() == "imagesCSV") {
m_csvSavedImagesFilename = projectRoot + xmlReader->readElementText();
}
else if (xmlReader->qualifiedName() == "pointsCSV") {
m_csvSavedPointsFilename = projectRoot + xmlReader->readElementText();
}
else if (xmlReader->qualifiedName() == "residualsCSV") {
m_csvSavedResidualsFilename = projectRoot + xmlReader->readElementText();
}
else {
xmlReader->skipCurrentElement();
}
}
}
else if (xmlReader->name() == "bundleSettings") {
m_settings = NULL;
m_settings = BundleSettingsQsp(new BundleSettings(xmlReader));
}
else if (xmlReader->name() == "bundleResults") {
m_statisticsResults = NULL;
m_statisticsResults = new BundleResults(xmlReader);
}
else if (xmlReader->name() == "imageList") {
// m_xmlHandlerBundleSolutionInfo->m_adjustedImages->append(
// new ImageList(m_xmlHandlerProject, xmlReader));
}
else if (xmlReader->name() == "outputControl") {
// FileName outputControlPath = FileName(m_xmlHandlerProject->bundleSolutionInfoRoot() + "/"
// + m_xmlHandlerBundleSolutionInfo->runTime());

// m_xmlHandlerBundleSolutionInfo->m_outputControl = new Control(outputControlPath, xmlReader);
}
else {
xmlReader->raiseError(QObject::tr("Incorrect file"));
xmlReader->skipCurrentElement();
}
}
}
}

/**
Expand Down
32 changes: 18 additions & 14 deletions isis/tests/BundleSolutionInfoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,22 @@
namespace Isis {
class BundleSolutionInfoXmlHandlerTester : public BundleSolutionInfo {
public:
BundleSolutionInfoXmlHandlerTester(FileName xmlFile) : BundleSolutionInfo() {

BundleSolutionInfoXmlHandlerTester(QXmlStreamReader *reader, FileName xmlFile) : BundleSolutionInfo() {
QString xmlPath(xmlFile.expanded());
QFile file(xmlPath);

if (!file.open(QFile::ReadOnly) ) {
throw IException(IException::Io,
QString("Unable to open xml file, [%1], with read access").arg(xmlPath),
QString("Unable to open xml file, [%1], with read access").arg(xmlFile.expanded()),
_FILEINFO_);
}

QXmlStreamReader reader(&file);

while (!reader.atEnd()) {
reader.readNext();
}
if (reader.hasError()) {
throw IException(IException::Unknown,
QString("Failed to parse xml file, [%1]").arg(xmlPath),
_FILEINFO_);
if (reader->readNextStartElement()) {
if (reader->name() == "bundleSolutionInfo") {
readBundleSolutionInfo(reader);
}
else {
reader->raiseError(QObject::tr("Incorrect file"));
}
}
}

Expand Down Expand Up @@ -98,7 +94,15 @@ TEST_F(ThreeImageNetwork, BundleSolutionInfoSerialization) {
writer.writeEndDocument();
qXmlFile.close();

BundleSolutionInfoXmlHandlerTester newSolution(saveFile);
QFile xml(saveFile);
if(!xml.open(QFile::ReadOnly | QFile::Text)){
throw IException(IException::Unknown,
QString("Failed to parse xml file, [%1]").arg(xml.fileName()),
_FILEINFO_);
}

QXmlStreamReader reader(&xml);
BundleSolutionInfoXmlHandlerTester newSolution(&reader, saveFile);

EXPECT_EQ(solution.adjustedImages().size(), newSolution.adjustedImages().size());
EXPECT_EQ(solution.bundleResults().numberObservations(), newSolution.bundleResults().numberObservations());
Expand Down

0 comments on commit 0c70005

Please sign in to comment.