Commit a70c03df authored by Adam Paquette's avatar Adam Paquette Committed by Jesse Mapel
Browse files

Adds the ability to arbitraily create image polygons from the set of coordinates

parent f2d2d1cb
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -271,7 +271,22 @@ namespace Isis {
      p_gMap->Camera()->IgnoreElevationModel(false);
  }

  void ImagePolygon::Create(std::vector<std::vector<double>> polyCoordinates) {
    p_pts = new geos::geom::CoordinateArraySequence();

    for (std::vector<double> coord : polyCoordinates) {
      p_pts->add(geos::geom::Coordinate(coord[0], coord[1]));
    }

    std::vector<geos::geom::Geometry *> *polys = new std::vector<geos::geom::Geometry *>;
    geos::geom::Polygon *poly = globalFactory->createPolygon(globalFactory->createLinearRing(p_pts), nullptr);
    polys->push_back(poly->clone());
    p_polygons = globalFactory->createMultiPolygon(polys);

    delete polys;

    Fix360Poly();
  }
  /**
  * Finds the next point on the image using a left hand rule walking algorithm. To
  * initiate the walk pass it the same point for both currentPoint and lastPoint.
+2 −0
Original line number Diff line number Diff line
@@ -174,6 +174,8 @@ namespace Isis {
          int ss = 1, int sl = 1, int ns = 0, int nl = 0, int band = 1,
          bool increasePrecision = false);
          
      void Create(std::vector<std::vector<double>> polyCoordinates);

      Camera * initCube(Cube &cube, int ss = 1, int sl = 1,
                        int ns = 0, int nl = 0, int band = 1);

+15 −52
Original line number Diff line number Diff line
@@ -168,65 +168,28 @@ 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);
    ImagePolygon poly;
    coords = {{30, 0},
              {30, 10},
              {35, 10},
              {35, 0},
              {30, 0}};
    poly.Create(coords);
    cube1->write(poly);
    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);
    coords = {{31, 1},
              {31, 11},
              {36, 11},
              {36, 1},
              {31, 1}};
    poly.Create(coords);
    cube2->write(poly);
    cube2->reopen("rw");

    delete wkt;

    cube3 = new Cube();
    cube3->fromIsd(tempDir.path() + "/cube3.cub", labelPath3, *isdPath3, "rw");

+1 −4
Original line number Diff line number Diff line
@@ -105,10 +105,7 @@ namespace Isis {
      FileList *cubeList;
      QString cubeListFile;

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

      void SetUp() override;
      void TearDown() override;
+8 −30
Original line number Diff line number Diff line
@@ -108,38 +108,16 @@ TEST_F(ThreeImageNetwork, FunctionalTestFindImageOverlapTwoImageOverlap) {

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);
  ImagePolygon poly;
  coords = {{31, 1},
            {31, 9},
            {34, 9},
            {34, 1},
            {31, 1}};
  poly.Create(coords);
  cube2->write(poly);
  cube2->reopen("rw");

  delete wkt;

  QVector<QString> args = {"OVERLAPLIST=" + tempDir.path() + "/overlaps.txt", "detailed=true", "errors=true"};
  UserInterface ui(APP_XML, args);
  FileList images;