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

Test camera model #95

Merged
merged 6 commits into from
Aug 22, 2018
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
12 changes: 6 additions & 6 deletions src/UsgsAstroFrameSensorModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ csm::ImageCoord UsgsAstroFrameSensorModel::groundToImage(

//Convert distorted mm into line/sample
double sample, line;
sample = m_iTransS[0] + m_iTransS[1] * distortedx + m_iTransS[2] * distortedx + m_ccdCenter[0] - 0.5;
line = m_iTransL[0] + m_iTransL[1] * distortedy + m_iTransL[2] * distortedy + m_ccdCenter[0] - 0.5;
sample = m_iTransS[0] + m_iTransS[1] * distortedx + m_iTransS[2] * distortedx + m_ccdCenter[0];
line = m_iTransL[0] + m_iTransL[1] * distortedy + m_iTransL[2] * distortedy + m_ccdCenter[0];

return csm::ImageCoord(line, sample);
}
Expand Down Expand Up @@ -244,8 +244,8 @@ csm::EcefCoord UsgsAstroFrameSensorModel::imageToGround(const csm::ImageCoord &i

//Convert from the pixel space into the metric space
double optical_center_x, optical_center_y, x_camera, y_camera;
optical_center_x = m_ccdCenter[0] - 0.5;
optical_center_y = m_ccdCenter[1] - 0.5;
optical_center_x = m_ccdCenter[0];
optical_center_y = m_ccdCenter[1];
y_camera = m_transY[0] + m_transY[1] * (lo - optical_center_y) + m_transY[2] * (lo - optical_center_y);
x_camera = m_transX[0] + m_transX[1] * (so - optical_center_x) + m_transX[2] * (so - optical_center_x);

Expand Down Expand Up @@ -301,8 +301,8 @@ csm::EcefLocus UsgsAstroFrameSensorModel::imageToRemoteImagingLocus(const csm::I
csm::WarningList *warnings) const {
// Find the line,sample on the focal plane (mm)
// CSM center = 0.5, MDIS IK center = 1.0
double col = imagePt.samp - (m_ccdCenter[0] - 0.5);
double row = imagePt.line - (m_ccdCenter[1] - 0.5);
double col = imagePt.samp - (m_ccdCenter[0]);
double row = imagePt.line - (m_ccdCenter[1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I could have sworn this was already merged by #91 weird

Copy link
Collaborator

Choose a reason for hiding this comment

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

I bet that upstream was not pulled and merged, so we are seeing both.

double focalPlaneX = m_transX[0] + m_transX[1] * col + m_transX[2] * col;
double focalPlaneY = m_transY[0] + m_transY[1] * row + m_transY[2] * row;

Expand Down
111 changes: 104 additions & 7 deletions tests/FrameCameraTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,33 @@

using json = nlohmann::json;

class FrameIsdTest : public ::testing::Test {
protected:


virtual void SetUp() {
std::ifstream isdFile("data/simpleFramerISD.json");
json jsonIsd = json::parse(isdFile);
for (json::iterator it = jsonIsd.begin(); it != jsonIsd.end(); ++it) {
json jsonValue = it.value();
if (jsonValue.size() > 1) {
for (int i = 0; i < jsonValue.size(); i++) {
isd.addParam(it.key(), jsonValue[i].dump());
}
}
else {
isd.addParam(it.key(), jsonValue.dump());
}
}
isdFile.close();
}
};

Copy link
Contributor

Choose a reason for hiding this comment

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

code copy and paste will be removed once Fixtures.h files gets merged.

class FrameSensorModel : public ::testing::Test {
protected:

UsgsAstroFrameSensorModel *sensorModel;

csm::Isd isd;
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be removed

void SetUp() override {
sensorModel = NULL;
std::ifstream isdFile("data/simpleFramerISD.json");
Expand Down Expand Up @@ -57,14 +79,14 @@ class FrameSensorModel : public ::testing::Test {

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can yank this comment, since this is fixed.

//centered and slightly off-center:
TEST_F(FrameSensorModel, Center) {
csm::ImageCoord imagePt(7.0, 7.0);
csm::ImageCoord imagePt(7.5, 7.5);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 10.0, 1e-8);
EXPECT_NEAR(groundPt.y, 0, 1e-8);
EXPECT_NEAR(groundPt.z, 0, 1e-8);
}
TEST_F(FrameSensorModel, SlightlyOffCenter) {
csm::ImageCoord imagePt(7.0, 6.0);
csm::ImageCoord imagePt(7.5, 6.5);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 9.80194018, 1e-8);
EXPECT_NEAR(groundPt.y, 0, 1e-8);
Expand All @@ -73,31 +95,106 @@ TEST_F(FrameSensorModel, SlightlyOffCenter) {

//Test all four corners:
TEST_F(FrameSensorModel, OffBody1) {
csm::ImageCoord imagePt(14.5, -0.5);
csm::ImageCoord imagePt(15.0, 0.0);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 0.44979759, 1e-8);
EXPECT_NEAR(groundPt.y, -14.99325304, 1e-8);
EXPECT_NEAR(groundPt.z, 14.99325304, 1e-8);
}
TEST_F(FrameSensorModel, OffBody2) {
csm::ImageCoord imagePt(-0.5, 14.5);
csm::ImageCoord imagePt(0.0, 15.0);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 0.44979759, 1e-8);
EXPECT_NEAR(groundPt.y, 14.99325304, 1e-8);
EXPECT_NEAR(groundPt.z, -14.99325304, 1e-8);
}
TEST_F(FrameSensorModel, OffBody3) {
csm::ImageCoord imagePt(-0.5, -0.5);
csm::ImageCoord imagePt(0.0, 0.0);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 0.44979759, 1e-8);
EXPECT_NEAR(groundPt.y, 14.99325304, 1e-8);
EXPECT_NEAR(groundPt.z, 14.99325304, 1e-8);
}
TEST_F(FrameSensorModel, OffBody4) {
csm::ImageCoord imagePt(14.5, 14.5);
csm::ImageCoord imagePt(15.0, 15.0);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 0.44979759, 1e-8);
EXPECT_NEAR(groundPt.y, -14.99325304, 1e-8);
EXPECT_NEAR(groundPt.z, -14.99325304, 1e-8);
}


// Focal Length Tests:
TEST_F(FrameIsdTest, FL500_OffBody4) {
isd.clearParams("focal_length");
isd.addParam("focal_length","500.0");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This super nit picky. Can we use a single variable for the key? std::string key = "focal_length"? This will make refactoring later easier and is better form I think to help maintain these.

UsgsAstroFramePlugin frameCameraPlugin;

csm::Model *model = frameCameraPlugin.constructModelFromISD(
isd,
"USGS_ASTRO_FRAME_SENSOR_MODEL");

UsgsAstroFrameSensorModel* sensorModel = dynamic_cast<UsgsAstroFrameSensorModel *>(model);

ASSERT_NE(sensorModel, nullptr);
csm::ImageCoord imagePt(15.0, 15.0);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 9.77688917, 1e-8);
EXPECT_NEAR(groundPt.y, -1.48533467, 1e-8);
EXPECT_NEAR(groundPt.z, -1.48533467, 1e-8);
}
TEST_F(FrameIsdTest, FL500_OffBody3) {
isd.clearParams("focal_length");
isd.addParam("focal_length","500.0");
UsgsAstroFramePlugin frameCameraPlugin;

csm::Model *model = frameCameraPlugin.constructModelFromISD(
isd,
"USGS_ASTRO_FRAME_SENSOR_MODEL");

UsgsAstroFrameSensorModel* sensorModel = dynamic_cast<UsgsAstroFrameSensorModel *>(model);

ASSERT_NE(sensorModel, nullptr);
csm::ImageCoord imagePt(0.0, 0.0);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 9.77688917, 1e-8);
EXPECT_NEAR(groundPt.y, 1.48533467, 1e-8);
EXPECT_NEAR(groundPt.z, 1.48533467, 1e-8);
}
TEST_F(FrameIsdTest, FL500_Center) {
isd.clearParams("focal_length");
isd.addParam("focal_length","500.0");
UsgsAstroFramePlugin frameCameraPlugin;

csm::Model *model = frameCameraPlugin.constructModelFromISD(
isd,
"USGS_ASTRO_FRAME_SENSOR_MODEL");

UsgsAstroFrameSensorModel* sensorModel = dynamic_cast<UsgsAstroFrameSensorModel *>(model);

Copy link
Collaborator

Choose a reason for hiding this comment

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

All these repeated instantiations look good. We can refactor out once parameterized tests are working the way we want them to.

ASSERT_NE(sensorModel, nullptr);
csm::ImageCoord imagePt(7.5, 7.5);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 10.0, 1e-8);
EXPECT_NEAR(groundPt.y, 0.0, 1e-8);
EXPECT_NEAR(groundPt.z, 0.0, 1e-8);
}
TEST_F(FrameIsdTest, FL500_SlightlyOffCenter) {
isd.clearParams("focal_length");
isd.addParam("focal_length","500.0");
UsgsAstroFramePlugin frameCameraPlugin;

csm::Model *model = frameCameraPlugin.constructModelFromISD(
isd,
"USGS_ASTRO_FRAME_SENSOR_MODEL");

UsgsAstroFrameSensorModel* sensorModel = dynamic_cast<UsgsAstroFrameSensorModel *>(model);

ASSERT_NE(sensorModel, nullptr);
csm::ImageCoord imagePt(7.5, 6.5);
csm::EcefCoord groundPt = sensorModel->imageToGround(imagePt, 0.0);
EXPECT_NEAR(groundPt.x, 9.99803960, 1e-8);
EXPECT_NEAR(groundPt.y, 0.0, 1e-8);
EXPECT_NEAR(groundPt.z, 1.98000392e-01, 1e-8);

}