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/Fixtures.cpp b/isis/tests/Fixtures.cpp index d9c65c9763..01992b846a 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.str(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..039f87cc92 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,104 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapsNoOverlap) { << e.toString().toStdString(); } -} +} + +TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapTwoImageOverlap) { + + 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(), 3); + 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"); +} + +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"); +}