9#include "BundleSettings.h"
17#include <QXmlStreamWriter>
18#include <QXmlInputSource>
20#include "BundleObservationSolveSettings.h"
21#include "IException.h"
24#include "PvlKeyword.h"
26#include "SpecialPixel.h"
27#include "XmlStackedHandlerReader.h"
42 m_observationSolveSettings.append(defaultSolveSettings);
113 xmlReader->setErrorHandler(
new XmlHandler(
this, project));
114 xmlReader->pushContentHandler(
new XmlHandler(
this, project));
125 : m_validateNetwork(other.m_validateNetwork),
126 m_cubeList(other.m_cubeList),
127 m_solveObservationMode(other.m_solveObservationMode),
128 m_solveRadius(other.m_solveRadius),
129 m_updateCubeLabel(other.m_updateCubeLabel),
130 m_errorPropagation(other.m_errorPropagation),
131 m_createInverseMatrix(other.m_createInverseMatrix),
132 m_outlierRejection(other.m_outlierRejection),
133 m_outlierRejectionMultiplier(other.m_outlierRejectionMultiplier),
134 m_globalPointCoord1AprioriSigma(other.m_globalPointCoord1AprioriSigma),
135 m_globalPointCoord2AprioriSigma(other.m_globalPointCoord2AprioriSigma),
136 m_globalPointCoord3AprioriSigma(other.m_globalPointCoord3AprioriSigma),
137 m_observationSolveSettings(other.m_observationSolveSettings),
138 m_convergenceCriteria(other.m_convergenceCriteria),
139 m_convergenceCriteriaThreshold(other.m_convergenceCriteriaThreshold),
140 m_convergenceCriteriaMaximumIterations(other.m_convergenceCriteriaMaximumIterations),
141 m_maximumLikelihood(other.m_maximumLikelihood),
142 m_solveTargetBody(other.m_solveTargetBody),
143 m_bundleTargetBody(other.m_bundleTargetBody),
144 m_cpCoordTypeReports(other.m_cpCoordTypeReports),
145 m_cpCoordTypeBundle(other.m_cpCoordTypeBundle),
146 m_outputFilePrefix(other.m_outputFilePrefix){
170 if (&other !=
this) {
172 m_cubeList = other.m_cubeList;
183 m_observationSolveSettings = other.m_observationSolveSettings;
270 bool updateCubeLabel,
271 bool errorPropagation,
275 double globalPointCoord1AprioriSigma,
276 double globalPointCoord2AprioriSigma,
277 double globalPointCoord3AprioriSigma) {
348 QList<BundleObservationSolveSettings> obsSolveSettingsList) {
349 m_observationSolveSettings = obsSolveSettingsList;
518 return m_observationSolveSettings.size();
539 if (m_observationSolveSettings[i].observationNumbers().contains(observationNumber)) {
540 return m_observationSolveSettings[i];
543 return defaultSolveSettings;
562 return m_observationSolveSettings[n];
564 QString msg =
"Unable to find BundleObservationSolveSettings with index = ["
577 return m_observationSolveSettings;
602 if (criteria.compare(
"SIGMA0", Qt::CaseInsensitive) == 0) {
605 else if (criteria.compare(
"PARAMETERCORRECTIONS", Qt::CaseInsensitive) == 0) {
609 "Unknown bundle convergence criteria [" + criteria +
"].",
627 if (criteria ==
Sigma0)
return "Sigma0";
630 "Unknown convergence criteria enum [" +
toString(criteria) +
"].",
647 int maximumIterations) {
728 double maxModelCQuantile) {
731 QString msg =
"For bundle adjustments with multiple maximum likelihood estimators, the first "
732 "model must be of type HUBER or HUBER_MODIFIED.";
748 QList< QPair< MaximumLikelihoodWFunctions::Model, double > >
1051 stream.writeStartElement(
"bundleSettings");
1053 stream.writeStartElement(
"globalSettings");
1057 stream.writeStartElement(
"solveOptions");
1065 stream.writeEndElement();
1067 stream.writeStartElement(
"aprioriSigmas");
1069 stream.writeAttribute(
"pointCoord1",
"N/A");
1075 stream.writeAttribute(
"pointCoord2",
"N/A");
1081 stream.writeAttribute(
"pointCoord3",
"N/A");
1086 stream.writeEndElement();
1088 stream.writeStartElement(
"outlierRejectionOptions");
1094 stream.writeAttribute(
"multiplier",
"N/A");
1096 stream.writeEndElement();
1098 stream.writeStartElement(
"convergenceCriteriaOptions");
1099 stream.writeAttribute(
"convergenceCriteria",
1101 stream.writeAttribute(
"threshold",
1103 stream.writeAttribute(
"maximumIterations",
1105 stream.writeEndElement();
1107 stream.writeStartElement(
"maximumLikelihoodEstimation");
1109 stream.writeStartElement(
"model");
1110 stream.writeAttribute(
"type",
1113 stream.writeEndElement();
1115 stream.writeEndElement();
1117 stream.writeStartElement(
"outputFileOptions");
1119 stream.writeEndElement();
1121 stream.writeEndElement();
1123 if (!m_observationSolveSettings.isEmpty()) {
1124 stream.writeStartElement(
"observationSolveSettingsList");
1125 for (
int i = 0; i < m_observationSolveSettings.size(); i++) {
1126 m_observationSolveSettings[i].save(stream, project);
1128 stream.writeEndElement();
1133 stream.writeEndElement();
1146 m_xmlHandlerBundleSettings = bundleSettings;
1147 m_xmlHandlerProject = project;
1148 m_xmlHandlerCharacters =
"";
1149 m_xmlHandlerObservationSettings.clear();
1176 const QString &localName,
1177 const QString &qName,
1178 const QXmlAttributes &attributes) {
1179 m_xmlHandlerCharacters =
"";
1181 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, attributes)) {
1183 if (localName ==
"solveOptions") {
1185 QString solveObservationModeStr = attributes.value(
"solveObservationMode");
1186 if (!solveObservationModeStr.isEmpty()) {
1187 m_xmlHandlerBundleSettings->m_solveObservationMode =
toBool(solveObservationModeStr);
1190 QString solveRadiusStr = attributes.value(
"solveRadius");
1191 if (!solveRadiusStr.isEmpty()) {
1192 m_xmlHandlerBundleSettings->m_solveRadius =
toBool(solveRadiusStr);
1195 QString coordTypeReportsStr = attributes.value(
"controlPointCoordinateTypeReports");
1196 if (!coordTypeReportsStr.isEmpty()) {
1197 m_xmlHandlerBundleSettings->m_cpCoordTypeReports =
1201 QString coordTypeBundleStr = attributes.value(
"controlPointCoordinateTypeBundle");
1202 if (!coordTypeBundleStr.isEmpty()) {
1203 m_xmlHandlerBundleSettings->m_cpCoordTypeBundle =
1207 QString updateCubeLabelStr = attributes.value(
"updateCubeLabel");
1208 if (!updateCubeLabelStr.isEmpty()) {
1209 m_xmlHandlerBundleSettings->m_updateCubeLabel =
toBool(updateCubeLabelStr);
1212 QString errorPropagationStr = attributes.value(
"errorPropagation");
1213 if (!errorPropagationStr.isEmpty()) {
1214 m_xmlHandlerBundleSettings->m_errorPropagation =
toBool(errorPropagationStr);
1217 QString createInverseMatrixStr = attributes.value(
"createInverseMatrix");
1218 if (!createInverseMatrixStr.isEmpty()) {
1219 m_xmlHandlerBundleSettings->m_createInverseMatrix =
toBool(createInverseMatrixStr);
1222 else if (localName ==
"aprioriSigmas") {
1224 QString globalPointCoord1AprioriSigmaStr = attributes.value(
"pointCoord1");
1225 m_xmlHandlerBundleSettings->m_globalPointCoord1AprioriSigma =
Isis::Null;
1227 if (!globalPointCoord1AprioriSigmaStr.isEmpty()) {
1228 if (globalPointCoord1AprioriSigmaStr ==
"N/A") {
1229 m_xmlHandlerBundleSettings->m_globalPointCoord1AprioriSigma =
Isis::Null;
1232 m_xmlHandlerBundleSettings->m_globalPointCoord1AprioriSigma
1233 =
toDouble(globalPointCoord1AprioriSigmaStr);
1237 QString globalPointCoord2AprioriSigmaStr = attributes.value(
"pointCoord2");
1238 if (!globalPointCoord2AprioriSigmaStr.isEmpty()) {
1239 if (globalPointCoord2AprioriSigmaStr ==
"N/A") {
1240 m_xmlHandlerBundleSettings->m_globalPointCoord2AprioriSigma =
Isis::Null;
1243 m_xmlHandlerBundleSettings->m_globalPointCoord2AprioriSigma
1244 =
toDouble(globalPointCoord2AprioriSigmaStr);
1248 QString globalPointCoord3AprioriSigmaStr = attributes.value(
"radius");
1249 if (!globalPointCoord3AprioriSigmaStr.isEmpty()) {
1250 if (globalPointCoord3AprioriSigmaStr ==
"N/A") {
1251 m_xmlHandlerBundleSettings->m_globalPointCoord3AprioriSigma =
Isis::Null;
1254 m_xmlHandlerBundleSettings->m_globalPointCoord3AprioriSigma
1255 =
toDouble(globalPointCoord3AprioriSigmaStr);
1259 else if (localName ==
"outlierRejectionOptions") {
1260 QString outlierRejectionStr = attributes.value(
"rejection");
1261 if (!outlierRejectionStr.isEmpty()) {
1262 m_xmlHandlerBundleSettings->m_outlierRejection =
toBool(outlierRejectionStr);
1265 QString outlierRejectionMultiplierStr = attributes.value(
"multiplier");
1266 if (!outlierRejectionMultiplierStr.isEmpty()) {
1267 if (outlierRejectionMultiplierStr !=
"N/A") {
1268 m_xmlHandlerBundleSettings->m_outlierRejectionMultiplier
1269 =
toDouble(outlierRejectionMultiplierStr);
1272 m_xmlHandlerBundleSettings->m_outlierRejectionMultiplier = 3.0;
1276 else if (localName ==
"convergenceCriteriaOptions") {
1278 QString convergenceCriteriaStr = attributes.value(
"convergenceCriteria");
1279 if (!convergenceCriteriaStr.isEmpty()) {
1280 m_xmlHandlerBundleSettings->m_convergenceCriteria
1284 QString convergenceCriteriaThresholdStr = attributes.value(
"threshold");
1285 if (!convergenceCriteriaThresholdStr.isEmpty()) {
1286 m_xmlHandlerBundleSettings->m_convergenceCriteriaThreshold
1287 =
toDouble(convergenceCriteriaThresholdStr);
1290 QString convergenceCriteriaMaximumIterationsStr = attributes.value(
"maximumIterations");
1291 if (!convergenceCriteriaMaximumIterationsStr.isEmpty()) {
1292 m_xmlHandlerBundleSettings->m_convergenceCriteriaMaximumIterations
1293 =
toInt(convergenceCriteriaMaximumIterationsStr);
1296 else if (localName ==
"model") {
1297 QString type = attributes.value(
"type");
1298 QString quantile = attributes.value(
"quantile");
1299 if (!type.isEmpty() && !quantile.isEmpty()) {
1300 m_xmlHandlerBundleSettings->m_maximumLikelihood.append(
1301 qMakePair(MaximumLikelihoodWFunctions::stringToModel(type),
1305 else if (localName ==
"outputFileOptions") {
1306 QString outputFilePrefixStr = attributes.value(
"fileNamePrefix");
1307 if (!outputFilePrefixStr.isEmpty()) {
1308 m_xmlHandlerBundleSettings->m_outputFilePrefix = outputFilePrefixStr;
1311 else if (localName ==
"bundleObservationSolveSettings") {
1312 m_xmlHandlerObservationSettings.append(
1327 m_xmlHandlerCharacters += ch;
1328 return XmlStackedHandler::characters(ch);
1342 const QString &qName) {
1343 if (!m_xmlHandlerCharacters.isEmpty()) {
1344 if (localName ==
"validateNetwork") {
1345 m_xmlHandlerBundleSettings->m_validateNetwork =
toBool(m_xmlHandlerCharacters);
1347 else if (localName ==
"observationSolveSettingsList") {
1348 for (
int i = 0; i < m_xmlHandlerObservationSettings.size(); i++) {
1349 m_xmlHandlerBundleSettings->m_observationSolveSettings.append(
1350 *m_xmlHandlerObservationSettings[i]);
1352 m_xmlHandlerObservationSettings.clear();
1355 m_xmlHandlerCharacters =
"";
1357 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
1368 qDebug() <<
"Parse error with BundleSettings at line " << exception.lineNumber()
1369 <<
", " <<
"column " << exception.columnNumber() <<
": "
1370 << qPrintable(exception.message());
This class is used to modify and manage solve settings for 1 to many BundleObservations.
This class is needed to read/write BundleSettings from/to an XML formateed file.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
XmlHandler(BundleSettings *bundleSettings, Project *project)
Create an XML Handler (reader) that can populate the BundleSettings class data.
~XmlHandler()
Destroys BundleSettings::XmlHandler object.
virtual bool characters(const QString &ch)
Add a character from an XML element to the content handler.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle end tags for the BundleSettings serialized XML.
bool fatalError(const QXmlParseException &exception)
Format an error message indicating a problem with BundleSettings.
Container class for BundleAdjustment settings.
bool m_createInverseMatrix
Indicates whether to create the inverse matrix file.
double globalPointCoord2AprioriSigma() const
Retrieves the global a priori sigma for 2nd coordinate of points for this bundle.
bool validateNetwork() const
This method is used to determine whether to validate the network before the bundle adjustment.
int convergenceCriteriaMaximumIterations() const
Retrieves the maximum number of iterations allowed to solve the bundle adjustment.
bool m_solveRadius
Indicates whether to solve for point radii.
BundleSettings & operator=(const BundleSettings &other)
Assignment operator to allow proper copying of the 'other' BundleSettings object to this one.
double globalPointCoord3AprioriSigma() const
Retrieves the global a priori sigma 3rd coordinate of points for this bundle.
void addMaximumLikelihoodEstimatorModel(MaximumLikelihoodWFunctions::Model model, double cQuantile)
Add a maximum likelihood estimator (MLE) model to the bundle adjustment.
BundleSettings()
Constructs a BundleSettings object.
QString m_outputFilePrefix
The prefix for all output files.
bool m_solveObservationMode
Indicates whether to solve for observation mode.
SurfacePoint::CoordinateType controlPointCoordTypeBundle() const
Indicates the control point coordinate type for the actual bundle adjust.
bool errorPropagation() const
This method is used to determine whether this bundle adjustment will perform error propagation.
void setConvergenceCriteria(ConvergenceCriteria criteria, double threshold, int maximumIterations)
Set the convergence criteria options for the bundle adjustment.
bool solvePMVelocity() const
This method is used to determine whether the bundle adjustment will solve for target body prime merid...
double m_globalPointCoord2AprioriSigma
The global a priori sigma for longitude or Y.
void save(QXmlStreamWriter &stream, const Project *project) const
This method is used to write a BundleSettings object in an XML format.
ConvergenceCriteria
This enum defines the options for the bundle adjustment's convergence.
@ Sigma0
The value of sigma0 will be used to determine that the bundle adjustment has converged.
@ ParameterCorrections
All parameter corrections will be used to determine that the bundle adjustment has converged.
BundleTargetBodyQsp bundleTargetBody() const
Retrieves a pointer to target body information for the bundle adjustment.
void setCreateInverseMatrix(bool createMatrix)
Turn the creation of the inverse correlation matrix file on or off.
bool solveMeanRadius() const
This method is used to determine whether the bundle adjustment will solve for target body mean radius...
bool solveRadius() const
This method is used to determine whether this bundle adjustment will solve for radius.
void init()
Set Default vales for a BundleSettings object.
bool solveTriaxialRadii() const
This method is used to determine whether the bundle adjustment will solve for target body triaxial ra...
BundleTargetBodyQsp m_bundleTargetBody
A pointer to the target body settings and information.
ConvergenceCriteria m_convergenceCriteria
Enumeration used to indicate what criteria to use to determine bundle adjustment convergence.
double m_globalPointCoord3AprioriSigma
The global a priori sigma for radius or Z.
bool solvePMAcceleration() const
This method is used to determine whether the bundle adjustment will solve for target body prime merid...
QList< BundleObservationSolveSettings > observationSolveSettings() const
Retrieves solve settings for the observation corresponding to the given index.
void setBundleTargetBody(BundleTargetBodyQsp bundleTargetBody)
Sets the target body for the bundle adjustment.
int numberTargetBodyParameters() const
This method is used to determine whether the bundle adjustment will solve for target body pole positi...
QString outputFilePrefix() const
Retrieve the output file prefix.
double globalPointCoord1AprioriSigma() const
Retrieves global a priori sigma for 1st coordinate of points for this bundle.
bool updateCubeLabel() const
This method is used to determine whether this bundle adjustment will update the cube labels.
double m_convergenceCriteriaThreshold
Tolerance value corresponding to the selected convergence criteria.
double m_outlierRejectionMultiplier
The multiplier value for outlier rejection.
bool outlierRejection() const
This method is used to determine whether outlier rejection will be performed on this bundle adjustmen...
void setOutputFilePrefix(QString outputFilePrefix)
Set the output file prefix for the bundle adjustment.
bool solvePoleRA() const
This method is used to determine whether the bundle adjustment will solve for target body pole right ...
bool solvePoleDecVelocity() const
This method is used to determine whether the bundle adjustment will solve for target body pole declin...
static QString convergenceCriteriaToString(ConvergenceCriteria criteria)
Converts the given BundleSettings::ConvergenceCriteria enumeration to a string.
void setValidateNetwork(bool validate)
Sets the internal flag to indicate whether to validate the network before the bundle adjustment.
~BundleSettings()
Destroys the BundleSettings object.
static ConvergenceCriteria stringToConvergenceCriteria(QString criteria)
Converts the given string value to a BundleSettings::ConvergenceCriteria enumeration.
SurfacePoint::CoordinateType m_cpCoordTypeReports
Indicates the coordinate type for outputting control points in reports.
bool m_outlierRejection
Indicates whether to perform automatic outlier detection/rejection.
bool m_errorPropagation
Indicates whether to perform error propagation.
bool createInverseMatrix() const
Indicates if the settings will allow the inverse correlation matrix to be created.
bool solvePoleRAVelocity() const
This method is used to determine whether the bundle adjustment will solve for target body pole right ...
QString cubeList() const
BundleSettings::cubeList.
QList< QPair< MaximumLikelihoodWFunctions::Model, double > > m_maximumLikelihood
Model and C-Quantile for each of the three maximum likelihood estimations.
void setOutlierRejection(bool outlierRejection, double multiplier=1.0)
Set the outlier rejection options for the bundle adjustment.
ConvergenceCriteria convergenceCriteria() const
Retrieves the convergence criteria to be used to solve the bundle adjustment.
QList< QPair< MaximumLikelihoodWFunctions::Model, double > > maximumLikelihoodEstimatorModels() const
Retrieves the list of maximum likelihood estimator (MLE) models with their corresponding C-Quantiles.
bool solvePoleDec() const
This method is used to determine whether the bundle adjustment will solve for target body pole declin...
bool m_validateNetwork
Indicates whether the network should be validated.
double m_globalPointCoord1AprioriSigma
The global a priori sigma for latitude or X.
int numberSolveSettings() const
Retrieves the number of observation solve settings.
void setSolveOptions(bool solveObservationMode=false, bool updateCubeLabel=false, bool errorPropagation=false, bool solveRadius=false, SurfacePoint::CoordinateType coordTypeBundle=SurfacePoint::Latitudinal, SurfacePoint::CoordinateType coordTypeReports=SurfacePoint::Latitudinal, double globalPointCoord1AprioriSigma=Isis::Null, double globalPointCoord2AprioriSigma=Isis::Null, double globalPointCoord3AprioriSigma=Isis::Null)
Set the solve options for the bundle adjustment.
SurfacePoint::CoordinateType controlPointCoordTypeReports() const
Indicates the control point coordinate type for reports.
bool solvePM() const
This method is used to determine whether the bundle adjustment will solve for target body prime merid...
void setCubeList(QString fileName)
BundleSettings::setCubeList.
bool m_updateCubeLabel
Indicates whether to update cubes.
double convergenceCriteriaThreshold() const
Retrieves the convergence threshold to be used to solve the bundle adjustment.
void setObservationSolveOptions(QList< BundleObservationSolveSettings > obsSolveSettingsList)
Add the list of solve options for each observation.
bool solveObservationMode() const
This method is used to determine whether this bundle adjustment will solve for observation mode.
int m_convergenceCriteriaMaximumIterations
Maximum number of iterations before quitting the bundle adjustment if it has not yet converged to the...
bool solveTargetBody() const
This method is used to determine whether the bundle adjustment will solve for target body.
double outlierRejectionMultiplier() const
Retrieves the outlier rejection multiplier for the bundle adjustment.
bool m_solveTargetBody
Indicates whether to solve for target body.
SurfacePoint::CoordinateType m_cpCoordTypeBundle
Indicates the coordinate type used for control points in the bundle adjustment.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
static QString modelToString(Model model)
Static method to return a string represtentation for a given MaximumLikelihoodWFunctions::Model enum.
Model
The supported maximum likelihood estimation models.
@ HuberModified
A modification to Huber's method propsed by William J.J.
The main project for ipce.
CoordinateType
Defines the coordinate typ, units, and coordinate index for some of the output methods.
@ Latitudinal
Planetocentric latitudinal (lat/lon/rad) coordinates.
@ Rectangular
Body-fixed rectangular x/y/z coordinates.
static CoordinateType stringToCoordinateType(QString type)
This method converts the given string value to a SurfacePoint::CoordinateType enumeration.
Manage a stack of content handlers for reading XML files.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
int toInt(const QString &string)
Global function to convert from a string to an integer.
const double Null
Value for an Isis Null pixel.
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
bool IsSpecial(const double d)
Returns if the input pixel is special.
double toDouble(const QString &string)
Global function to convert from a string to a double.
bool validate(const NaifVertex &v)
Verifies that the given NaifVector or NaifVertex is 3 dimensional.