Пример #1
0
  /**
   * Updates the tracking labels.
   * Displays the Planetocentric Latitude and 360 Positive East
   * Longitude in the lower right corner of the window.
   *
   *
   * @param p
   */
  void MosaicTrackTool::updateLabels(QPointF p) {
    //----------------------------------------------------------------------
    // we need to find out if the point given is over an item, if not, call
    // clearLables() if so, then we need to get the item and figure out the
    // lat/lon that corresponds with the given point.
    //----------------------------------------------------------------------
    Projection *proj = getWidget()->getProjection();
    TProjection *tproj = (TProjection *) proj;

    if (!proj || proj->projectionType() != Projection::Triaxial) {
      clearLabels();
      return;
    }

    proj->SetCoordinate(p.x(), -1 * p.y());

    if(p_lonLabel) {
      p_lonLabel->setVisible(true);
      p_lonLabel->setText("LON " + QString::number(tproj->Longitude()));
    }

    if(p_latLabel) {
      p_latLabel->setVisible(true);
      p_latLabel->setText("LAT " + QString::number(tproj->Latitude()));
    }

    if(p_xLabel) {
      p_xLabel->setVisible(true);
      p_xLabel->setText("X " + QString::number(p.x()));
    }

    if(p_yLabel) {
      p_yLabel->setVisible(true);
      p_yLabel->setText("Y " + QString::number(-1 * p.y()));
    }
  }
Пример #2
0
/**
 * Removes control points not in the lat/lon range provided in the unput 
 * parameters. 
 * 
 * @param outNet The output control net being removed from
 * @param noLanLonPoint The keyword recording all of the control points removed
 *                      due to the provided lat/lon range
 * @param noLanLonPoint The keyword recording all of the control points removed
 *                      due to the inability to calculate the lat/lon for that
 *                      point
 */
void ExtractLatLonRange( ControlNet & outNet, PvlKeyword & nonLatLonPoints,
                         PvlKeyword & cannotGenerateLatLonPoints,  map<iString,iString> sn2filename ) {
  if( outNet.Size() == 0 ) { return; }

  UserInterface &ui = Application::GetUserInterface();

  // Get the lat/lon and fix the range for the internal 0/360
  double minlat = ui.GetDouble("MINLAT");
  double maxlat = ui.GetDouble("MAXLAT");
  double minlon = ui.GetDouble("MINLON");
  if( minlon < 0.0 ) { minlon += 360; }
  double maxlon = ui.GetDouble("MAXLON");
  if( maxlon < 0.0 ) { minlon += 360; }

  bool useNetwork = ui.GetBoolean("USENETWORK");

  Progress progress;
  progress.SetText("Calculating lat/lon");
  progress.SetMaximumSteps(outNet.Size());
  progress.CheckStatus();

  CubeManager manager;
  manager.SetNumOpenCubes( 50 ); //Should keep memory usage to around 1GB

  for( int cp = outNet.Size()-1; cp >= 0; cp --) {
    progress.CheckStatus();

    // If the Contorl Network takes priority, use it
    double pointLat = outNet[cp].UniversalLatitude();
    double pointLon = outNet[cp].UniversalLongitude();
    bool useControlNet = useNetwork && pointLat > -1000 && pointLon > -1000;
    if( outNet[cp].Type() == Isis::ControlPoint::Ground || useControlNet ) {
      if( NotInLatLonRange( outNet[cp].UniversalLatitude(),
                            outNet[cp].UniversalLongitude(),
                            minlat, maxlat, minlon, maxlon ) ) {
        nonLatLonPoints += outNet[cp].Id();
        outNet.Delete( cp );
      }
    }

    /** 
     * If the lat/lon cannot be determined from the point, then we need to calculate
     * lat/lon on our own 
     */
    else if( ui.WasEntered("FROMLIST") ) {

      // Find a cube in the Control Point to get the lat/lon from
      int cm = 0;
      iString sn = "";
      double lat = 0.0;
      double lon = 0.0;
      double radius = 0.0;

      // First check the reference Measure
      if( outNet[cp].HasReference() ) {
        cm = outNet[cp].ReferenceIndex();
        if( !sn2filename[outNet[cp][cm].CubeSerialNumber()].empty() ) {
          sn = outNet[cp][cm].CubeSerialNumber();
        }
      }

      // Search for other Control Measures if needed
      if( sn.empty() ) {
        // Find the Serial Number if it exists
        for( int cm = 0; (cm < outNet[cp].Size()) && sn.empty(); cm ++ ) {
          if( !sn2filename[outNet[cp][cm].CubeSerialNumber()].empty() ) {
            sn = outNet[cp][cm].CubeSerialNumber();
          }
        }
      }

      // Connot fine a cube to get the lat/lon from
      if( sn.empty() ) {
        cannotGenerateLatLonPoints += outNet[cp].Id();
        outNet.Delete( cp );
      }

      // Calculate the lat/lon and check for validity
      else {
        bool remove = false;

        Cube *cube = manager.OpenCube( sn2filename[sn] );
        Camera *camera = cube->Camera();

        if (camera == NULL) {
          try {
            Projection *projection = ProjectionFactory::Create( (*(cube->Label())) );

            if(!projection->SetCoordinate(outNet[cp][cm].Sample(),outNet[cp][cm].Line())) {
              nonLatLonPoints += outNet[cp].Id();
              remove = true;
            }

            lat = projection->Latitude();
            lon = projection->Longitude();
            radius = projection->LocalRadius();

            delete projection;
            projection = NULL;
          } catch ( iException &e ) {
            remove = true;
            e.Clear();
          }
        }
        else {
          if(!camera->SetImage(outNet[cp][cm].Sample(),outNet[cp][cm].Line())) {
            nonLatLonPoints += outNet[cp].Id();
            remove = true;
          }

          lat = camera->UniversalLatitude();
          lon = camera->UniversalLongitude();
          radius = camera->LocalRadius();

          camera = NULL;
        }

        cube = NULL;

        if( remove  ||  NotInLatLonRange( lat, lon, minlat, maxlat, minlon, maxlon ) ) {
          nonLatLonPoints += outNet[cp].Id();
          outNet.Delete( cp );
        }
        else { // Add the reference lat/lon/radius to the Control Point
          outNet[cp].SetUniversalGround( lat, lon, radius );
        }
      }
    }
    else {
      cannotGenerateLatLonPoints += outNet[cp].Id();
      outNet.Delete( cp );
    }

  }

  manager.CleanCubes();
}
Пример #3
0
int main() {
  Isis::Preference::Preferences(true);
  try {
    cout << "Test 1, create a seeder" << endl;

    PvlGroup alg("PolygonSeederAlgorithm");

    if(!alg.hasKeyword("Name")) {
      cout << "Test without subgrid" << endl;
      alg += PvlKeyword("Name", "Strip");
      alg += PvlKeyword("MinimumThickness", toString(0.3));
      alg += PvlKeyword("MinimumArea", toString(10));
      alg += PvlKeyword("XSpacing", toString(1500));
      alg += PvlKeyword("YSpacing", toString(1500));
    }

    PvlObject o("AutoSeed");
    o.addGroup(alg);

    Pvl pvl;
    pvl.addObject(o);
    cout << pvl << endl << endl;

    PolygonSeeder *ps = PolygonSeederFactory::Create(pvl);

    std::cout << "Test to make sure Parse did it's job" << std::endl;
    std::cout << "MinimumThickness = " << ps->MinimumThickness() << std::endl;
    std::cout << "MinimumArea = " << ps->MinimumArea() << std::endl;

    cout << "Test 2, test a square polygon" << endl;
    try {
      // Call the seed member with a polygon
      geos::geom::CoordinateSequence *pts;
      vector<geos::geom::Geometry *> polys;

      // Create the A polygon
      pts = new geos::geom::CoordinateArraySequence();
      pts->add(geos::geom::Coordinate(0, 0));
      pts->add(geos::geom::Coordinate(0, 1.5));
      pts->add(geos::geom::Coordinate(0.5, 1.5));
      pts->add(geos::geom::Coordinate(0.5, 0));
      pts->add(geos::geom::Coordinate(0, 0));

      polys.push_back(Isis::globalFactory.createPolygon(
                        Isis::globalFactory.createLinearRing(pts), NULL));

      geos::geom::MultiPolygon *mp = Isis::globalFactory.createMultiPolygon(polys);

      cout << "Lon/Lat polygon = " << mp->toString() << endl;
      // Create the projection necessary for seeding
      PvlGroup radii = Projection::TargetRadii("MARS");
      Isis::Pvl maplab;
      maplab.addGroup(Isis::PvlGroup("Mapping"));
      Isis::PvlGroup &mapGroup = maplab.findGroup("Mapping");
      mapGroup += Isis::PvlKeyword("EquatorialRadius", (QString)radii["EquatorialRadius"]);
      mapGroup += Isis::PvlKeyword("PolarRadius", (QString)radii["PolarRadius"]);
      mapGroup += Isis::PvlKeyword("LatitudeType", "Planetocentric");
      mapGroup += Isis::PvlKeyword("LongitudeDirection", "PositiveEast");
      mapGroup += Isis::PvlKeyword("LongitudeDomain", toString(360));
      mapGroup += Isis::PvlKeyword("CenterLatitude", "0");
      mapGroup += Isis::PvlKeyword("CenterLongitude", "0");
      mapGroup += Isis::PvlKeyword("ProjectionName", "Sinusoidal");

      Projection *proj = Isis::ProjectionFactory::Create(maplab);

      /*
      This test doesn't make sense because there is no ground range on this
      projection.


      double x1,x2,y1,y2;
      proj->XYRange(x1,x2,y1,y2);
      if(fabs(x1) < 0.00000001) x1 = 0.0;
      if(fabs(x2) < 0.00000001) x2 = 0.0;
      if(fabs(y1) < 0.00000001) y1 = 0.0;
      if(fabs(y2) < 0.00000001) y2 = 0.0;
      std::cout << "X: " << x1 << "-" << x2 << " Y: " << y1 << "-" << y2 << std::endl;
      */

      geos::geom::MultiPolygon *xymp = PolygonTools::LatLonToXY(*mp, proj);
      vector<geos::geom::Point *> seedValues = ps->Seed(xymp);

      vector<geos::geom::Point *> points;
      for(unsigned int pt = 0; pt < seedValues.size(); pt ++) {
        if(proj->SetCoordinate(seedValues[pt]->getX(), seedValues[pt]->getY())) {
          points.push_back(Isis::globalFactory.createPoint(
                             geos::geom::Coordinate(proj->UniversalLongitude(),
                                 proj->UniversalLatitude())));
        }
        else {
          IString msg = "Unable to convert to a (lon,lat)";
          throw IException(IException::Programmer, msg, _FILEINFO_);
        }
      }

      cout << setprecision(13);
      for(unsigned int i = 0; i < points.size(); i++) {
        cout << "  POINT (";
        cout << points[i]->getX() << " " << points[i]->getY() << ")" << endl;
      }
    }
    catch(IException &e) {
      e.print();
    }

    cout << "Test 3, test for too thin" << endl;
    try {
      // Call the seed member with a polygon
      geos::geom::CoordinateSequence *pts;
      vector<geos::geom::Geometry *> polys;

      // Create the A polygon
      pts = new geos::geom::DefaultCoordinateSequence();
      pts->add(geos::geom::Coordinate(0, 0));
      pts->add(geos::geom::Coordinate(0, 0.5));
      pts->add(geos::geom::Coordinate(0.0125, 0.5));
      pts->add(geos::geom::Coordinate(0.0125, 0));
      pts->add(geos::geom::Coordinate(0, 0));

      polys.push_back(Isis::globalFactory.createPolygon(
                        Isis::globalFactory.createLinearRing(pts), NULL));

      geos::geom::MultiPolygon *mp = Isis::globalFactory.createMultiPolygon(polys);

      cout << "Lon/Lat polygon = " << mp->toString() << endl;

      // Create the projection necessary for seeding
      PvlGroup radii = Projection::TargetRadii("MARS");
      Isis::Pvl maplab;
      maplab.addGroup(Isis::PvlGroup("Mapping"));
      Isis::PvlGroup &mapGroup = maplab.findGroup("Mapping");
      mapGroup += Isis::PvlKeyword("EquatorialRadius", (QString)radii["EquatorialRadius"]);
      mapGroup += Isis::PvlKeyword("PolarRadius", (QString)radii["PolarRadius"]);
      mapGroup += Isis::PvlKeyword("LatitudeType", "Planetocentric");
      mapGroup += Isis::PvlKeyword("LongitudeDirection", "PositiveEast");
      mapGroup += Isis::PvlKeyword("LongitudeDomain", toString(360));
      mapGroup += Isis::PvlKeyword("CenterLatitude", toString(0));
      mapGroup += Isis::PvlKeyword("CenterLongitude", toString(0));
      mapGroup += Isis::PvlKeyword("ProjectionName", "Sinusoidal");
      Projection *proj = Isis::ProjectionFactory::Create(maplab);

      // NOTHING SHOULD BE PRINTED (the thickness test should not have been met)
      geos::geom::MultiPolygon *xymp = PolygonTools::LatLonToXY(*mp, proj);
      vector<geos::geom::Point *> seedValues = ps->Seed(xymp);

      for(unsigned int i = 0; i < seedValues.size(); i++) {
        cout << "Point(" << i << ") = " << seedValues[i]->toString() << endl;
      }
    }
    catch(IException &e) {
      e.print();
    }
  }
  catch(IException &e) {
    e.print();
  }

  return 0;
}