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

FindImageOverlaps test #4007

Merged
merged 4 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions isis/src/base/apps/findimageoverlaps/tsts/default/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions isis/src/base/apps/findimageoverlaps/tsts/fulloverlap/Makefile

This file was deleted.

62 changes: 59 additions & 3 deletions isis/tests/Fixtures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<geos::geom::Geometry *>;
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");

Expand All @@ -197,9 +253,9 @@ namespace Isis {

delete isdPath1;
delete isdPath2;
delete isdPath3;
delete isdPath3;

delete threeImageOverlapFile;
delete twoImageOverlapFile;
delete threeImageOverlapFile;
delete twoImageOverlapFile;
}
}
19 changes: 17 additions & 2 deletions isis/tests/Fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>
#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 {
Expand Down Expand Up @@ -84,17 +94,22 @@ namespace Isis {
Cube *cube1;
Cube *cube2;
Cube *cube3;

FileName *isdPath1;
FileName *isdPath2;
FileName *isdPath3;
FileName *isdPath3;

FileName *threeImageOverlapFile;
FileName *twoImageOverlapFile;

FileList *cubeList;
QString cubeListFile;

geos::geom::CoordinateSequence *lonLatPts;
std::vector<geos::geom::Geometry *> *polys;
geos::geom::Polygon *poly;
geos::geom::MultiPolygon *multiPoly;

void SetUp() override;
void TearDown() override;
};
Expand Down
137 changes: 127 additions & 10 deletions isis/tests/FuntionalTestsFindImageOverlaps.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
#include <iostream>
#include <QTemporaryFile>

#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 <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>
#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"

Expand All @@ -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<QString> 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\".";
Expand All @@ -50,4 +67,104 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapsNoOverlap) {
<< e.toString().toStdString();
}

}
}

TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapTwoImageOverlap) {

QVector<QString> 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<geos::geom::Geometry *>;
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);
Kelvinrr marked this conversation as resolved.
Show resolved Hide resolved

pvlBlob.Read(pvl, polyStream);
cube2->write(pvlBlob);
cube2->reopen("rw");

delete wkt;

QVector<QString> 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");
}