Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to update CSM model state in jigsaw #4529

Merged
merged 5 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions isis/src/base/objs/CSMCamera/CSMCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,16 @@ namespace Isis {
}


/**
* Get the CSM Model state string to re-create the CSM Model.
*
* @returns @b QString The CSM Model state string
*/
QString CSMCamera::getModelState() const {
return QString::fromStdString(m_model->getModelState());
}


/**
* Set the time and update the sensor position and orientation.
*
Expand Down
2 changes: 2 additions & 0 deletions isis/src/base/objs/CSMCamera/CSMCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ namespace Isis {
virtual std::vector<double> GroundPartials(SurfacePoint groundPoint);
virtual std::vector<double> GroundPartials();

QString getModelState() const;

protected:
void setTarget(Pvl label);

Expand Down
28 changes: 20 additions & 8 deletions isis/src/control/apps/jigsaw/jigsaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ find files of those names at the top level of this repository. **/
#include <QSharedPointer>
#include <QString>

#include "Blob.h"
#include "BundleAdjust.h"
#include "BundleObservationSolveSettings.h"
#include "BundleResults.h"
Expand Down Expand Up @@ -148,15 +149,26 @@ namespace Isis {
break;
}

// Get Kernel group and add or replace LastModifiedInstrumentPointing
// keyword.
Table cmatrix = bundleAdjustment->cMatrix(i);
// Update the image parameters
QString jigComment = "Jigged = " + Isis::iTime::CurrentLocalTime();
cmatrix.Label().addComment(jigComment);
Table spvector = bundleAdjustment->spVector(i);
spvector.Label().addComment(jigComment);
c->write(cmatrix);
c->write(spvector);
if (c->hasBlob("CSMState", "String")) {
Blob csmStateBlob("CSMState", "String");
// Read the BLOB from the cube to prepropagate things like the model
// and plugin name
c->read(csmStateBlob);
std::string modelState = bundleAdjustment->modelState(i).toStdString();
csmStateBlob.setData(modelState.c_str(), modelState.size());
csmStateBlob.Label().addComment(jigComment);
c->write(csmStateBlob);
}
else {
Table cmatrix = bundleAdjustment->cMatrix(i);
cmatrix.Label().addComment(jigComment);
Table spvector = bundleAdjustment->spVector(i);
spvector.Label().addComment(jigComment);
c->write(cmatrix);
c->write(spvector);
}
p.WriteHistory(*c);
}
gp += PvlKeyword("Status", "Camera pointing updated");
Expand Down
23 changes: 23 additions & 0 deletions isis/src/control/objs/BundleAdjust/BundleAdjust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ find files of those names at the top level of this repository. **/
#include "CameraDistortionMap.h"
#include "CameraFocalPlaneMap.h"
#include "CameraGroundMap.h"
#include "CSMCamera.h"
#include "Control.h"
#include "ControlPoint.h"
#include "CorrelationMatrix.h"
Expand Down Expand Up @@ -2829,6 +2830,7 @@ namespace Isis {
return m_controlNet->Camera(i)->instrumentRotation()->Cache("InstrumentPointing");
}


/**
* Return a table spacecraft vector for the ith cube in the cube list given to the
* constructor.
Expand All @@ -2842,6 +2844,27 @@ namespace Isis {
}


/**
* Return the updated model state for the ith cube in the cube list given to the
* constructor. This is only valid for CSM cubes.
*
* @param i The index of the cube to get the model state for
*
* @return @b QString The updated CSM model state string
*/
QString BundleAdjust::modelState(int i) {
Camera *imageCam = m_controlNet->Camera(i);
if (imageCam->GetCameraType() != Camera::Csm) {
QString msg = "Cannot get model state for image [" + toString(i) +
"] because it is not a CSM camera model.";
throw IException(IException::Programmer, msg, _FILEINFO_);
}

CSMCamera *csmCamera = dynamic_cast<CSMCamera*>(imageCam);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not happy about having the dynamic_cast in BundleAdjust and not using the Observation, but attempts to use the polymorphism of the observation resulting in strange issues with the indices in the control network not matching the indices in the observations. I also ran into issues with who has the correct camera model and simultaneous open/close of the cube. This approach side-steps all of those issues at the cost of the cast happening here.

return csmCamera->getModelState();
}


/**
* Creates an iteration summary and an iteration group for the solution summary
*
Expand Down
1 change: 1 addition & 0 deletions isis/src/control/objs/BundleAdjust/BundleAdjust.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ namespace Isis {
bool isConverged();
Table cMatrix(int index);
Table spVector(int index);
QString modelState(int index);
int numberOfImages() const;
double iteration() const;

Expand Down
2 changes: 1 addition & 1 deletion isis/src/control/objs/BundleUtilities/BundleObservation.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Isis {
virtual bool computeTargetPartials(LinearAlgebra::Matrix &coeffTarget, BundleMeasure &measure,
BundleSettingsQsp &bundleSettings, BundleTargetBodyQsp &bundleTargetBody) = 0;
virtual bool computeImagePartials(LinearAlgebra::Matrix &coeffImage, BundleMeasure &measure) = 0;
virtual bool computePoint3DPartials(LinearAlgebra::Matrix &coeffPoint3D, BundleMeasure &measure, SurfacePoint::CoordinateType coordType = SurfacePoint::Rectangular) = 0;
virtual bool computePoint3DPartials(LinearAlgebra::Matrix &coeffPoint3D, BundleMeasure &measure, SurfacePoint::CoordinateType coordType = SurfacePoint::Rectangular) = 0;
virtual bool computeRHSPartials(LinearAlgebra::Vector &coeffRHS, BundleMeasure &measure) = 0;
virtual double computeObservationValue(BundleMeasure &measure, double deltaVal) = 0;

Expand Down
36 changes: 23 additions & 13 deletions isis/tests/CSMCameraTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,29 @@ TEST_F(CSMCameraFixture, getParameterUnits) {
}


TEST_F(CSMCameraSetFixture, SerialNumber) {
QString sn = SerialNumber::Compose(*testCube);
SerialNumberList snl;

snl.add(testCube->fileName());
QString instId = snl.spacecraftInstrumentId(sn);

EXPECT_PRED_FORMAT2(AssertQStringsEqual, sn, "TestPlatform/TestInstrument/2000-01-01T11:58:55.816");
EXPECT_TRUE(snl.hasSerialNumber(sn));
EXPECT_PRED_FORMAT2(AssertQStringsEqual, instId, "TESTPLATFORM/TESTINSTRUMENT");
}


TEST_F(CSMCameraFixture, CameraState) {
std::string testString = "MockSensorModel\nTestModelState";
EXPECT_CALL(mockModel, getModelState())
.Times(1)
.WillOnce(::testing::Return(testString));

EXPECT_EQ(dynamic_cast<CSMCamera*>(testCam)->getModelState().toStdString(), testString);
}


TEST_F(CSMCameraFixture, SetTime) {
try
{
Expand Down Expand Up @@ -654,16 +677,3 @@ TEST_F(CSMCameraFixture, Declination) {
" Declination is not supported for CSM camera models\"";
}
}


TEST_F(CSMCameraSetFixture, SerialNumber) {
QString sn = SerialNumber::Compose(*testCube);
SerialNumberList snl;

snl.add(testCube->fileName());
QString instId = snl.spacecraftInstrumentId(sn);

EXPECT_PRED_FORMAT2(AssertQStringsEqual, sn, "TestPlatform/TestInstrument/2000-01-01T11:58:55.816");
EXPECT_TRUE(snl.hasSerialNumber(sn));
EXPECT_PRED_FORMAT2(AssertQStringsEqual, instId, "TESTPLATFORM/TESTINSTRUMENT");
}
34 changes: 32 additions & 2 deletions isis/tests/FunctionalTestsJigsaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ TEST_F(MiniRFNetwork, FunctionalTestJigsawRadar) {
}


TEST_F(CSMNetwork, FunctionalTestCSMNetwork) {
TEST_F(CSMNetwork, unctionalTestJigsawCSM) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put the 'F' back in?

QTemporaryDir prefix;
QString outCnetFileName = prefix.path() + "/outTemp.net";

Expand All @@ -1605,6 +1605,7 @@ TEST_F(CSMNetwork, FunctionalTestCSMNetwork) {
"maxits=10",
"errorprop=yes",
"bundleout_txt=yes",
"update=yes",
"csmsolveset=adjustable",
"POINT_LATITUDE_SIGMA=1125",
"POINT_LONGITUDE_SIGMA=1125",
Expand Down Expand Up @@ -1647,7 +1648,6 @@ TEST_F(CSMNetwork, FunctionalTestCSMNetwork) {
"Test_B.cub, 6.65E-12, 1.41E-13, 4.70E-12, 2.875, 0.125, 3, 0.004162598, 0,"
" -0.0078125, 0.0078125, 6.29E-15, 0.004162598, 0, 258, -2, 256, 68.2, 0",
1);

compareCsvLine(line.getRow(5),
"Test_D.cub, 3.96E-12, 1.31E-13, 2.80E-12, -0.125, 0.125, 2.23E-17,"
" 0.004162598, 0, -2.875, -0.125, -3, 0.004162598, 0, 254,"
Expand All @@ -1663,4 +1663,34 @@ TEST_F(CSMNetwork, FunctionalTestCSMNetwork) {
compareCsvLine(line.getRow(11),
"Test_J.cub, 2.76E-12, 9.95E-14, 1.96E-12, -0.0625, 0.0625,"
"-2.63E-17, 0.016650391, 0, -0.03125, 0.03125, 6.23E-15, 0.016650391", 1);

Cube testB(tempDir.path() + "/Test_B.cub");
CSMCamera *camB = dynamic_cast<CSMCamera*>(testB.camera());
EXPECT_NEAR(camB->getParameterValue(0), 3.0, 0.00000001);
EXPECT_NEAR(camB->getParameterValue(1), 0.0, 0.00000001);
EXPECT_NEAR(camB->getParameterValue(2), 256.0, 0.00000001);

Cube testD(tempDir.path() + "/Test_D.cub");
CSMCamera *camD = dynamic_cast<CSMCamera*>(testD.camera());
EXPECT_NEAR(camD->getParameterValue(0), 0.0, 0.00000001);
EXPECT_NEAR(camD->getParameterValue(1), -3.0, 0.00000001);
EXPECT_NEAR(camD->getParameterValue(2), 256.0, 0.00000001);

Cube testF(tempDir.path() + "/Test_F.cub");
CSMCamera *camF = dynamic_cast<CSMCamera*>(testF.camera());
EXPECT_NEAR(camF->getParameterValue(0), 0.0, 0.00000001);
EXPECT_NEAR(camF->getParameterValue(1), 3.0, 0.00000001);
EXPECT_NEAR(camF->getParameterValue(2), 256.0, 0.00000001);

Cube testH(tempDir.path() + "/Test_H.cub");
CSMCamera *camH = dynamic_cast<CSMCamera*>(testH.camera());
EXPECT_NEAR(camH->getParameterValue(0), -3.0, 0.00000001);
EXPECT_NEAR(camH->getParameterValue(1), 0.0, 0.00000001);
EXPECT_NEAR(camH->getParameterValue(2), 256.0, 0.00000001);

Cube testJ(tempDir.path() + "/Test_J.cub");
CSMCamera *camJ = dynamic_cast<CSMCamera*>(testJ.camera());
EXPECT_NEAR(camJ->getParameterValue(0), 0.0, 0.00000001);
EXPECT_NEAR(camJ->getParameterValue(1), 0.0, 0.00000001);
EXPECT_NEAR(camJ->getParameterValue(2), 128.0, 0.00000001);
}