From 975f05996a5585058999bb539087cdfb903e8fe3 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Thu, 8 Oct 2020 09:46:14 -0700 Subject: [PATCH 01/10] first run at apollofindrx tests --- .../apollo/apps/apollofindrx/apollofindrx.cpp | 283 ++++++++++++++++++ .../apollo/apps/apollofindrx/apollofindrx.h | 12 + isis/src/apollo/apps/apollofindrx/main.cpp | 277 +---------------- isis/tests/FunctionalTestsApolloFindRx.cpp | 77 +++++ 4 files changed, 378 insertions(+), 271 deletions(-) create mode 100644 isis/src/apollo/apps/apollofindrx/apollofindrx.cpp create mode 100644 isis/src/apollo/apps/apollofindrx/apollofindrx.h create mode 100644 isis/tests/FunctionalTestsApolloFindRx.cpp diff --git a/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp new file mode 100644 index 0000000000..9513d29937 --- /dev/null +++ b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp @@ -0,0 +1,283 @@ +#include "PvlGroup.h" +#include "UserInterface.h" +#include "Cube.h" +#include "Chip.h" +#include "PolynomialBivariate.h" +#include "LeastSquares.h" +#include "Progress.h" +#include "IException.h" +#include "Apollo.h" +#include "History.h" + +#include "apollofindrx.h" + +using namespace std; + +namespace Isis { + + int MAX_DISPX = 10, + MAX_DISPY = 10, + MIN_DISP = 10; + + bool Walk(); + double Register(); + void Refine(); + + double tolerance = 0.0; + + Chip chip, subChip, fitChip; + + double bestSample = 0.0, + bestLine = 0.0; + + double GoodnessOfFit = 1.0; + + void apollofindrx(UserInterface &ui) { + Cube *cube = new Cube(ui.GetFileName("FROM"), "rw"); + std::cout << cube->fileName() << std::endl; + apollofindrx(cube, ui); + } + + void apollofindrx(Cube *cube, UserInterface &ui) { + std::cout << "I'm, in" << std::endl; + // Import cube data & PVL information + + tolerance = ui.GetDouble("TOLERANCE"); + int patternSize = ui.GetInteger("PATTERNSIZE"); + MAX_DISPX = ui.GetInteger("DELTAX"); + MAX_DISPY = ui.GetInteger("DELTAY"); + + PvlGroup &reseaus = cube->label()->findGroup("Reseaus",Pvl::Traverse); + QString mission = (cube->label()->findGroup("Instrument",Pvl::Traverse))["SpacecraftName"]; + QString instrument = (cube->label()->findGroup("Instrument",Pvl::Traverse))["InstrumentId"]; + Apollo apollo(mission, instrument); + if (mission.mid(0,6) != "APOLLO") { + QString msg = "This application is for use with Apollo spacecrafts only."; + throw IException(IException::Unknown, msg, _FILEINFO_); + } + + // If the Keyword sizes don't match up, throw errors. + int nres = reseaus["Line"].size(); + if (nres != reseaus["Sample"].size()) { + QString msg = "Sample size incorrect [Sample size " + + toString(reseaus["Sample"].size()) + " != " + " Line size " + + toString(reseaus["Line"].size()) + "]"; + throw IException(IException::Unknown, msg, _FILEINFO_); + } + if (nres != reseaus["Type"].size()) { + QString msg = "Type size incorrect [Type size " + + toString(reseaus["Type"].size()) + " != " + " Line size " + + toString(reseaus["Line"].size()) + "]"; + throw IException(IException::Unknown, msg, _FILEINFO_); + } + if (nres != reseaus["Valid"].size()) { + QString msg = "Valid size incorrect [Valid size " + + toString(reseaus["Valid"].size()) + " != " + " Line size " + + toString(reseaus["Line"].size()) + "]"; + throw IException(IException::Unknown, msg, _FILEINFO_); + } + + // Display the progress + Progress prog; + prog.SetMaximumSteps(nres); + prog.CheckStatus(); + + PolynomialBivariate sampPoly(1), + linePoly(1); + LeastSquares sampFunc(sampPoly), + lineFunc(linePoly); + + // Find the first good reseau (the first reseau within tolerance) + // then use it and the label data to + int ds = MAX_DISPX, + dl = MAX_DISPY; + + subChip.SetSize(patternSize, patternSize); + + int currentSample = 0 , + currentLine = 0; + int dim = (int)sqrt(nres); + int validReseaus = 0; + // for (int res=0; res 0 && reseaus["Valid"][res-1] == "1") dy = currentLine - patternSize/2 - dl + bestLine-1 - toDouble(reseaus["Line"][res]); + if (res/dim > 0 && reseaus["Valid"][res - dim] == "1") dx = currentSample - patternSize/2 - ds + bestSample-1 - toDouble(reseaus["Sample"][res]); + double horizontalShift = currentSample - patternSize/2 - ds + bestSample-1 - toDouble(reseaus["Sample"][res]) - dx, + verticalShift = currentLine - patternSize/2 - dl + bestLine-1 - toDouble(reseaus["Line"][res]) - dy; + for (int i=res; i xy; + xy.push_back(res%(int)sqrt(nres)); + xy.push_back(res/(int)sqrt(nres)); + sampFunc.AddKnown(xy, toDouble(reseaus["Sample"][res])); + lineFunc.AddKnown(xy, toDouble(reseaus["Line"][res])); + + ds = (int)(MIN_DISP+ abs(dx) + abs(horizontalShift)); + dl = (int)(MIN_DISP + abs(dy) + abs(verticalShift)); + } + else { + reseaus["Valid"][res] = "0"; + } + + prog.CheckStatus(); + } + + if (validReseaus > 2) { + sampFunc.Solve(); + lineFunc.Solve(); + + // for invalid reseaus, refine the estimated locations + for (int res=0; res xy; + xy.push_back(res%(int)sqrt(nres)); + xy.push_back(res/(int)sqrt(nres)); + reseaus["Sample"][res] = toString(sampFunc.Evaluate(xy)); + reseaus["Line"][res] = toString(lineFunc.Evaluate(xy)); + } + } + + // Change status to "Refined", corrected! + reseaus["Status"] = "Refined"; + } + else { + QString msg = "No Reseaus located. Labels will not be changed."; + msg += "Try changing the registration parameters."; + throw IException(IException::Unknown, msg, _FILEINFO_); + } + + // Record apollofindrx history to the cube + // create a History Blob with value found in the History PvlObject's Name keyword + PvlObject &histObj = cube->label()->findObject("History"); + Isis::History histBlob( (QString)histObj["Name"] ); + // read cube's History PvlObject data into the History Blob + cube->read(histBlob); + // add apollofindrx History PvlObject into the History Blob and write to cube + histBlob.AddEntry(); + cube->write(histBlob); + cube->close(); + } + + bool Walk() { + // create a chip to store registration values + fitChip.TackCube(chip.TackSample(), chip.TackLine()); + fitChip.SetSize(chip.Samples(), chip.Lines()); + + double bestFit = Isis::Null; + for (int s = (subChip.Samples()+1)/2; s <= chip.Samples()-(subChip.Samples()+1)/2+1; s++) { + for (int l = (subChip.Lines()+1)/2; l <= chip.Lines()-(subChip.Lines()+1)/2+1; l++) { + subChip = chip.Extract(subChip.Samples(), subChip.Lines(), s, l); + double fit = Register(); + if (fit !=Isis::Null && (bestFit == Isis::Null || fit < bestFit)) { + bestSample = s; + bestLine = l; + bestFit = fit; + } + fitChip.SetValue(s, l, fit); + } + } + + if (bestFit == Isis::Null || bestFit > tolerance) return false; + + GoodnessOfFit = bestFit; + Refine(); + return true; + } + + // Refine the registration results to sub-pixel accuracy + // if it does not work, keep old results + void Refine() { + // if the best fit is on an edge, it cannot be refined + if (bestSample==1 || bestLine ==1 || bestSample==fitChip.Samples() || bestLine==fitChip.Lines()) return; + + PolynomialBivariate p(2); + LeastSquares lsq(p); + for (int i=-1; i<=1; i++) { + for (int j=-1; j<=1; j++) { + int x = (int)(bestSample+i), + y = (int)(bestLine + j); + if (fitChip.GetValue(x, y) == Isis::Null) continue; + std::vector xy; + xy.push_back(x); + xy.push_back(y); + lsq.AddKnown(xy, fitChip.GetValue(x, y) ); + } + } + try { + lsq.Solve(); + } catch (IException &) { + return; + } + + // Get coefficients (don't need a) + double b = p.Coefficient(1); + double c = p.Coefficient(2); + double d = p.Coefficient(3); + double e = p.Coefficient(4); + double f = p.Coefficient(5); + + // Compute the determinant + double det = 4.0*d*f - e*e; + if (det == 0.0) return; + + // Compute our chip position to sub-pixel accuracy + double refinedSample = (c*e - 2.0*b*f) / det; + double refinedLine = (b*e - 2.0*c*d) / det; + if ( abs(bestSample-refinedSample) < 1 && abs(bestLine-refinedLine) < 1 ) { + bestSample = refinedSample; + bestLine = refinedLine; + } + + return; + } + + double Register() { + double sum = 0.0; + int count = 0; + + for (int l=1; l<=subChip.Lines(); l++) { + double min = DBL_MAX, + max = DBL_MIN; + for (int i=-2; i<=2; i++) { + double dn = subChip.GetValue( (subChip.Samples()+1)/2+i, (int)l ); + if (dn < min) min = dn; + if (dn > max) max = dn; + } + if (max == min) continue; + sum += (subChip.GetValue( (subChip.Samples()+1)/2, (int)l) - min)/(max - min); + count++; + } + + for (int s=1; s<=subChip.Samples(); s++) { + double min = DBL_MAX, + max = DBL_MIN; + for (int i=-2; i<=2; i++) { + double dn = subChip.GetValue( (int)s, (subChip.Lines()+1)/2+i ); + if (dn < min) min = dn; + if (dn > max) max = dn; + } + if (max == min) continue; + sum += (subChip.GetValue( (int)s, (subChip.Lines()+1)/2 ) - min)/(max - min); + count++; + } + + if (count < 1) return Isis::Null; + return sum/count; + } +} \ No newline at end of file diff --git a/isis/src/apollo/apps/apollofindrx/apollofindrx.h b/isis/src/apollo/apps/apollofindrx/apollofindrx.h new file mode 100644 index 0000000000..73463b13e2 --- /dev/null +++ b/isis/src/apollo/apps/apollofindrx/apollofindrx.h @@ -0,0 +1,12 @@ +#ifndef apollofindrx_h // Change this to your app name in all lower case suffixed with _h (e.g. campt_h, cam2map_h etc.) +#define apollofindrx_h + +#include "Cube.h" +#include "UserInterface.h" + +namespace Isis{ + extern void apollofindrx(Cube *cube, UserInterface &ui); + extern void apollofindrx(UserInterface &ui); +} + +#endif \ No newline at end of file diff --git a/isis/src/apollo/apps/apollofindrx/main.cpp b/isis/src/apollo/apps/apollofindrx/main.cpp index 7300029fdf..967510cae4 100644 --- a/isis/src/apollo/apps/apollofindrx/main.cpp +++ b/isis/src/apollo/apps/apollofindrx/main.cpp @@ -1,276 +1,11 @@ #include "Isis.h" -#include "PvlGroup.h" -#include "UserInterface.h" -#include "Cube.h" -#include "Chip.h" -#include "PolynomialBivariate.h" -#include "LeastSquares.h" -#include "Progress.h" -#include "IException.h" -#include "Apollo.h" -#include "History.h" -using namespace std; -using namespace Isis; - -int MAX_DISPX = 10, - MAX_DISPY = 10, - MIN_DISP = 10; - -bool Walk(); -double Register(); -void Refine(); - -double tolerance = 0.0; - -Chip chip, subChip, fitChip; - -double bestSample = 0.0, - bestLine = 0.0; - -double GoodnessOfFit = 1.0; - -void IsisMain () -{ - // Import cube data & PVL information - Cube cube; - UserInterface &ui = Application::GetUserInterface(); - tolerance = ui.GetDouble("TOLERANCE"); - int patternSize = ui.GetInteger("PATTERNSIZE"); - MAX_DISPX = ui.GetInteger("DELTAX"); - MAX_DISPY = ui.GetInteger("DELTAY"); - cube.open(ui.GetFileName("FROM"),"rw"); - - PvlGroup &reseaus = cube.label()->findGroup("Reseaus",Pvl::Traverse); - QString mission = (cube.label()->findGroup("Instrument",Pvl::Traverse))["SpacecraftName"]; - QString instrument = (cube.label()->findGroup("Instrument",Pvl::Traverse))["InstrumentId"]; - Apollo apollo(mission, instrument); - if (mission.mid(0,6) != "APOLLO") { - QString msg = "This application is for use with Apollo spacecrafts only."; - throw IException(IException::Unknown, msg, _FILEINFO_); - } - - // If the Keyword sizes don't match up, throw errors. - int nres = reseaus["Line"].size(); - if (nres != reseaus["Sample"].size()) { - QString msg = "Sample size incorrect [Sample size " + - toString(reseaus["Sample"].size()) + " != " + " Line size " + - toString(reseaus["Line"].size()) + "]"; - throw IException(IException::Unknown, msg, _FILEINFO_); - } - if (nres != reseaus["Type"].size()) { - QString msg = "Type size incorrect [Type size " + - toString(reseaus["Type"].size()) + " != " + " Line size " + - toString(reseaus["Line"].size()) + "]"; - throw IException(IException::Unknown, msg, _FILEINFO_); - } - if (nres != reseaus["Valid"].size()) { - QString msg = "Valid size incorrect [Valid size " + - toString(reseaus["Valid"].size()) + " != " + " Line size " + - toString(reseaus["Line"].size()) + "]"; - throw IException(IException::Unknown, msg, _FILEINFO_); - } - - // Display the progress - Progress prog; - prog.SetMaximumSteps(nres); - prog.CheckStatus(); - - PolynomialBivariate sampPoly(1), - linePoly(1); - LeastSquares sampFunc(sampPoly), - lineFunc(linePoly); - - // Find the first good reseau (the first reseau within tolerance) - // then use it and the label data to - int ds = MAX_DISPX, - dl = MAX_DISPY; - - subChip.SetSize(patternSize, patternSize); - - int currentSample = 0 , - currentLine = 0; - int dim = (int)sqrt(nres); - int validReseaus = 0; - // for (int res=0; res 0 && reseaus["Valid"][res-1] == "1") dy = currentLine - patternSize/2 - dl + bestLine-1 - toDouble(reseaus["Line"][res]); - if (res/dim > 0 && reseaus["Valid"][res - dim] == "1") dx = currentSample - patternSize/2 - ds + bestSample-1 - toDouble(reseaus["Sample"][res]); - double horizontalShift = currentSample - patternSize/2 - ds + bestSample-1 - toDouble(reseaus["Sample"][res]) - dx, - verticalShift = currentLine - patternSize/2 - dl + bestLine-1 - toDouble(reseaus["Line"][res]) - dy; - for (int i=res; i xy; - xy.push_back(res%(int)sqrt(nres)); - xy.push_back(res/(int)sqrt(nres)); - sampFunc.AddKnown(xy, toDouble(reseaus["Sample"][res])); - lineFunc.AddKnown(xy, toDouble(reseaus["Line"][res])); - - ds = (int)(MIN_DISP+ abs(dx) + abs(horizontalShift)); - dl = (int)(MIN_DISP + abs(dy) + abs(verticalShift)); - } - else { - reseaus["Valid"][res] = "0"; - } - - prog.CheckStatus(); - } +#include "Application.h" +#include "apollofindrx.h" - if (validReseaus > 2) { - sampFunc.Solve(); - lineFunc.Solve(); - - // for invalid reseaus, refine the estimated locations - for (int res=0; res xy; - xy.push_back(res%(int)sqrt(nres)); - xy.push_back(res/(int)sqrt(nres)); - reseaus["Sample"][res] = toString(sampFunc.Evaluate(xy)); - reseaus["Line"][res] = toString(lineFunc.Evaluate(xy)); - } - } - - // Change status to "Refined", corrected! - reseaus["Status"] = "Refined"; - } - else { - QString msg = "No Reseaus located. Labels will not be changed."; - msg += "Try changing the registration parameters."; - throw IException(IException::Unknown, msg, _FILEINFO_); - } - - // Record apollofindrx history to the cube - // create a History Blob with value found in the History PvlObject's Name keyword - PvlObject &histObj = cube.label()->findObject("History"); - Isis::History histBlob( (QString)histObj["Name"] ); - // read cube's History PvlObject data into the History Blob - cube.read(histBlob); - // add apollofindrx History PvlObject into the History Blob and write to cube - histBlob.AddEntry(); - cube.write(histBlob); - cube.close(); -} - -bool Walk() { - // create a chip to store registration values - fitChip.TackCube(chip.TackSample(), chip.TackLine()); - fitChip.SetSize(chip.Samples(), chip.Lines()); - - double bestFit = Isis::Null; - for (int s = (subChip.Samples()+1)/2; s <= chip.Samples()-(subChip.Samples()+1)/2+1; s++) { - for (int l = (subChip.Lines()+1)/2; l <= chip.Lines()-(subChip.Lines()+1)/2+1; l++) { - subChip = chip.Extract(subChip.Samples(), subChip.Lines(), s, l); - double fit = Register(); - if (fit !=Isis::Null && (bestFit == Isis::Null || fit < bestFit)) { - bestSample = s; - bestLine = l; - bestFit = fit; - } - fitChip.SetValue(s, l, fit); - } - } - - if (bestFit == Isis::Null || bestFit > tolerance) return false; - - GoodnessOfFit = bestFit; - Refine(); - return true; -} - -// Refine the registration results to sub-pixel accuracy -// if it does not work, keep old results -void Refine() { - // if the best fit is on an edge, it cannot be refined - if (bestSample==1 || bestLine ==1 || bestSample==fitChip.Samples() || bestLine==fitChip.Lines()) return; - - PolynomialBivariate p(2); - LeastSquares lsq(p); - for (int i=-1; i<=1; i++) { - for (int j=-1; j<=1; j++) { - int x = (int)(bestSample+i), - y = (int)(bestLine + j); - if (fitChip.GetValue(x, y) == Isis::Null) continue; - std::vector xy; - xy.push_back(x); - xy.push_back(y); - lsq.AddKnown(xy, fitChip.GetValue(x, y) ); - } - } - try { - lsq.Solve(); - } catch (IException &) { - return; - } - - // Get coefficients (don't need a) - double b = p.Coefficient(1); - double c = p.Coefficient(2); - double d = p.Coefficient(3); - double e = p.Coefficient(4); - double f = p.Coefficient(5); - - // Compute the determinant - double det = 4.0*d*f - e*e; - if (det == 0.0) return; - // Compute our chip position to sub-pixel accuracy - double refinedSample = (c*e - 2.0*b*f) / det; - double refinedLine = (b*e - 2.0*c*d) / det; - if ( abs(bestSample-refinedSample) < 1 && abs(bestLine-refinedLine) < 1 ) { - bestSample = refinedSample; - bestLine = refinedLine; - } - - return; -} - -double Register() { - double sum = 0.0; - int count = 0; - - for (int l=1; l<=subChip.Lines(); l++) { - double min = DBL_MAX, - max = DBL_MIN; - for (int i=-2; i<=2; i++) { - double dn = subChip.GetValue( (subChip.Samples()+1)/2+i, (int)l ); - if (dn < min) min = dn; - if (dn > max) max = dn; - } - if (max == min) continue; - sum += (subChip.GetValue( (subChip.Samples()+1)/2, (int)l) - min)/(max - min); - count++; - } - - for (int s=1; s<=subChip.Samples(); s++) { - double min = DBL_MAX, - max = DBL_MIN; - for (int i=-2; i<=2; i++) { - double dn = subChip.GetValue( (int)s, (subChip.Lines()+1)/2+i ); - if (dn < min) min = dn; - if (dn > max) max = dn; - } - if (max == min) continue; - sum += (subChip.GetValue( (int)s, (subChip.Lines()+1)/2 ) - min)/(max - min); - count++; - } +using namespace Isis; - if (count < 1) return Isis::Null; - return sum/count; +void IsisMain() { + UserInterface &ui = Application::GetUserInterface(); + apollofindrx(ui); } diff --git a/isis/tests/FunctionalTestsApolloFindRx.cpp b/isis/tests/FunctionalTestsApolloFindRx.cpp new file mode 100644 index 0000000000..bf7dcc5d30 --- /dev/null +++ b/isis/tests/FunctionalTestsApolloFindRx.cpp @@ -0,0 +1,77 @@ +#include "Fixtures.h" +#include "Pvl.h" +#include "PvlGroup.h" +#include "TestUtilities.h" + +#include "apollofindrx.h" + +#include "gtest/gtest.h" + +using namespace Isis; + +static QString APP_XML = FileName("$ISISROOT/bin/xml/apollofindrx.xml").expanded(); + +TEST_F(SmallCube, FunctionalTestApolloFineRxDefault) { + PvlGroup reseaus("Reseaus"); + PvlKeyword samples = PvlKeyword("Sample", "2"); + samples += "4"; + samples += "6"; + samples += "8"; + + PvlKeyword lines = PvlKeyword("Line", "2"); + lines += "4"; + lines += "6"; + lines += "8"; + + PvlKeyword types = PvlKeyword("Type", "5"); + types += "5"; + types += "5"; + types += "5"; + + PvlKeyword valid = PvlKeyword("Valid", "1"); + valid += "1"; + valid += "1"; + valid += "1"; + + reseaus += lines; + reseaus += samples; + reseaus += types; + reseaus += valid; + reseaus += PvlKeyword("Status", "Nominal"); + + std::istringstream instStr (R"( + Group = Instrument + SpacecraftName = "APOLLO 15" + InstrumentId = METRIC + TargetName = MOON + StartTime = 1971-08-01T14:58:03.78 + End_Group + )"); + + PvlGroup instGroup; + instStr >> instGroup; + + Pvl *lab = testCube->label(); + lab->findObject("IsisCube").addGroup(reseaus); + lab->findObject("IsisCube").addGroup(instGroup); + + PvlGroup &inst = testCube->label()->findObject("IsisCube").findGroup("Instrument"); + inst.findKeyword("SpacecraftName").setValue("APOLLO 15"); + inst.findKeyword("InstrumentId").setValue("METRIC"); + + std::cout << *lab << std::endl; + + QTemporaryDir prefix; + QString outCubeFileName = prefix.path() + "/outTemp.cub"; + QVector args = {"to="+outCubeFileName, "tolerance=0.125"}; + + UserInterface options(APP_XML, args); + try { + apollofindrx(testCube, options); + } + catch (IException &e) { + FAIL() << "Call failed, Unable to process cube: " << e.what() << std::endl; + } + + // Assert some stuff +} \ No newline at end of file From 3363395cef42c8404c1aec9a5025cd7e904e98ce Mon Sep 17 00:00:00 2001 From: Kelvin Date: Thu, 8 Oct 2020 18:38:36 -0700 Subject: [PATCH 02/10] tests updated --- .../apollo/apps/apollofindrx/apollofindrx.cpp | 24 +++++++-------- isis/tests/FunctionalTestsApolloFindRx.cpp | 30 +++++++++++++++---- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp index 9513d29937..29dd8bbea7 100644 --- a/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp +++ b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp @@ -34,12 +34,10 @@ namespace Isis { void apollofindrx(UserInterface &ui) { Cube *cube = new Cube(ui.GetFileName("FROM"), "rw"); - std::cout << cube->fileName() << std::endl; apollofindrx(cube, ui); } void apollofindrx(Cube *cube, UserInterface &ui) { - std::cout << "I'm, in" << std::endl; // Import cube data & PVL information tolerance = ui.GetDouble("TOLERANCE"); @@ -162,16 +160,18 @@ namespace Isis { throw IException(IException::Unknown, msg, _FILEINFO_); } - // Record apollofindrx history to the cube - // create a History Blob with value found in the History PvlObject's Name keyword - PvlObject &histObj = cube->label()->findObject("History"); - Isis::History histBlob( (QString)histObj["Name"] ); - // read cube's History PvlObject data into the History Blob - cube->read(histBlob); - // add apollofindrx History PvlObject into the History Blob and write to cube - histBlob.AddEntry(); - cube->write(histBlob); - cube->close(); + if (cube->label()->hasObject("History")) { + PvlObject histObj = cube->label()->findObject("History"); + // Record apollofindrx history to the cube + // create a History Blob with value found in the History PvlObject's Name keyword + Isis::History histBlob( (QString)histObj["Name"] ); + // read cube's History PvlObject data into the History Blob + cube->read(histBlob); + // add apollofindrx History PvlObject into the History Blob and write to cube + histBlob.AddEntry(); + cube->write(histBlob); + cube->close(); + } } bool Walk() { diff --git a/isis/tests/FunctionalTestsApolloFindRx.cpp b/isis/tests/FunctionalTestsApolloFindRx.cpp index bf7dcc5d30..301e022b61 100644 --- a/isis/tests/FunctionalTestsApolloFindRx.cpp +++ b/isis/tests/FunctionalTestsApolloFindRx.cpp @@ -11,7 +11,7 @@ using namespace Isis; static QString APP_XML = FileName("$ISISROOT/bin/xml/apollofindrx.xml").expanded(); -TEST_F(SmallCube, FunctionalTestApolloFineRxDefault) { +TEST_F(SmallCube, FunctionalTestApolloFindRxDefault) { PvlGroup reseaus("Reseaus"); PvlKeyword samples = PvlKeyword("Sample", "2"); samples += "4"; @@ -59,11 +59,8 @@ TEST_F(SmallCube, FunctionalTestApolloFineRxDefault) { inst.findKeyword("SpacecraftName").setValue("APOLLO 15"); inst.findKeyword("InstrumentId").setValue("METRIC"); - std::cout << *lab << std::endl; - QTemporaryDir prefix; - QString outCubeFileName = prefix.path() + "/outTemp.cub"; - QVector args = {"to="+outCubeFileName, "tolerance=0.125"}; + QVector args = {"tolerance=0.125"}; UserInterface options(APP_XML, args); try { @@ -72,6 +69,29 @@ TEST_F(SmallCube, FunctionalTestApolloFineRxDefault) { catch (IException &e) { FAIL() << "Call failed, Unable to process cube: " << e.what() << std::endl; } + + Pvl newLab = *testCube->label(); + + PvlGroup newReseaus = newLab.findObject("IsisCube").findGroup("Reseaus"); + PvlKeyword testKeyword = newReseaus.findKeyword("Line"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[0], "-98.0"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[1], "-205.0"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[2], "-212.0"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[3], "-446.0"); + + testKeyword = newReseaus.findKeyword("Sample"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[0], "-98.0"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[1], "-205.0"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[2], "-321.0"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[3], "-446.0"); + testKeyword = newReseaus.findKeyword("Valid"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[0], "1"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[1], "1"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[2], "1"); + EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[3], "1"); + + EXPECT_PRED_FORMAT2(AssertQStringsEqual, newReseaus.findKeyword("Status"), "Refined"); + // Assert some stuff } \ No newline at end of file From bbe30705984b7d6be37732da369527db80321ab0 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Thu, 8 Oct 2020 18:47:27 -0700 Subject: [PATCH 03/10] removed old tests --- isis/src/apollo/apps/apollofindrx/tsts/Makefile | 4 ---- .../apollo/apps/apollofindrx/tsts/default/Makefile | 11 ----------- 2 files changed, 15 deletions(-) delete mode 100644 isis/src/apollo/apps/apollofindrx/tsts/Makefile delete mode 100644 isis/src/apollo/apps/apollofindrx/tsts/default/Makefile diff --git a/isis/src/apollo/apps/apollofindrx/tsts/Makefile b/isis/src/apollo/apps/apollofindrx/tsts/Makefile deleted file mode 100644 index 46d84c74c2..0000000000 --- a/isis/src/apollo/apps/apollofindrx/tsts/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -BLANKS = "%-6s" -LENGTH = "%-40s" - -include $(ISISROOT)/make/isismake.tststree diff --git a/isis/src/apollo/apps/apollofindrx/tsts/default/Makefile b/isis/src/apollo/apps/apollofindrx/tsts/default/Makefile deleted file mode 100644 index 6a7bea91ab..0000000000 --- a/isis/src/apollo/apps/apollofindrx/tsts/default/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -APPNAME = apollofindrx - -include $(ISISROOT)/make/isismake.tsts - -commands: - cp $(INPUT)/AS15-M-1450.cub $(OUTPUT)/AS15-M-1450.cub > /dev/null; - apollofindrx from=$(OUTPUT)/AS15-M-1450.cub > /dev/null; - catlab from=$(OUTPUT)/AS15-M-1450.cub \ - to=$(OUTPUT)/AS15-M-1450.pvl > /dev/null; - cathist from=$(OUTPUT)/AS15-M-1450.cub \ - to=$(OUTPUT)/histTruth.pvl > /dev/null; From 635daf94aee0b5a34378a941749536de7904699f Mon Sep 17 00:00:00 2001 From: Stuart Sides Date: Thu, 8 Oct 2020 20:49:50 -0700 Subject: [PATCH 04/10] Update FunctionalTestsApolloFindRx.cpp --- isis/tests/FunctionalTestsApolloFindRx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isis/tests/FunctionalTestsApolloFindRx.cpp b/isis/tests/FunctionalTestsApolloFindRx.cpp index 301e022b61..36a89780c4 100644 --- a/isis/tests/FunctionalTestsApolloFindRx.cpp +++ b/isis/tests/FunctionalTestsApolloFindRx.cpp @@ -94,4 +94,4 @@ TEST_F(SmallCube, FunctionalTestApolloFindRxDefault) { EXPECT_PRED_FORMAT2(AssertQStringsEqual, newReseaus.findKeyword("Status"), "Refined"); // Assert some stuff -} \ No newline at end of file +} From b92c72afda592d4fa65ce7e6b0828fbdba92cef3 Mon Sep 17 00:00:00 2001 From: Stuart Sides Date: Thu, 8 Oct 2020 20:50:15 -0700 Subject: [PATCH 05/10] Update apollofindrx.cpp --- isis/src/apollo/apps/apollofindrx/apollofindrx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp index 29dd8bbea7..269848d7f5 100644 --- a/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp +++ b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp @@ -280,4 +280,4 @@ namespace Isis { if (count < 1) return Isis::Null; return sum/count; } -} \ No newline at end of file +} From f593d44df51655b8a7dd655e8945624ba22d4bc1 Mon Sep 17 00:00:00 2001 From: Stuart Sides Date: Thu, 8 Oct 2020 20:50:33 -0700 Subject: [PATCH 06/10] Update apollofindrx.h --- isis/src/apollo/apps/apollofindrx/apollofindrx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isis/src/apollo/apps/apollofindrx/apollofindrx.h b/isis/src/apollo/apps/apollofindrx/apollofindrx.h index 73463b13e2..ca4a7dc11d 100644 --- a/isis/src/apollo/apps/apollofindrx/apollofindrx.h +++ b/isis/src/apollo/apps/apollofindrx/apollofindrx.h @@ -9,4 +9,4 @@ namespace Isis{ extern void apollofindrx(UserInterface &ui); } -#endif \ No newline at end of file +#endif From a1fab1804635dbae485a1cd0dfe451182a854a78 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Fri, 9 Oct 2020 07:22:18 -0700 Subject: [PATCH 07/10] changes from comments --- isis/src/apollo/apps/apollofindrx/apollofindrx.h | 2 +- isis/tests/FunctionalTestsApolloFindRx.cpp | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/isis/src/apollo/apps/apollofindrx/apollofindrx.h b/isis/src/apollo/apps/apollofindrx/apollofindrx.h index 73463b13e2..cb0dca9cf3 100644 --- a/isis/src/apollo/apps/apollofindrx/apollofindrx.h +++ b/isis/src/apollo/apps/apollofindrx/apollofindrx.h @@ -1,4 +1,4 @@ -#ifndef apollofindrx_h // Change this to your app name in all lower case suffixed with _h (e.g. campt_h, cam2map_h etc.) +#ifndef apollofindrx_h #define apollofindrx_h #include "Cube.h" diff --git a/isis/tests/FunctionalTestsApolloFindRx.cpp b/isis/tests/FunctionalTestsApolloFindRx.cpp index 301e022b61..48538340c9 100644 --- a/isis/tests/FunctionalTestsApolloFindRx.cpp +++ b/isis/tests/FunctionalTestsApolloFindRx.cpp @@ -55,10 +55,6 @@ TEST_F(SmallCube, FunctionalTestApolloFindRxDefault) { lab->findObject("IsisCube").addGroup(reseaus); lab->findObject("IsisCube").addGroup(instGroup); - PvlGroup &inst = testCube->label()->findObject("IsisCube").findGroup("Instrument"); - inst.findKeyword("SpacecraftName").setValue("APOLLO 15"); - inst.findKeyword("InstrumentId").setValue("METRIC"); - QTemporaryDir prefix; QVector args = {"tolerance=0.125"}; From eccc186bc383bdbf5b637e735f460f6bce7240b1 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Fri, 16 Oct 2020 14:10:28 -0700 Subject: [PATCH 08/10] updated tests with bigger cube --- .../apollo/apps/apollofindrx/apollofindrx.cpp | 2 +- isis/tests/Fixtures.cpp | 33 +++++++++++- isis/tests/Fixtures.h | 10 ++++ isis/tests/FunctionalTestsApolloFindRx.cpp | 53 ++++++++++--------- 4 files changed, 71 insertions(+), 27 deletions(-) diff --git a/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp index 269848d7f5..0cd32b225c 100644 --- a/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp +++ b/isis/src/apollo/apps/apollofindrx/apollofindrx.cpp @@ -192,7 +192,7 @@ namespace Isis { fitChip.SetValue(s, l, fit); } } - + if (bestFit == Isis::Null || bestFit > tolerance) return false; GoodnessOfFit = bestFit; diff --git a/isis/tests/Fixtures.cpp b/isis/tests/Fixtures.cpp index 01992b846a..0379805ec0 100644 --- a/isis/tests/Fixtures.cpp +++ b/isis/tests/Fixtures.cpp @@ -13,7 +13,7 @@ namespace Isis { TempTestingFiles::SetUp(); testCube = new Cube(); - testCube->setDimensions(10, 10, 10); + testCube->setDimensions(100, 100, 10); testCube->create(tempDir.path() + "/small.cub"); LineManager line(*testCube); @@ -37,6 +37,37 @@ namespace Isis { } } + + void LargeCube::SetUp() { + TempTestingFiles::SetUp(); + + testCube = new Cube(); + testCube->setDimensions(1000, 1000, 10); + testCube->create(tempDir.path() + "/large.cub"); + + LineManager line(*testCube); + double pixelValue = 0.0; + for(line.begin(); !line.end(); line++) { + for(int i = 0; i < line.size(); i++) { + line[i] = pixelValue; + } + + pixelValue++; + testCube->write(line); + } + } + + void LargeCube::TearDown() { + if (testCube->isOpen()) { + testCube->close(); + } + + if (testCube) { + delete testCube; + } + } + + void SpecialSmallCube::SetUp() { TempTestingFiles::SetUp(); diff --git a/isis/tests/Fixtures.h b/isis/tests/Fixtures.h index 0066875dfe..7be68c3f08 100644 --- a/isis/tests/Fixtures.h +++ b/isis/tests/Fixtures.h @@ -51,6 +51,16 @@ namespace Isis { void TearDown() override; }; + + class LargeCube : public TempTestingFiles { + protected: + Cube *testCube; + + void SetUp() override; + void TearDown() override; + }; + + class SpecialSmallCube : public TempTestingFiles { protected: Cube *testCube; diff --git a/isis/tests/FunctionalTestsApolloFindRx.cpp b/isis/tests/FunctionalTestsApolloFindRx.cpp index 611b4be5dc..683a8315b9 100644 --- a/isis/tests/FunctionalTestsApolloFindRx.cpp +++ b/isis/tests/FunctionalTestsApolloFindRx.cpp @@ -11,27 +11,28 @@ using namespace Isis; static QString APP_XML = FileName("$ISISROOT/bin/xml/apollofindrx.xml").expanded(); -TEST_F(SmallCube, FunctionalTestApolloFindRxDefault) { +TEST_F(LargeCube, FunctionalTestApolloFindRxDefault) { + PvlGroup reseaus("Reseaus"); - PvlKeyword samples = PvlKeyword("Sample", "2"); - samples += "4"; - samples += "6"; - samples += "8"; + PvlKeyword samples = PvlKeyword("Sample", "200"); + samples += "400"; + samples += "600"; + samples += "800"; - PvlKeyword lines = PvlKeyword("Line", "2"); - lines += "4"; - lines += "6"; - lines += "8"; + PvlKeyword lines = PvlKeyword("Line", "200"); + lines += "400"; + lines += "600"; + lines += "800"; PvlKeyword types = PvlKeyword("Type", "5"); types += "5"; types += "5"; - types += "5"; + types += "5"; PvlKeyword valid = PvlKeyword("Valid", "1"); valid += "1"; valid += "1"; - valid += "1"; + valid += "1"; reseaus += lines; reseaus += samples; @@ -54,9 +55,11 @@ TEST_F(SmallCube, FunctionalTestApolloFindRxDefault) { Pvl *lab = testCube->label(); lab->findObject("IsisCube").addGroup(reseaus); lab->findObject("IsisCube").addGroup(instGroup); - + + testCube->reopen("r"); + QTemporaryDir prefix; - QVector args = {"tolerance=0.125"}; + QVector args = {"tolerance=0.5", "patternsize=101", "deltax=2", "deltay=2"}; UserInterface options(APP_XML, args); try { @@ -70,22 +73,22 @@ TEST_F(SmallCube, FunctionalTestApolloFindRxDefault) { PvlGroup newReseaus = newLab.findObject("IsisCube").findGroup("Reseaus"); PvlKeyword testKeyword = newReseaus.findKeyword("Line"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[0], "-98.0"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[1], "-205.0"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[2], "-212.0"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[3], "-446.0"); + EXPECT_NEAR(testKeyword[0].toDouble(), 198.8, 0.0001); + EXPECT_NEAR(testKeyword[1].toDouble(), 388.8, 0.0001); + EXPECT_NEAR(testKeyword[2].toDouble(), 580.8, 0.0001); + EXPECT_NEAR(testKeyword[3].toDouble(), 744.8, 0.0001); testKeyword = newReseaus.findKeyword("Sample"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[0], "-98.0"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[1], "-205.0"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[2], "-321.0"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[3], "-446.0"); + EXPECT_NEAR(testKeyword[0].toDouble(), 198.8, 0.0001); + EXPECT_NEAR(testKeyword[1].toDouble(), 388.8, 0.0001); + EXPECT_NEAR(testKeyword[2].toDouble(), 569.8, 0.0001); + EXPECT_NEAR(testKeyword[3].toDouble(), 742.8, 0.0001); testKeyword = newReseaus.findKeyword("Valid"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[0], "1"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[1], "1"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[2], "1"); - EXPECT_PRED_FORMAT2(AssertQStringsEqual, testKeyword[3], "1"); + EXPECT_EQ(testKeyword[0].toInt(), 1); + EXPECT_EQ(testKeyword[1].toInt(), 1); + EXPECT_EQ(testKeyword[2].toInt(), 1); + EXPECT_EQ(testKeyword[3].toInt(), 1); EXPECT_PRED_FORMAT2(AssertQStringsEqual, newReseaus.findKeyword("Status"), "Refined"); From dc14e8a8eced3cc56bc65796a5d236367df4d687 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Mon, 19 Oct 2020 12:52:26 -0700 Subject: [PATCH 09/10] opened window for more cosistant tests and removed a rx point for faster tests --- isis/tests/FunctionalTestsApolloFindRx.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/isis/tests/FunctionalTestsApolloFindRx.cpp b/isis/tests/FunctionalTestsApolloFindRx.cpp index 683a8315b9..7e7172065f 100644 --- a/isis/tests/FunctionalTestsApolloFindRx.cpp +++ b/isis/tests/FunctionalTestsApolloFindRx.cpp @@ -17,22 +17,18 @@ TEST_F(LargeCube, FunctionalTestApolloFindRxDefault) { PvlKeyword samples = PvlKeyword("Sample", "200"); samples += "400"; samples += "600"; - samples += "800"; PvlKeyword lines = PvlKeyword("Line", "200"); lines += "400"; lines += "600"; - lines += "800"; PvlKeyword types = PvlKeyword("Type", "5"); types += "5"; types += "5"; - types += "5"; PvlKeyword valid = PvlKeyword("Valid", "1"); valid += "1"; valid += "1"; - valid += "1"; reseaus += lines; reseaus += samples; @@ -59,7 +55,7 @@ TEST_F(LargeCube, FunctionalTestApolloFindRxDefault) { testCube->reopen("r"); QTemporaryDir prefix; - QVector args = {"tolerance=0.5", "patternsize=101", "deltax=2", "deltay=2"}; + QVector args = {"tolerance=0.5", "patternsize=201"}; UserInterface options(APP_XML, args); try { @@ -73,22 +69,19 @@ TEST_F(LargeCube, FunctionalTestApolloFindRxDefault) { PvlGroup newReseaus = newLab.findObject("IsisCube").findGroup("Reseaus"); PvlKeyword testKeyword = newReseaus.findKeyword("Line"); - EXPECT_NEAR(testKeyword[0].toDouble(), 198.8, 0.0001); - EXPECT_NEAR(testKeyword[1].toDouble(), 388.8, 0.0001); - EXPECT_NEAR(testKeyword[2].toDouble(), 580.8, 0.0001); - EXPECT_NEAR(testKeyword[3].toDouble(), 744.8, 0.0001); + EXPECT_NEAR(testKeyword[0].toDouble(), 100.8141, 0.0001); + EXPECT_NEAR(testKeyword[1].toDouble(), 192.8, 0.0001); + EXPECT_NEAR(testKeyword[2].toDouble(), 275.8, 0.0001); testKeyword = newReseaus.findKeyword("Sample"); - EXPECT_NEAR(testKeyword[0].toDouble(), 198.8, 0.0001); - EXPECT_NEAR(testKeyword[1].toDouble(), 388.8, 0.0001); - EXPECT_NEAR(testKeyword[2].toDouble(), 569.8, 0.0001); - EXPECT_NEAR(testKeyword[3].toDouble(), 742.8, 0.0001); + EXPECT_NEAR(testKeyword[0].toDouble(), 100.8141, 0.0001); + EXPECT_NEAR(testKeyword[1].toDouble(), 192.8, 0.0001); + EXPECT_NEAR(testKeyword[2].toDouble(), 167.8, 0.0001); testKeyword = newReseaus.findKeyword("Valid"); EXPECT_EQ(testKeyword[0].toInt(), 1); EXPECT_EQ(testKeyword[1].toInt(), 1); EXPECT_EQ(testKeyword[2].toInt(), 1); - EXPECT_EQ(testKeyword[3].toInt(), 1); EXPECT_PRED_FORMAT2(AssertQStringsEqual, newReseaus.findKeyword("Status"), "Refined"); From a75fae5d8da38d0fece5a755410605df6e38a9fc Mon Sep 17 00:00:00 2001 From: Kelvin Date: Mon, 19 Oct 2020 14:17:12 -0700 Subject: [PATCH 10/10] reverted small cube change --- isis/tests/Fixtures.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isis/tests/Fixtures.cpp b/isis/tests/Fixtures.cpp index 0379805ec0..f578ea4678 100644 --- a/isis/tests/Fixtures.cpp +++ b/isis/tests/Fixtures.cpp @@ -13,7 +13,7 @@ namespace Isis { TempTestingFiles::SetUp(); testCube = new Cube(); - testCube->setDimensions(100, 100, 10); + testCube->setDimensions(10, 10, 10); testCube->create(tempDir.path() + "/small.cub"); LineManager line(*testCube);