Commit c3891aff authored by Janet Barrett's avatar Janet Barrett
Browse files

Fixed SubArea class so it recalculates the min/max lat/lon keyword values of...

Fixed SubArea class so it recalculates the min/max lat/lon keyword values of cropped maps with equatorial cylindrical projections. Fixes #1500.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@5714 41f8697f-d340-4b68-9986-7bafba869bb8
parent 6292bdb0
Loading
Loading
Loading
Loading
+53 −4
Changes for isis/src/base/objs/SubArea/SubArea.cpp: 53 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "AlphaCube.h"
#include "Projection.h"
#include "ProjectionFactory.h"
#include "TProjection.h"
#include "IException.h"
#include "IString.h"

@@ -162,13 +163,13 @@ namespace Isis {
    if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
      // Update the upper left corner X,Y values if the starting line or
      // starting sample are changed.
      TProjection *proj = (TProjection *) icube->projection();
      if(p_sl != 1 || p_ss != 1) {
        Projection &proj = *icube->projection();
        proj.SetWorld(p_ss - 0.5, p_sl - 0.5);
        proj->SetWorld(p_ss - 0.5, p_sl - 0.5);
        PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
        mapgroup.addKeyword(PvlKeyword("UpperLeftCornerX", toString(proj.XCoord())),
        mapgroup.addKeyword(PvlKeyword("UpperLeftCornerX", toString(proj->XCoord())),
                            Pvl::Replace);
        mapgroup.addKeyword(PvlKeyword("UpperLeftCornerY", toString(proj.YCoord())),
        mapgroup.addKeyword(PvlKeyword("UpperLeftCornerY", toString(proj->YCoord())),
                            Pvl::Replace);
      }

@@ -190,6 +191,53 @@ namespace Isis {
      // latitude,longitude range is no longer valid.
      if(p_sl != 1 || p_ss != 1 || p_el != p_nl || p_es != p_ns) {
        PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
        if (proj->IsEquatorialCylindrical()) {
          double minlat, maxlat;
          double minlon, maxlon;
          proj->SetWorld(p_ss-.5, p_sl-.5);
          if (proj->IsGood()) {
            maxlat = proj->UniversalLatitude();
            if (proj->IsPlanetographic()) {
              maxlat = proj->ToPlanetographic(maxlat);
            }
            if (proj->IsPositiveEast()) {
              minlon = proj->UniversalLongitude();
              if (proj->Has180Domain()) {
                minlon = proj->To180Domain(minlon);
              }
            }
            else {
              minlon = proj->ToPositiveWest(proj->UniversalLongitude(), 360);
              if (proj->Has180Domain()) {
                minlon = proj->To180Domain(proj->ToPositiveWest(proj->UniversalLongitude(), 360));
              }
            }
            proj->SetWorld(p_es+.5, p_el+.5);
            if (proj->IsGood()) {
              minlat = proj->UniversalLatitude();
              if (proj->IsPlanetographic()) {
                minlat = proj->ToPlanetographic(minlat);
              }
              if (proj->IsPositiveEast()) {
                maxlon = proj->UniversalLongitude();
                if (proj->Has180Domain()) {
                  maxlon = proj->To180Domain(maxlon);
                }
              }
              else {
                maxlon = proj->ToPositiveWest(proj->UniversalLongitude(), 360);
                if (proj->Has180Domain()) {
                  maxlon = proj->To180Domain(proj->ToPositiveWest(proj->UniversalLongitude(), 360));
                }
              }
              mapgroup.addKeyword(PvlKeyword("MinimumLatitude",toString(minlat)),Pvl::Replace);
              mapgroup.addKeyword(PvlKeyword("MaximumLatitude",toString(maxlat)),Pvl::Replace);
              mapgroup.addKeyword(PvlKeyword("MinimumLongitude",toString(minlon)),Pvl::Replace);
              mapgroup.addKeyword(PvlKeyword("MaximumLongitude",toString(maxlon)),Pvl::Replace);
            }
          }
        }
        else {
          if(mapgroup.hasKeyword("MinimumLatitude")) {
            mapgroup.deleteKeyword("MinimumLatitude");
          }
@@ -204,6 +252,7 @@ namespace Isis {
          }
        }
      }
    }

    // Make changes to the output cube label
    if(ocube->hasGroup("Instrument")) {
+7 −0
Changes for isis/src/base/objs/SubArea/SubArea.h: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -51,6 +51,13 @@ namespace Isis {
   *                                         and sinc are not equal, so now
   *                                         this class is more likely to not
   *                                         delete the instrument group.
   *  @history 2013-12-27 Janet Barrett - Modified the UpdateLabel method so that
   *                                      it updates the MinimumLatitude, MaximumLatitude,
   *                                      MinimumLongitude, and MaximumLongitude keywords
   *                                      for equatorial cylindrical projections. All other
   *                                      projections will not have these keywords in their
   *                                      labels because it is not possible to recalculate
   *                                      them for curved projections. Fixes #1500.
   */

  class SubArea {
+127 −0
Changes for isis/src/base/objs/SubArea/SubArea.truth: 127 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -633,3 +633,130 @@ Group = AlphaCube
  BetaLines           = 1347
End_Group

Input Simple Cylindrical projected cube label: 

Group = Dimensions
  Samples = 2259
  Lines   = 3270
  Bands   = 1
End_Group

Group = Instrument
  SpacecraftName        = "MARS GLOBAL SURVEYOR"
  InstrumentId          = MOC-WA
  TargetName            = Mars
  StartTime             = 1997-10-20T10:58:37.46
  StopTime              = 1997-10-20T11:03:44.66
  CrosstrackSumming     = 4
  DowntrackSumming      = 4
  FocalPlaneTemperature = 213.1
  GainModeId            = 1A
  LineExposureDuration  = 100.000000 <milliseconds>
  MissionPhaseName      = AB-1
  OffsetModeId          = 5
  SpacecraftClockCount  = 561812335:32
  RationaleDesc         = "OLYMPUS MONS SPECIAL RED WIDE ANGLE"
  FirstLineSample       = 673
End_Group

Group = Mapping
  ProjectionName     = SimpleCylindrical
  CenterLongitude    = 227.87092862105
  TargetName         = Mars
  EquatorialRadius   = 3396190.0 <meters>
  PolarRadius        = 3376200.0 <meters>
  LatitudeType       = Planetocentric
  LongitudeDirection = PositiveEast
  LongitudeDomain    = 360
  MinimumLatitude    = 10.764699407299
  MaximumLatitude    = 34.460212012267
  MinimumLongitude   = 219.68763086864
  MaximumLongitude   = 236.05422637345
  UpperLeftCornerX   = -485337.86318746 <meters>
  UpperLeftCornerY   = 2042714.0507253 <meters>
  PixelResolution    = 429.50253379421 <meters/pixel>
  Scale              = 138.00779473796 <pixels/degree>
End_Group

Group = AlphaCube
  AlphaSamples        = 640
  AlphaLines          = 768
  AlphaStartingSample = 0.5
  AlphaStartingLine   = 0.5
  AlphaEndingSample   = 640.5
  AlphaEndingLine     = 768.5
  BetaSamples         = 640
  BetaLines           = 768
End_Group

Testing sub image area with linc=1.0, sinc=1.0 for Simple Cylindrical projected cube...

Group = Results
  InputLines      = 3270
  InputSamples    = 2259
  StartingLine    = 2070
  StartingSample  = 818
  EndingLine      = 2270
  EndingSample    = 1018
  LineIncrement   = 1.0
  SampleIncrement = 1.0
  OutputLines     = 201
  OutputSamples   = 201
End_Group

Output cube label: 

Group = Dimensions
  Samples = 201
  Lines   = 201
  Bands   = 1
End_Group

Group = Instrument
  SpacecraftName        = "MARS GLOBAL SURVEYOR"
  InstrumentId          = MOC-WA
  TargetName            = Mars
  StartTime             = 1997-10-20T10:58:37.46
  StopTime              = 1997-10-20T11:03:44.66
  CrosstrackSumming     = 4
  DowntrackSumming      = 4
  FocalPlaneTemperature = 213.1
  GainModeId            = 1A
  LineExposureDuration  = 100.000000 <milliseconds>
  MissionPhaseName      = AB-1
  OffsetModeId          = 5
  SpacecraftClockCount  = 561812335:32
  RationaleDesc         = "OLYMPUS MONS SPECIAL RED WIDE ANGLE"
  FirstLineSample       = 673
End_Group

Group = Mapping
  ProjectionName     = SimpleCylindrical
  CenterLongitude    = 227.87092862105
  TargetName         = Mars
  EquatorialRadius   = 3396190.0 <meters>
  PolarRadius        = 3376200.0 <meters>
  LatitudeType       = Planetocentric
  LongitudeDirection = PositiveEast
  LongitudeDomain    = 360
  MinimumLatitude    = 18.013475287539
  MaximumLatitude    = 19.469914761713
  MinimumLongitude   = 225.60294078316
  MaximumLongitude   = 227.05938025733
  UpperLeftCornerX   = -134434.29307759
  UpperLeftCornerY   = 1154073.3083051
  PixelResolution    = 429.50253379421 <meters/pixel>
  Scale              = 138.00779473796 <pixels/degree>
End_Group

Group = AlphaCube
  AlphaSamples        = 640
  AlphaLines          = 768
  AlphaStartingSample = 0.5
  AlphaStartingLine   = 0.5
  AlphaEndingSample   = 640.5
  AlphaEndingLine     = 768.5
  BetaSamples         = 640
  BetaLines           = 768
End_Group
+68 −0
Changes for isis/src/base/objs/SubArea/unitTest.cpp: 68 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -538,4 +538,72 @@ void IsisMain() {
  imapcube.close();

  results.clear();

  Cube smapcube;
  QString from3 = ui.GetFileName("FROM3");
  smapcube.open(from3);
  inl = smapcube.lineCount();
  ins = smapcube.sampleCount();
  ProcessByLine p11;
  p11.SetInputCube("FROM3");
  sl = 2070;
  ss = 818;
  el = 2270;
  es = 1018;
  linc = 1.0;
  sinc = 1.0;
  onl = (int)ceil((double)(el - sl + 1) / linc);
  ons = (int)ceil((double)(es - ss + 1) / sinc);
  omapcube = p11.SetOutputCube("TO", ons, onl, 1);

  results += PvlKeyword("InputLines", toString(inl));
  results += PvlKeyword("InputSamples", toString(ins));
  results += PvlKeyword("StartingLine", toString(sl));
  results += PvlKeyword("StartingSample", toString(ss));
  results += PvlKeyword("EndingLine", toString(el));
  results += PvlKeyword("EndingSample", toString(es));
  results += PvlKeyword("LineIncrement", toString(linc));
  results += PvlKeyword("SampleIncrement", toString(sinc));
  results += PvlKeyword("OutputLines", toString(onl));
  results += PvlKeyword("OutputSamples", toString(ons));

  s.SetSubArea(inl, ins, sl, ss, el, es, linc, sinc);
  s.UpdateLabel(&smapcube, omapcube, results);

  cout << "Input Simple Cylindrical projected cube label: " << endl << endl;
  inlabel = *smapcube.label();
  cout << inlabel.findObject("IsisCube").findObject("Core").findGroup("Dimensions") << endl << endl;
  if(inlabel.findObject("IsisCube").hasGroup("Instrument")) {
    cout << inlabel.findObject("IsisCube").findGroup("Instrument") << endl << endl;
  }
  if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
    cout << inlabel.findObject("IsisCube").findGroup("Mapping") << endl << endl;
  }
  if(inlabel.findObject("IsisCube").hasGroup("AlphaCube")) {
    cout << inlabel.findObject("IsisCube").findGroup("AlphaCube") << endl << endl;
  }

  cout << "Testing sub image area with linc=1.0, sinc=1.0 ";
  cout << "for Simple Cylindrical projected cube..." << endl;

  Isis::Application::Log(results);
  cout << endl;
  p11.EndProcess();

  cout << "Output cube label: " << endl << endl;
  cube.open(file);
  label = *cube.label();
  cube.close(true);
  cout << label.findObject("IsisCube").findObject("Core").findGroup("Dimensions") << endl << endl;
  if(label.findObject("IsisCube").hasGroup("Instrument")) {
    cout << label.findObject("IsisCube").findGroup("Instrument") << endl << endl;
  }
  if(label.findObject("IsisCube").hasGroup("Mapping")) {
    cout << label.findObject("IsisCube").findGroup("Mapping") << endl << endl;
  }
  if(label.findObject("IsisCube").hasGroup("AlphaCube")) {
    cout << label.findObject("IsisCube").findGroup("AlphaCube") << endl << endl;
  }

  results.clear();
}
+14 −0
Changes for isis/src/base/objs/SubArea/unitTest.xml: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -48,6 +48,20 @@
        </filter>
        <default><item>unitTest_map.cub</item></default>
      </parameter>
      <parameter name="FROM3">
        <type>cube</type>
        <fileMode>input</fileMode>
        <brief>
          Test cube
        </brief>
        <description>
          Test cube
        </description>
        <filter>
          *.cub
        </filter>
        <default><item>unitTest_mapsimp.cub</item></default>
      </parameter>
      <parameter name="TO">
        <type>cube</type>
        <fileMode>output</fileMode>