Unverified Commit 728b84af authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

FindImageOverlaps test (#4007)

* Found old findimageoverlaps test code. Updated based on original PR review

* Fix for centos build and other test failures

* Added full overlap test and removed old test make files
parent 9d867719
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
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;
+0 −10
Original line number Diff line number Diff line
# 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;
+59 −3
Original line number Diff line number Diff line
@@ -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");

+17 −2
Original line number Diff line number Diff line
@@ -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 {
@@ -95,6 +105,11 @@ namespace Isis {
      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;
  };
+127 −10
Original line number Diff line number Diff line
#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"

@@ -51,3 +68,103 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapsNoOverlap) {
  }

}

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);

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