From b5f18ad94bb84aecd5181b8d1ac287f8a914e6cc Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Tue, 8 Sep 2020 17:56:36 -0700 Subject: [PATCH 1/3] Found old findimageoverlaps test code. Updated based on original PR review --- isis/tests/Fixtures.cpp | 62 +++++++++++++++- isis/tests/Fixtures.h | 19 ++++- .../tests/FuntionalTestsFindImageOverlaps.cpp | 73 ++++++++++++++++--- 3 files changed, 139 insertions(+), 15 deletions(-) diff --git a/isis/tests/Fixtures.cpp b/isis/tests/Fixtures.cpp index d9c65c9763..b1d60270aa 100644 --- a/isis/tests/Fixtures.cpp +++ b/isis/tests/Fixtures.cpp @@ -168,9 +168,65 @@ namespace Isis { cube1 = new Cube(); cube1->fromIsd(tempDir.path() + "/cube1.cub", labelPath1, *isdPath1, "rw"); + lonLatPts = new geos::geom::CoordinateArraySequence(); + lonLatPts->add(geos::geom::Coordinate(30, 0)); + lonLatPts->add(geos::geom::Coordinate(30, 10)); + lonLatPts->add(geos::geom::Coordinate(35, 10)); + lonLatPts->add(geos::geom::Coordinate(35, 0)); + lonLatPts->add(geos::geom::Coordinate(30, 0)); + + polys = new std::vector; + poly = globalFactory->createPolygon(globalFactory->createLinearRing(lonLatPts), nullptr); + polys->push_back(poly->clone()); + multiPoly = globalFactory->createMultiPolygon(polys); + + geos::io::WKTWriter *wkt = new geos::io::WKTWriter(); + + std::string polyStr = wkt->write(multiPoly); + int polyStrSize = polyStr.size(); + std::istringstream polyStream(polyStr); + + Blob pvlBlob("Footprint", "Polygon"); + Pvl pvl; + PvlObject polyObject = PvlObject("Polygon"); + polyObject.addKeyword(PvlKeyword("Name", "Footprint")); + polyObject.addKeyword(PvlKeyword("StartByte", "1")); + polyObject.addKeyword(PvlKeyword("Bytes", toString(polyStrSize))); + pvl.addObject(polyObject); + + pvlBlob.Read(pvl, polyStream); + cube1->write(pvlBlob); + cube1->reopen("rw"); + cube2 = new Cube(); cube2->fromIsd(tempDir.path() + "/cube2.cub", labelPath2, *isdPath2, "rw"); + lonLatPts = new geos::geom::CoordinateArraySequence(); + lonLatPts->add(geos::geom::Coordinate(31, 1)); + lonLatPts->add(geos::geom::Coordinate(31, 11)); + lonLatPts->add(geos::geom::Coordinate(36, 11)); + lonLatPts->add(geos::geom::Coordinate(36, 1)); + lonLatPts->add(geos::geom::Coordinate(31, 1)); + + polys->pop_back(); + poly = globalFactory->createPolygon(globalFactory->createLinearRing(lonLatPts), nullptr); + polys->push_back(poly); + multiPoly = globalFactory->createMultiPolygon(polys); + + polyStr = wkt->write(multiPoly); + polyStrSize = polyStr.size(); + polyStream = std::istringstream(polyStr); + + pvlBlob = Blob("Footprint", "Polygon"); + polyObject.addKeyword(PvlKeyword("Bytes", toString(polyStrSize))); + pvl.addObject(polyObject); + + pvlBlob.Read(pvl, polyStream); + cube2->write(pvlBlob); + cube2->reopen("rw"); + + delete wkt; + cube3 = new Cube(); cube3->fromIsd(tempDir.path() + "/cube3.cub", labelPath3, *isdPath3, "rw"); @@ -197,9 +253,9 @@ namespace Isis { delete isdPath1; delete isdPath2; - delete isdPath3; + delete isdPath3; - delete threeImageOverlapFile; - delete twoImageOverlapFile; + delete threeImageOverlapFile; + delete twoImageOverlapFile; } } diff --git a/isis/tests/Fixtures.h b/isis/tests/Fixtures.h index 69aa900620..0066875dfe 100644 --- a/isis/tests/Fixtures.h +++ b/isis/tests/Fixtures.h @@ -16,10 +16,20 @@ #include "Pvl.h" #include "PvlGroup.h" #include "PvlObject.h" +#include "ImagePolygon.h" +#include "PolygonTools.h" +#include "Blob.h" #include "ControlNet.h" #include "FileList.h" #include "FileName.h" +#include +#include +#include "geos/geom/CoordinateArraySequence.h" +#include "geos/geom/CoordinateSequence.h" +#include "geos/geom/LinearRing.h" +#include "geos/geom/Polygon.h" + using json = nlohmann::json; namespace Isis { @@ -84,10 +94,10 @@ namespace Isis { Cube *cube1; Cube *cube2; Cube *cube3; - + FileName *isdPath1; FileName *isdPath2; - FileName *isdPath3; + FileName *isdPath3; FileName *threeImageOverlapFile; FileName *twoImageOverlapFile; @@ -95,6 +105,11 @@ namespace Isis { FileList *cubeList; QString cubeListFile; + geos::geom::CoordinateSequence *lonLatPts; + std::vector *polys; + geos::geom::Polygon *poly; + geos::geom::MultiPolygon *multiPoly; + void SetUp() override; void TearDown() override; }; diff --git a/isis/tests/FuntionalTestsFindImageOverlaps.cpp b/isis/tests/FuntionalTestsFindImageOverlaps.cpp index 13c1ef352b..6ba321427f 100644 --- a/isis/tests/FuntionalTestsFindImageOverlaps.cpp +++ b/isis/tests/FuntionalTestsFindImageOverlaps.cpp @@ -1,9 +1,26 @@ +#include +#include + #include "findimageoverlaps.h" #include "Fixtures.h" #include "TestUtilities.h" #include "IException.h" #include "FileList.h" #include "ImagePolygon.h" +#include "PolygonTools.h" +#include "ImageOverlap.h" +#include "ImageOverlapSet.h" +#include "Blob.h" +#include "Pvl.h" + +#include +#include +#include "geos/geom/CoordinateArraySequence.h" +#include "geos/geom/CoordinateSequence.h" +#include "geos/geom/LinearRing.h" +#include "geos/geom/Polygon.h" + +#include "Fixtures.h" #include "gmock/gmock.h" @@ -15,32 +32,32 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapsNoOverlap) { ImagePolygon fp1; fp1.Create(*cube1); cube1->write(fp1); - + Cube newCube2; - json newIsd2; + json newIsd2; std::ifstream i(isdPath2->expanded().toStdString()); - i >> newIsd2; + i >> newIsd2; newIsd2["instrument_position"]["positions"] = {{1,1,1}, {2,2,2}, {3,3,3}}; - newCube2.fromIsd(tempDir.path()+"/new2.cub", *cube2->label(), newIsd2, "rw"); + newCube2.fromIsd(tempDir.path()+"/new2.cub", *cube2->label(), newIsd2, "rw"); ImagePolygon fp2; fp2.Create(newCube2); - newCube2.write(fp2); + newCube2.write(fp2); - FileList cubes; + FileList cubes; cubes.append(cube1->fileName()); cubes.append(newCube2.fileName()); cube1->close(); cube2->close(); newCube2.close(); - - QString cubeListPath = tempDir.path() + "/cubes.lis"; + + QString cubeListPath = tempDir.path() + "/cubes.lis"; cubes.write(cubeListPath); QVector args = {"from="+cubeListPath, "overlapList="+tempDir.path()+"/overlaps.txt"}; UserInterface options(APP_XML, args); Pvl appLog; - + try { findimageoverlaps(options, &appLog); FAIL() << "Expected an IException with message: \"No overlaps were found\"."; @@ -50,4 +67,40 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapsNoOverlap) { << e.toString().toStdString(); } -} +} + +TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapDefault) { + + QVector args = {"OVERLAPLIST=" + tempDir.path() + "/test.txt", "detailed=true", "errors=true"}; + UserInterface ui(APP_XML, args); + FileList images; + images.append(FileName(cube1->fileName())); + images.append(FileName(cube2->fileName())); + findimageoverlaps(images, ui, nullptr); + + // Find all the overlaps between the images in the FROMLIST + // The overlap polygon coordinates are in Lon/Lat order + ImageOverlapSet overlaps; + overlaps.ReadImageOverlaps(ui.GetFileName("OVERLAPLIST")); + const ImageOverlap *poi; + const geos::geom::MultiPolygon *mp; + + poi = overlaps[0]; + mp = poi->Polygon(); + ASSERT_EQ(mp->getArea(), 14); + ASSERT_EQ(poi->Size(), 1); + ASSERT_EQ((*poi)[0], "MGS/688540926:0/MOC-WA/RED"); + + poi = overlaps[1]; + mp = poi->Polygon(); + ASSERT_EQ(mp->getArea(), 14); + ASSERT_EQ(poi->Size(), 1); + ASSERT_EQ((*poi)[0], "MGS/691204200:96/MOC-WA/RED"); + + poi = overlaps[2]; + mp = poi->Polygon(); + ASSERT_EQ(mp->getArea(), 36); + ASSERT_EQ(poi->Size(), 2); + ASSERT_EQ((*poi)[0], "MGS/688540926:0/MOC-WA/RED"); + ASSERT_EQ((*poi)[1], "MGS/691204200:96/MOC-WA/RED"); +} From 487414685f5f4fef99013daf32ede4e5f9a2f280 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Fri, 11 Sep 2020 10:55:26 -0700 Subject: [PATCH 2/3] Fix for centos build and other test failures --- isis/src/base/apps/stats/stats.xml | 1 + isis/tests/Fixtures.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/isis/src/base/apps/stats/stats.xml b/isis/src/base/apps/stats/stats.xml index 986cb66230..07cc2e02c7 100644 --- a/isis/src/base/apps/stats/stats.xml +++ b/isis/src/base/apps/stats/stats.xml @@ -58,6 +58,7 @@ Minimum DN value in the cube Maximum DN value in the cube 65536 +

The cube multiplier and base can be found in the header of the cube. diff --git a/isis/tests/Fixtures.cpp b/isis/tests/Fixtures.cpp index b1d60270aa..01992b846a 100644 --- a/isis/tests/Fixtures.cpp +++ b/isis/tests/Fixtures.cpp @@ -215,7 +215,7 @@ namespace Isis { polyStr = wkt->write(multiPoly); polyStrSize = polyStr.size(); - polyStream = std::istringstream(polyStr); + polyStream.str(polyStr); pvlBlob = Blob("Footprint", "Polygon"); polyObject.addKeyword(PvlKeyword("Bytes", toString(polyStrSize))); From df7a4b4a1af9d2db5633a29ccdb9819ebd10363c Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Fri, 11 Sep 2020 11:27:34 -0700 Subject: [PATCH 3/3] Added full overlap test and removed old test make files --- .../findimageoverlaps/tsts/default/Makefile | 8 --- .../tsts/fulloverlap/Makefile | 10 --- .../tests/FuntionalTestsFindImageOverlaps.cpp | 68 ++++++++++++++++++- 3 files changed, 66 insertions(+), 20 deletions(-) delete mode 100644 isis/src/base/apps/findimageoverlaps/tsts/default/Makefile delete mode 100644 isis/src/base/apps/findimageoverlaps/tsts/fulloverlap/Makefile diff --git a/isis/src/base/apps/findimageoverlaps/tsts/default/Makefile b/isis/src/base/apps/findimageoverlaps/tsts/default/Makefile deleted file mode 100644 index b80e4bd1c2..0000000000 --- a/isis/src/base/apps/findimageoverlaps/tsts/default/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -APPNAME = findimageoverlaps - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(LS) $(INPUT)/*.cub > $(OUTPUT)/cubes.lis; - $(APPNAME) FROMLIST=$(OUTPUT)/cubes.lis OVERLAPLIST=$(OUTPUT)/overlaps.txt > /dev/null; - $(RM) $(OUTPUT)/cubes.lis; diff --git a/isis/src/base/apps/findimageoverlaps/tsts/fulloverlap/Makefile b/isis/src/base/apps/findimageoverlaps/tsts/fulloverlap/Makefile deleted file mode 100644 index 26883a4e07..0000000000 --- a/isis/src/base/apps/findimageoverlaps/tsts/fulloverlap/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# This test checks to see that overlaps are properly generated -# when one image is completely inside of another image. -APPNAME = findimageoverlaps - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(LS) $(INPUT)/*.cub > $(OUTPUT)/cubes.lis; - $(APPNAME) FROM=$(OUTPUT)/cubes.lis OVERLAPLIST=$(OUTPUT)/overlaps.txt > /dev/null; - $(RM) $(OUTPUT)/cubes.lis; diff --git a/isis/tests/FuntionalTestsFindImageOverlaps.cpp b/isis/tests/FuntionalTestsFindImageOverlaps.cpp index 6ba321427f..039f87cc92 100644 --- a/isis/tests/FuntionalTestsFindImageOverlaps.cpp +++ b/isis/tests/FuntionalTestsFindImageOverlaps.cpp @@ -69,9 +69,9 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapsNoOverlap) { } -TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapDefault) { +TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapTwoImageOverlap) { - QVector args = {"OVERLAPLIST=" + tempDir.path() + "/test.txt", "detailed=true", "errors=true"}; + QVector args = {"OVERLAPLIST=" + tempDir.path() + "/overlaps.txt", "detailed=true", "errors=true"}; UserInterface ui(APP_XML, args); FileList images; images.append(FileName(cube1->fileName())); @@ -82,6 +82,7 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapDefault) { // The overlap polygon coordinates are in Lon/Lat order ImageOverlapSet overlaps; overlaps.ReadImageOverlaps(ui.GetFileName("OVERLAPLIST")); + ASSERT_EQ(overlaps.Size(), 3); const ImageOverlap *poi; const geos::geom::MultiPolygon *mp; @@ -104,3 +105,66 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapDefault) { ASSERT_EQ((*poi)[0], "MGS/688540926:0/MOC-WA/RED"); ASSERT_EQ((*poi)[1], "MGS/691204200:96/MOC-WA/RED"); } + +TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapFullOverlap) { + + lonLatPts = new geos::geom::CoordinateArraySequence(); + lonLatPts->add(geos::geom::Coordinate(31, 1)); + lonLatPts->add(geos::geom::Coordinate(31, 9)); + lonLatPts->add(geos::geom::Coordinate(34, 9)); + lonLatPts->add(geos::geom::Coordinate(34, 1)); + lonLatPts->add(geos::geom::Coordinate(31, 1)); + + polys = new std::vector; + poly = globalFactory->createPolygon(globalFactory->createLinearRing(lonLatPts), nullptr); + polys->push_back(poly->clone()); + multiPoly = globalFactory->createMultiPolygon(polys); + + geos::io::WKTWriter *wkt = new geos::io::WKTWriter(); + + std::string polyStr = wkt->write(multiPoly); + int polyStrSize = polyStr.size(); + std::istringstream polyStream(polyStr); + + Blob pvlBlob("Footprint", "Polygon"); + Pvl pvl; + PvlObject polyObject = PvlObject("Polygon"); + polyObject.addKeyword(PvlKeyword("Name", "Footprint")); + polyObject.addKeyword(PvlKeyword("StartByte", "1")); + polyObject.addKeyword(PvlKeyword("Bytes", toString(polyStrSize))); + pvl.addObject(polyObject); + + pvlBlob.Read(pvl, polyStream); + cube2->write(pvlBlob); + cube2->reopen("rw"); + + delete wkt; + + QVector args = {"OVERLAPLIST=" + tempDir.path() + "/overlaps.txt", "detailed=true", "errors=true"}; + UserInterface ui(APP_XML, args); + FileList images; + images.append(FileName(cube1->fileName())); + images.append(FileName(cube2->fileName())); + findimageoverlaps(images, ui, nullptr); + + // Find all the overlaps between the images in the FROMLIST + // The overlap polygon coordinates are in Lon/Lat order + ImageOverlapSet overlaps; + overlaps.ReadImageOverlaps(ui.GetFileName("OVERLAPLIST")); + ASSERT_EQ(overlaps.Size(), 2); + const ImageOverlap *poi; + const geos::geom::MultiPolygon *mp; + + poi = overlaps[0]; + mp = poi->Polygon(); + ASSERT_EQ(mp->getArea(), 26); + ASSERT_EQ(poi->Size(), 1); + ASSERT_EQ((*poi)[0], "MGS/688540926:0/MOC-WA/RED"); + + poi = overlaps[1]; + mp = poi->Polygon(); + ASSERT_EQ(mp->getArea(), 24); + ASSERT_EQ(poi->Size(), 2); + ASSERT_EQ((*poi)[0], "MGS/691204200:96/MOC-WA/RED"); + ASSERT_EQ((*poi)[1], "MGS/688540926:0/MOC-WA/RED"); +}