Commit 7f0e9486 authored by Jeannie Backer's avatar Jeannie Backer
Browse files

Fixed bug in GroundGrid uncovered when virtual Latitude::setAngle signature...

Fixed bug in GroundGrid uncovered when virtual Latitude::setAngle signature was fixed to match virtual Angle::setAngle.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@7147 41f8697f-d340-4b68-9986-7bafba869bb8
parent b8d70538
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -3,9 +3,24 @@ APPNAME = grid
include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) FROM=$(INPUT)/world.cub TO=$(OUTPUT)/truth1.cub \
	LATINC=45 LONINC=45 MODE=GROUND > /dev/null;
	$(APPNAME) FROM=$(INPUT)/world.cub TO=$(OUTPUT)/truth2.cub \
	LATINC=45 LONINC=45 MODE=GROUND ticks=true > /dev/null;
	$(APPNAME) FROM=$(INPUT)/world.cub TO=$(OUTPUT)/truth3.cub \
	LATINC=45 LONINC=45 MODE=GROUND ticks=true diagonal=true > /dev/null;
	$(APPNAME) FROM=$(INPUT)/world.cub \
	           TO=$(OUTPUT)/truth1.cub \
	           LATINC=45 \
			   LONINC=45 \
			   MODE=GROUND \
			   > /dev/null;
	$(APPNAME) FROM=$(INPUT)/world.cub \
	           TO=$(OUTPUT)/truth2.cub \
	           LATINC=45 \
			   LONINC=45 \
			   MODE=GROUND \
			   ticks=true \
			   > /dev/null;
	$(APPNAME) FROM=$(INPUT)/world.cub \
	           TO=$(OUTPUT)/truth3.cub \
	           LATINC=45 \
			   LONINC=45 \
			   MODE=GROUND \
			   ticks=true \
			   diagonal=true \
			   > /dev/null;
+145 −118
Original line number Diff line number Diff line
@@ -29,8 +29,10 @@ namespace Isis {
   * @param width The width of the grid; often cube samples
   * @param height The height of the grid; often cube samples
   */
  GroundGrid::GroundGrid(UniversalGroundMap *gmap, bool splitLatLon,
                         unsigned int width, unsigned int height) {
  GroundGrid::GroundGrid(UniversalGroundMap *gmap, 
                         bool splitLatLon,
                         unsigned int width, 
                         unsigned int height) {
    p_width = width;
    p_height = height;

@@ -86,17 +88,18 @@ namespace Isis {
        Distance::Meters);

    if (p_mapping->hasKeyword("MinimumLatitude")) {
      p_minLat = new Latitude(
          toDouble((*p_mapping)["MinimumLatitude"][0]), *p_mapping,
          Angle::Degrees);
      p_minLat = new Latitude(toDouble((*p_mapping)["MinimumLatitude"][0]), 
                              *p_mapping,
                              Angle::Degrees, 
                              Latitude::AllowPastPole);
    }
    else {
      p_minLat = new Latitude;
    }

    if (p_mapping->hasKeyword("MaximumLatitude")) {
      p_maxLat = new Latitude(
          toDouble((*p_mapping)["MaximumLatitude"][0]), *p_mapping,
      p_maxLat = new Latitude(toDouble((*p_mapping)["MaximumLatitude"][0]), 
                              *p_mapping,
                              Angle::Degrees);
    }
    else {
@@ -104,8 +107,8 @@ namespace Isis {
    }

    if (p_mapping->hasKeyword("MinimumLongitude")) {
      p_minLon = new Longitude(
          toDouble((*p_mapping)["MinimumLongitude"][0]), *p_mapping,
      p_minLon = new Longitude(toDouble((*p_mapping)["MinimumLongitude"][0]), 
                               *p_mapping,
                               Angle::Degrees);
    }
    else {
@@ -113,8 +116,8 @@ namespace Isis {
    }

    if (p_mapping->hasKeyword("MaximumLongitude")) {
      p_maxLon = new Longitude(
          toDouble((*p_mapping)["MaximumLongitude"][0]), *p_mapping,
      p_maxLon = new Longitude(toDouble((*p_mapping)["MaximumLongitude"][0]), 
                               *p_mapping,
                               Angle::Degrees);
    }
    else {
@@ -202,8 +205,10 @@ namespace Isis {
   * @param lonInc  Distance between longitude lines
   * @param progress If passed in, this progress will be used
   */
  void GroundGrid::CreateGrid(Latitude baseLat, Longitude baseLon,
                              Angle latInc,  Angle lonInc,
  void GroundGrid::CreateGrid(Latitude baseLat, 
                              Longitude baseLon,
                              Angle latInc,  
                              Angle lonInc,
                              Progress *progress) {
    CreateGrid(baseLat, baseLon, latInc, lonInc, progress, Angle(), Angle());
  }
@@ -221,10 +226,13 @@ namespace Isis {
   * @param latRes  Resolution of latitude lines (in degrees/pixel)
   * @param lonRes  Resolution of longitude lines (in degrees/pixel)
   */
  void GroundGrid::CreateGrid(Latitude baseLat, Longitude baseLon,
                              Angle latInc,  Angle lonInc,
  void GroundGrid::CreateGrid(Latitude baseLat, 
                              Longitude baseLon,
                              Angle latInc,  
                              Angle lonInc,
                              Progress *progress,
                              Angle latRes, Angle lonRes) {
                              Angle latRes, 
                              Angle lonRes) {
    if (p_groundMap == NULL ||
        (p_grid == NULL && p_latLinesGrid == NULL && p_lonLinesGrid == NULL)) {
      IString msg = "GroundGrid::CreateGrid missing ground map or grid array";
@@ -283,23 +291,23 @@ namespace Isis {
    p_reinitialize = true;

    // Find starting points for lat/lon
    Latitude startLat = Latitude(
        baseLat - Angle(floor((baseLat - *p_minLat) / latInc) * latInc),
        *GetMappingGroup());
    Latitude startLat = Latitude(baseLat - Angle(floor((baseLat - *p_minLat) / latInc) * latInc),
                                 *GetMappingGroup(), 
                                 Latitude::AllowPastPole);

    Longitude startLon = Longitude(
        baseLon - Angle(floor((baseLon - *p_minLon) / lonInc) * lonInc));
    Longitude startLon = Longitude(baseLon - Angle(floor((baseLon - *p_minLon) / lonInc) * lonInc));

    if (!latRes.isValid() || latRes <= Angle(0, Angle::Degrees)) {
      latRes = Angle(p_defaultResolution, Angle::Degrees);
      latRes = Angle(p_defaultResolution, 
                     Angle::Degrees);
    }

    if (!lonRes.isValid() || lonRes <= Angle(0, Angle::Degrees)) {
      lonRes = Angle(p_defaultResolution, Angle::Degrees);
      lonRes = Angle(p_defaultResolution, 
                     Angle::Degrees);
    }

    Latitude endLat = Latitude(
        (long)((*p_maxLat - startLat) / latInc) * latInc + startLat,
    Latitude endLat = Latitude((long)((*p_maxLat - startLat) / latInc) * latInc + startLat,
                               *GetMappingGroup());
    Longitude endLon =
        (long)((*p_maxLon - startLon) / lonInc) * lonInc + startLon;
@@ -503,6 +511,16 @@ namespace Isis {
  }


  /**
   * Returns a mapping group representation of the projection or camera.
   * This is useful for matching units with lat/lons.
   *
   * @returns Returns a mapping group representation of the projection or camera
   */
  PvlGroup *GroundGrid::GetMappingGroup() { 
    return p_mapping; 
  }

  /**
   * This method converts a lat/lon to an X/Y. This implementation converts to
   * sample/line.
@@ -530,6 +548,15 @@ namespace Isis {
  }


  /** 
   * Returns the ground map for children
   * 
   */
  UniversalGroundMap *GroundGrid::GroundMap() {
    return p_groundMap;
  }


  /**
   * This flags a bit as on the grid lines.
   *
+43 −36
Original line number Diff line number Diff line
@@ -40,65 +40,72 @@ namespace Isis {
   * @author 2010-01-06 Steven Lambright
   *
   * @internal
   *   @history 2010-05-06 Steven Lambright - Added Split Lat/Lon
   *                           Functionality
   *   @history 2010-05-06 Steven Lambright - Added Split Lat/Lon functionality
   *   @history 2010-06-22 Steven Lambright - Improved handling of resolutions
   *   @history 2011-01-25 Steven Lambright - Now uses native units to the
   *                           projection, Lat/Lon classes, and several bug
   *                           fixes when it comes to out of range values or
   *                           non-standard projection types.
   *   @history 2011-01-26 Steven Lambright - Fixed a bug where the grid was not
   *                           consistent on the edges and added SetGroundLimits
   *                           and WalkBoundary for the new grid options Bound
   *                           lat/lon range.
   *   @history 2011-02-25 Steven Lambright - Min/Max Lat/Lons do not have
   *                           to be known in the constructor any more
   *   @history 2011-12-08 Steven Lambright - Fixed a bug causing the longitude
   *                           range to be incorrect. Fixes #607.
   *   @history 2014-06-06 Kristin Berry - Fixed a bug where lat/lon were swapped
   *                           in the code. Fixes #2081.
   *          
   *   @history 2011-01-25 Steven Lambright - Now uses native units to the projection,
   *                           Lat/Lon classes, and several bug fixes when it comes to
   *                           out of range values or non-standard projection types.
   *   @history 2011-01-26 Steven Lambright - Fixed a bug where the grid was not consistent
   *                           on the edges and added SetGroundLimits and WalkBoundary
   *                           for the new grid options Bound lat/lon range.
   *   @history 2011-02-25 Steven Lambright - Min/Max Lat/Lons do not have to be known
   *                           in the constructor any more
   *   @history 2011-12-08 Steven Lambright - Fixed a bug causing the longitude range
   *                           to be incorrect. Fixes #607.
   *   @history 2014-06-06 Kristin Berry - Fixed a bug where lat/lon were swapped in the code.
   *                           Fixes #2081.
   *   @history 2016-09-29 Jeannie Backer - Changed Latitude objects that were created with
   *                           Latitude's mapping group constructor to have enum value
   *                           Latitude::AllowPastPole. This was done for p_minLat in the
   *                           GroundGrid constructor and for startLat in the CreateGrid()
   *                           method. The reason for this is that these objects are copied
   *                           to initialize another Latitude variable (lat) within for-loops
   *                           that go past the poles. Thus lat must be allowed to go past
   *                           the poles. This bug was uncovered when Latitude's virtual setAngle()
   *                           method was fixed to match the signature of the parent method.
   *                           Moved implementation of GroundMap() and GetMappingGroup() to the
   *                           cpp file per ISIS coding standards.
   */
  class GroundGrid {
    public:
      GroundGrid(UniversalGroundMap *gmap, bool splitLatLon,
                 unsigned int width, unsigned int height);
      GroundGrid(UniversalGroundMap *gmap, 
                 bool splitLatLon,
                 unsigned int width, 
                 unsigned int height);

      virtual ~GroundGrid();

      void CreateGrid(Latitude baseLat, Longitude baseLon,
                      Angle latInc,  Angle lonInc,
      void CreateGrid(Latitude baseLat, 
                      Longitude baseLon,
                      Angle latInc,  
                      Angle lonInc,
                      Progress *progress = 0);

      void CreateGrid(Latitude baseLat, Longitude baseLon,
                      Angle latInc,  Angle lonInc,
      void CreateGrid(Latitude baseLat, 
                      Longitude baseLon,
                      Angle latInc,  
                      Angle lonInc,
                      Progress *progress,
                      Angle latRes, Angle lonRes);
                      Angle latRes, 
                      Angle lonRes);

      void WalkBoundary();

      void SetGroundLimits(Latitude minLat, Longitude minLon, Latitude maxLat,
      void SetGroundLimits(Latitude minLat, 
                           Longitude minLon, 
                           Latitude maxLat,
                           Longitude maxLon);

      bool PixelOnGrid(int x, int y);
      bool PixelOnGrid(int x, int y, bool latGrid);

      /**
       * Returns a mapping group representation of the projection or camera.
       * This is useful for matching units with lat/lons.
       *
       * @returns Returns a mapping group representation of the projection or camera
       */
      PvlGroup *GetMappingGroup() { return p_mapping; }
      PvlGroup *GetMappingGroup();

    protected:
      virtual bool GetXY(Latitude lat, Longitude lon,
                         unsigned int &x, unsigned int &y);

      //! Returns the ground map for children
      UniversalGroundMap *GroundMap() {
        return p_groundMap;
      }
      UniversalGroundMap *GroundMap();

    private:
      void SetGridBit(unsigned int x, unsigned int y, bool latGrid);
+12 −12
Original line number Diff line number Diff line
@@ -328,7 +328,7 @@ namespace Isis {
  double Latitude::planetographic(Angle::Units units) const {
    
    if (m_equatorialRadius == NULL || m_polarRadius == NULL) {
      QString msg = "Latitude [" + toString(degrees()) + " degrees] cannot "
      QString msg = "Latitude [" + toString(true) + "] cannot "
          "be converted to Planetographic without the planetary radii, please "
          "use the other Latitude constructor.";
      throw IException(IException::Programmer, msg, _FILEINFO_);
@@ -373,7 +373,7 @@ namespace Isis {
  void Latitude::setPlanetographic(double latitude, Angle::Units units) {
    
    if (m_equatorialRadius == NULL || m_polarRadius == NULL) {
      QString msg = "Latitude [" + Isis::toString(latitude) + "] cannot be "
      QString msg = "Latitude [" + Isis::toString(latitude) + " degrees] cannot be "
          "converted to Planetocentic without the planetary radii, please use "
          "the other Latitude constructor.";
      throw IException(IException::Programmer, msg, _FILEINFO_);
@@ -425,9 +425,9 @@ namespace Isis {
    
    // Validity check on the range
    if (min > max) {
      QString msg = "Minimum latitude [" + toString(min.degrees()) + 
                    "] degrees is greater than maximum latitude [" + 
                    toString(max.degrees()) + "] degrees";
      QString msg = "Minimum latitude [" + min.toString(true) + 
                    "] is greater than maximum latitude [" + 
                    max.toString(true) + "]";
      throw IException(IException::User, msg, _FILEINFO_);
    }

@@ -534,7 +534,9 @@ namespace Isis {
   * 
   * @return The result of adding another latitude
   */
  Latitude Latitude::add(Angle angleToAdd, Distance equatorialRadius, Distance polarRadius,
  Latitude Latitude::add(Angle angleToAdd, 
                         Distance equatorialRadius, 
                         Distance polarRadius,
                         CoordinateType latType) {
    Latitude result;

@@ -556,16 +558,15 @@ namespace Isis {

  /**
   * We're overriding this method in order to do -90/90 degree checking
   *d
   *
   * @param angle The numeric value of the angle
   * @param units The units the angle is in (radians or degrees typically)
   * 
   * @throws IException::Programmer "Latitudes past 90 degrees are not valid. 
   *     The latitude is not allowed"
   */
  void Latitude::setAngle(const double &angle, const Angle::Units &units) {
    
    
  void Latitude::setAngle(const double &angle, 
                          const Angle::Units &units) {
    
    // Check for passing 90 degrees if that error checking is on
    if (!IsSpecial(angle) && (m_errors & AllowPastPole) != AllowPastPole) {
@@ -573,11 +574,10 @@ namespace Isis {
      if (tmpAngle > Angle(90, Angle::Degrees) ||
          tmpAngle < Angle(-90, Angle::Degrees)) {
        QString msg = "Latitudes past 90 degrees are not valid. The latitude [" 
                      + toString(tmpAngle.degrees()) + " degrees] is not allowed";
                      + Isis::toString(tmpAngle.degrees(), 8) + "] is not allowed";
        throw IException(IException::Programmer, msg, _FILEINFO_);
      }
    }

    Angle::setAngle(angle, units);
  }
}
+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ namespace Isis {
   *                           Latitude::Latitude(double latitude, PvlGroup mapping, 
   *                           Angle::Units latitudeUnits, ErrorChecking errors) and added in
   *                           documentation for all exceptions thrown. Fixes #3907
   *   @history 2016-09-29 Jeannie Backer - Changed strings in error message to use Angle::toString
   *                           instead of the Isis::toString(double) method.
   */
  class Latitude : public Angle {
    public:
Loading