diff --git a/isis/src/base/objs/CSMCamera/CSMCamera.cpp b/isis/src/base/objs/CSMCamera/CSMCamera.cpp index d9c1e6443b..c3f04aaf98 100644 --- a/isis/src/base/objs/CSMCamera/CSMCamera.cpp +++ b/isis/src/base/objs/CSMCamera/CSMCamera.cpp @@ -905,6 +905,42 @@ namespace Isis { } + /** + * Get the name of the parameter. + * + * @param index The index of parameter + * + * @returns @b QString name of the parameter at index + */ + QString CSMCamera::getParameterName(int index) { + return QString::fromStdString(m_model->getParameterName(index)); + } + + + /** + * Get the value of a parameter. + * + * @param index The index of the parameter + * + * @returns @b double value of the parameter at index + */ + double CSMCamera::getParameterValue(int index) { + return m_model->getParameterValue(index); + } + + + /** + * Get the units of the parameter at a particular index. + * + * @param index The index of parameter + * + * @returns @b QString units of the parameter at index + */ + QString CSMCamera::getParameterUnits(int index) { + return QString::fromStdString(m_model->getParameterUnits(index)); + } + + /** * Set the time and update the sensor position and orientation. * diff --git a/isis/src/base/objs/CSMCamera/CSMCamera.h b/isis/src/base/objs/CSMCamera/CSMCamera.h index 0c01749ba6..95b637a2ff 100644 --- a/isis/src/base/objs/CSMCamera/CSMCamera.h +++ b/isis/src/base/objs/CSMCamera/CSMCamera.h @@ -122,6 +122,9 @@ namespace Isis { std::vector getParameterIndices(QStringList paramList) const; void applyParameterCorrection(int index, double correction); double getParameterCovariance(int index1, int index2); + QString getParameterName(int index); + QString getParameterUnits(int index); + double getParameterValue(int index); std::vector getSensorPartials(int index, SurfacePoint groundPoint); virtual std::vector GroundPartials(SurfacePoint groundPoint); diff --git a/isis/src/control/objs/CsmBundleObservation/CsmBundleObservation.cpp b/isis/src/control/objs/CsmBundleObservation/CsmBundleObservation.cpp index d79d02d7ae..431af79f94 100644 --- a/isis/src/control/objs/CsmBundleObservation/CsmBundleObservation.cpp +++ b/isis/src/control/objs/CsmBundleObservation/CsmBundleObservation.cpp @@ -563,218 +563,65 @@ QString CsmBundleObservation::formatBundleOutputString(bool errorPropagation, bo * (corrections, sigmas, adjusted sigmas...) to the output. */ void CsmBundleObservation::bundleOutputString(std::ostream &fpOut, bool errorPropagation) { - // TODO implement for CSM - - // char buf[4096]; - - // QVector finalParameterValues; - // int nPositionCoefficients, nPointingCoefficients; - // bool useDefaultPosition, useDefaultPointing,useDefaultTwist; - - // bundleOutputFetchData(finalParameterValues, - // nPositionCoefficients,nPointingCoefficients, - // useDefaultPosition,useDefaultPointing,useDefaultTwist); - // int nPositionParameters = 3 * nPositionCoefficients; - // int nPointingParameters = 3 * nPointingCoefficients; - // int nParameters = nPositionParameters + nPointingParameters; - - // // for convenience, create vectors of parameters names and values in the correct sequence - // QStringList parameterNamesListX,parameterNamesListY,parameterNamesListZ, - // parameterNamesListRA,parameterNamesListDEC,parameterNamesListTWI, - // parameterNamesList; - // QStringList correctionUnitListX,correctionUnitListY,correctionUnitListZ, - // correctionUnitListRA,correctionUnitListDEC,correctionUnitListTWI, - // correctionUnitList; - - // QString str("%1(%2) "); - // QString str2("%1(%2) "); - // QString strN("%1(%2)"); - - - // if (nPositionCoefficients > 0) { - // for (int j = 0; j < nPositionCoefficients;j++) { - // if (j == 0) { - // parameterNamesListX.append(str.arg(" X ").arg("km")); - // parameterNamesListY.append(str.arg(" Y ").arg("km")); - // parameterNamesListZ.append(str.arg(" Z ").arg("km")); - // correctionUnitListX.append("m"); - // correctionUnitListY.append("m"); - // correctionUnitListZ.append("m"); - // } //end inner-if - - // else if (j==1) { - // parameterNamesListX.append( str2.arg(" ").arg("km/s") ); - // parameterNamesListY.append( str2.arg(" ").arg("km/s") ); - // parameterNamesListZ.append( str2.arg(" ").arg("km/s") ); - // correctionUnitListX.append("m/s"); - // correctionUnitListY.append("m/s"); - // correctionUnitListZ.append("m/s"); - // } - // else { - // QString str("%1(%2)"); - // parameterNamesListX.append(strN.arg(" ").arg("km/s^"+toString(j) ) ); - // parameterNamesListY.append(strN.arg(" ").arg("km/s^"+toString(j) ) ); - // parameterNamesListZ.append(strN.arg(" ").arg("km/s^"+toString(j) ) ); - // correctionUnitListX.append("m/s^"+toString(j)); - // correctionUnitListY.append("m/s^"+toString(j)); - // correctionUnitListZ.append("m/s^"+toString(j)); - // } - // }//end for - // }//end outer-if - - // if (nPointingCoefficients > 0) { - // for (int j = 0; j < nPointingCoefficients;j++) { - // if (j == 0) { - // parameterNamesListRA.append(str.arg(" RA ").arg("dd")); - // parameterNamesListDEC.append(str.arg("DEC ").arg("dd")); - // parameterNamesListTWI.append(str.arg("TWI ").arg("dd")); - // correctionUnitListRA.append("dd"); - // correctionUnitListDEC.append("dd"); - // correctionUnitListTWI.append("dd"); - // } //end inner-if - - // else if (j==1) { - // parameterNamesListRA.append( str2.arg(" ").arg("dd/s") ); - // parameterNamesListDEC.append( str2.arg(" ").arg("dd/s") ); - // parameterNamesListTWI.append( str2.arg(" ").arg("dd/s") ); - // correctionUnitListRA.append("dd/s"); - // correctionUnitListDEC.append("dd/s"); - // correctionUnitListTWI.append("dd/s"); - // } - // else { - // parameterNamesListRA.append(strN.arg(" ").arg("dd/s^"+toString(j) ) ); - // parameterNamesListDEC.append(strN.arg(" ").arg("dd/s^"+toString(j) ) ); - // parameterNamesListTWI.append(strN.arg(" ").arg("dd/s^"+toString(j) ) ); - // correctionUnitListRA.append("dd/s^"+toString(j)); - // correctionUnitListDEC.append("dd/s^"+toString(j)); - // correctionUnitListTWI.append("dd/s^"+toString(j)); - // } - // }//end for - // }// end outer-if - - // //Put all of the parameter names together into one QStringList - // parameterNamesList.append(parameterNamesListX); - // parameterNamesList.append(parameterNamesListY); - // parameterNamesList.append(parameterNamesListZ); - // parameterNamesList.append(parameterNamesListRA); - // parameterNamesList.append(parameterNamesListDEC); - // parameterNamesList.append(parameterNamesListTWI); - - // //Put all of the correction unit names together into one QStringList - // correctionUnitList.append(correctionUnitListX); - // correctionUnitList.append(correctionUnitListY); - // correctionUnitList.append(correctionUnitListZ); - // correctionUnitList.append(correctionUnitListDEC); - // correctionUnitList.append(correctionUnitListRA); - // correctionUnitList.append(correctionUnitListTWI); - - // // Save the list of parameter names we've accumulated above - // m_parameterNamesList = parameterNamesList; + char buf[4096]; - // // Set up default values when we are using default position - // QString sigma = "N/A"; - // QString adjustedSigma = "N/A"; - // double correction = 0.0; - - // // position parameters - // for (int i = 0; i < nPositionParameters; i++) { - // // If not using the default position, we can correctly access sigmas and corrections - // // members - // if (!useDefaultPosition) { - // correction = m_corrections(i); - // adjustedSigma = QString::number(m_adjustedSigmas[i], 'f', 8); - // sigma = ( IsSpecial(m_aprioriSigmas[i]) ? "FREE" : toString(m_aprioriSigmas[i], 8) ); - // } - - // sprintf(buf,"%s",parameterNamesList.at(i).toStdString().c_str() ); - // fpOut << buf; - // sprintf(buf,"%18.8lf ",finalParameterValues[i] - correction); - // fpOut << buf; - // sprintf(buf,"%20.8lf ",correction); - // fpOut << buf; - // sprintf(buf,"%23.8lf ",finalParameterValues[i]); - // fpOut << buf; - // sprintf(buf," "); - // fpOut << buf; - // sprintf(buf,"%6s",sigma.toStdString().c_str()); - // fpOut << buf; - // sprintf(buf," "); - // fpOut << buf; - // if (errorPropagation) { - // sprintf(buf,"%s",adjustedSigma.toStdString().c_str()); - // } - // else { - // sprintf(buf,"%s","N/A"); - // } - // fpOut< finalParameterValues; + CSMCamera *csmCamera = dynamic_cast(front()->camera()); - // } + int nParameters = numberParameters(); - // // We need to use an offset of -3 (1 coef; X,Y,Z) if we used the default center coordinate - // // (i.e. we did not solve for position), as m_corrections and m_*sigmas are populated - // // according to which parameters are solved - // int offset = 0; - // if (useDefaultPosition) { - // offset = 3; - // } + QStringList parameterNamesList; + QStringList parameterUnitList; - // // pointing parameters - // for (int i = nPositionParameters; i < nParameters; i++) { - // if (!useDefaultPointing) { - // // If solving camera and not solving for twist, provide default values for twist to - // // prevent bad indexing into m_corrections and m_*sigmas - // // TWIST is last parameter, which corresponds to nParameters - nPointingCoefficients - // if ( (i >= nParameters - nPointingCoefficients) && useDefaultTwist) { - // correction = 0.0; - // adjustedSigma = "N/A"; - // sigma = "N/A"; - // } - // else { - // correction = m_corrections(i - offset); - // adjustedSigma = QString::number(m_adjustedSigmas(i-offset) * RAD2DEG, 'f', 8); - // sigma = ( IsSpecial(m_aprioriSigmas[i - offset]) ? "FREE" : - // toString(m_aprioriSigmas[i-offset], 8) ); - // } - // } - // // We are using default pointing, so provide default correction and sigma values to output - // else { - // correction = 0.0; - // adjustedSigma = "N/A"; - // sigma = "N/A"; - // } + for (int i = 0; i < nParameters; i++) { + parameterNamesList.append(csmCamera->getParameterName(m_paramIndices[i])); + parameterUnitList.append(csmCamera->getParameterUnits(m_paramIndices[i])); + finalParameterValues.append(csmCamera->getParameterValue(m_paramIndices[i])); + } - // sprintf(buf,"%s",parameterNamesList.at(i).toStdString().c_str() ); - // fpOut << buf; - // sprintf(buf,"%18.8lf ",(finalParameterValues[i]*RAD2DEG - correction*RAD2DEG)); - // fpOut << buf; - // sprintf(buf,"%20.8lf ",(correction*RAD2DEG)); - // fpOut << buf; - // sprintf(buf,"%23.8lf ",(finalParameterValues[i]*RAD2DEG)); - // fpOut << buf; - // sprintf(buf," "); - // fpOut << buf; - // sprintf(buf,"%6s",sigma.toStdString().c_str()); - // fpOut << buf; - // sprintf(buf," "); - // fpOut << buf; - // if (errorPropagation) { - // sprintf(buf,"%s",adjustedSigma.toStdString().c_str()); - // } - // else { - // sprintf(buf,"%s","N/A"); - // } - // fpOut<(measure.camera()); SurfacePoint groundPoint = measure.parentControlPoint()->adjustedSurfacePoint(); @@ -935,27 +782,27 @@ QString CsmBundleObservation::formatBundleOutputString(bool errorPropagation, bo /** - * Calculates the ground partials for the line, sample currently - * set in the sensor model. - * - * @param coeffPoint3D A matrix that will be populated with the + * Calculates the ground partials for the line, sample currently + * set in the sensor model. + * + * @param coeffPoint3D A matrix that will be populated with the * (line, sample) partials with respect to * the ground point. - * @param measure The measure that the partials are being + * @param measure The measure that the partials are being * computed for. - * @param coordType Not used in this class. Coordinates are + * @param coordType Not used in this class. Coordinates are * x,y,z - * - * @return bool + * + * @return bool */ bool CsmBundleObservation::computePoint3DPartials(LinearAlgebra::Matrix &coeffPoint3D, BundleMeasure &measure, SurfacePoint::CoordinateType coordType) { coeffPoint3D.clear(); CSMCamera *measureCamera = dynamic_cast(measure.camera()); - // do ground partials + // do ground partials vector groundPartials = measureCamera->GroundPartials(); - + // groundPartials is: // line WRT x // line WRT y @@ -975,16 +822,16 @@ QString CsmBundleObservation::formatBundleOutputString(bool errorPropagation, bo /** - * Calculates the sample, line residuals between the values - * measured in the image and the ground-to-image sample, line - * calculated by the sensor model. - * - * @param coeffRHS A vector that will contain the sample, line + * Calculates the sample, line residuals between the values + * measured in the image and the ground-to-image sample, line + * calculated by the sensor model. + * + * @param coeffRHS A vector that will contain the sample, line * residuals. - * @param measure The measure that the partials are being + * @param measure The measure that the partials are being * computed for. - * - * @return bool + * + * @return bool */ bool CsmBundleObservation::computeRHSPartials(LinearAlgebra::Vector &coeffRHS, BundleMeasure &measure) { // Clear old values @@ -993,7 +840,7 @@ QString CsmBundleObservation::formatBundleOutputString(bool errorPropagation, bo Camera *measureCamera = measure.camera(); BundleControlPoint* point = measure.parentControlPoint(); - // Get ground-to-image computed coordinates for this point. + // Get ground-to-image computed coordinates for this point. if (!(measureCamera->SetGround(point->adjustedSurfacePoint()))) { QString msg = "Unable to map apriori surface point for measure "; msg += measure.cubeSerialNumber() + " on point " + point->id() + " back into image."; @@ -1003,7 +850,7 @@ QString CsmBundleObservation::formatBundleOutputString(bool errorPropagation, bo double computedLine = measureCamera->Line(); // The RHS is the difference between the measured coordinates on the image - // and the coordinates calculated by the ground to image call. + // and the coordinates calculated by the ground to image call. double deltaSample = measure.sample() - computedSample; double deltaLine = measure.line() - computedLine; @@ -1015,15 +862,15 @@ QString CsmBundleObservation::formatBundleOutputString(bool errorPropagation, bo /** - * Returns the observed value in (sample, line) coordinates. - * This requires no modification for Csm. - * - * @param measure measure The measure that the partials are + * Returns the observed value in (sample, line) coordinates. + * This requires no modification for Csm. + * + * @param measure measure The measure that the partials are * being computed for. - * @param deltaVal The difference between the measured and + * @param deltaVal The difference between the measured and * calculate sample, line coordinates - * - * @return double The The difference between the measured and + * + * @return double The The difference between the measured and * calculated (line, sample) coordinate */ double CsmBundleObservation::computeObservationValue(BundleMeasure &measure, double deltaVal) { diff --git a/isis/tests/CSMCameraTests.cpp b/isis/tests/CSMCameraTests.cpp index 54879ca5cf..1bcf526ce1 100644 --- a/isis/tests/CSMCameraTests.cpp +++ b/isis/tests/CSMCameraTests.cpp @@ -296,6 +296,33 @@ TEST_F(CSMCameraFixture, getParameterCovariance) { } +TEST_F(CSMCameraFixture, getParameterName) { + EXPECT_CALL(mockModel, getParameterName(2)) + .Times(1) + .WillOnce(::testing::Return("Omega Bias")); + + EXPECT_EQ(dynamic_cast(testCam)->getParameterName(2), "Omega Bias"); +} + + +TEST_F(CSMCameraFixture, getParameterValue) { + EXPECT_CALL(mockModel, getParameterValue(2)) + .Times(1) + .WillOnce(::testing::Return(0.5)); + + EXPECT_DOUBLE_EQ(dynamic_cast(testCam)->getParameterValue(2), 0.5); +} + + +TEST_F(CSMCameraFixture, getParameterUnits) { + EXPECT_CALL(mockModel, getParameterUnits(2)) + .Times(1) + .WillOnce(::testing::Return("m")); + + EXPECT_EQ(dynamic_cast(testCam)->getParameterUnits(2), "m"); +} + + TEST_F(CSMCameraFixture, SetTime) { try { diff --git a/isis/tests/CsmBundleObservationTests.cpp b/isis/tests/CsmBundleObservationTests.cpp new file mode 100644 index 0000000000..b3f82cc5e5 --- /dev/null +++ b/isis/tests/CsmBundleObservationTests.cpp @@ -0,0 +1,79 @@ +#include +#include +#include + +#include "CsmBundleObservation.h" +#include "CSMCamera.h" +#include "Fixtures.h" +#include "MockCsmPlugin.h" +#include "Mocks.h" +#include "TestUtilities.h" +#include "SerialNumber.h" +#include "BundleTargetBody.h" +#include "BundleImage.h" + + +#include "gmock/gmock.h" + + +using namespace Isis; + +TEST_F(CSMCameraFixture, CsmBundleOutputString) { + EXPECT_CALL(mockModel, getNumParameters()) + .WillRepeatedly(::testing::Return(3)); + EXPECT_CALL(mockModel, getParameterType(0)) + .WillRepeatedly(::testing::Return(csm::param::REAL)); + EXPECT_CALL(mockModel, getParameterType(1)) + .WillRepeatedly(::testing::Return(csm::param::REAL)); + EXPECT_CALL(mockModel, getParameterType(2)) + .WillRepeatedly(::testing::Return(csm::param::REAL)); + EXPECT_CALL(mockModel, getParameterName(0)) + .WillRepeatedly(::testing::Return("Parameter 1")); + EXPECT_CALL(mockModel, getParameterName(1)) + .WillRepeatedly(::testing::Return("Parameter 2")); + EXPECT_CALL(mockModel, getParameterName(2)) + .WillRepeatedly(::testing::Return("Parameter 3")); + EXPECT_CALL(mockModel, getParameterUnits(0)) + .WillRepeatedly(::testing::Return("m")); + EXPECT_CALL(mockModel, getParameterUnits(1)) + .WillRepeatedly(::testing::Return("sec")); + EXPECT_CALL(mockModel, getParameterUnits(2)) + .WillRepeatedly(::testing::Return("cm")); + EXPECT_CALL(mockModel, getParameterValue(0)) + .WillRepeatedly(::testing::Return(234.2)); + EXPECT_CALL(mockModel, getParameterValue(1)) + .WillRepeatedly(::testing::Return(0.0)); + EXPECT_CALL(mockModel, getParameterValue(2)) + .WillRepeatedly(::testing::Return(M_PI)); + EXPECT_CALL(mockModel, getParameterCovariance(0, 0)) + .WillRepeatedly(::testing::Return(0.112)); + EXPECT_CALL(mockModel, getParameterCovariance(1, 1)) + .WillRepeatedly(::testing::Return(0.0123)); + EXPECT_CALL(mockModel, getParameterCovariance(2, 2)) + .WillRepeatedly(::testing::Return(0.342)); + + std::stringstream fpOut; + + QString sn = SerialNumber::Compose(*testCube); + + BundleImageQsp bi = BundleImageQsp(new BundleImage(testCam, sn, testCube->fileName())); + BundleObservationSolveSettingsQsp bundleSolSetting(new BundleObservationSolveSettings()); + + bundleSolSetting->setCSMSolveSet(csm::param::ADJUSTABLE); + + CsmBundleObservation observation(bi, + "ObservationNumber", + "InstrumentId", + nullptr); + + EXPECT_TRUE(observation.setSolveSettings(bundleSolSetting)); + observation.bundleOutputString(fpOut, false); + + QStringList lines = QString::fromStdString(fpOut.str()).split("\n"); + EXPECT_EQ(lines[0].toStdString(), + "Parameter 1 234.20000000 0.00000000 234.20000000 0.112 N/A m"); + EXPECT_EQ(lines[1].toStdString(), + "Parameter 2 0.00000000 0.00000000 0.00000000 0.0123 N/A sec"); + EXPECT_EQ(lines[2].toStdString(), + "Parameter 3 3.14159265 0.00000000 3.14159265 0.342 N/A cm"); +}