Commit 4e5bc792 authored by Jeannie Backer's avatar Jeannie Backer
Browse files

PROG: Fixed bug in TGO CaSSIS distortion map and updated unitTest for its camera.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7544 41f8697f-d340-4b68-9986-7bafba869bb8
parent e5c1d3a2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
Unit Test for TgoCassisCamera...
FileName:  "CAS-MCO-2016-11-22T16.38.39.354-NIR-02036-B1.cub"
FileName:  "CAS-MCO-2016-11-22T16.38.39.354-NIR-02036-00.cub"
CK Frame:  -143420

Kernel IDs: 
+42 −23
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ namespace Isis {
                                                 int naifIkCode) 
      : CameraDistortionMap(parent) {

    m_width = 2048;
    m_height = 2048;

    QString od = "INS" + toString(naifIkCode) + "_OD_";

    for(int i = 0; i < 6; i++) {
@@ -77,8 +80,8 @@ namespace Isis {
    p_focalPlaneY = dy;

    // i and j are normalized distorted coordinates
    double i = normalize(dx);
    double j = normalize(dy);
    double i = normalize(dx, m_width,  m_height);
    double j = normalize(dy, m_height, m_width);

    // convenience variables
    double i2 = i*i;
@@ -110,8 +113,8 @@ namespace Isis {
                   / divider;

    // denormalize ideal (x,y) coordinates
    p_undistortedFocalPlaneX = denormalize(xNorm);
    p_undistortedFocalPlaneY = denormalize(yNorm);
    p_undistortedFocalPlaneX = denormalize(xNorm, m_width,  m_height);
    p_undistortedFocalPlaneY = denormalize(yNorm, m_height, m_width);

    return true;
  }
@@ -131,8 +134,8 @@ namespace Isis {
    p_undistortedFocalPlaneY = uy;

    // x, y are normalized undistorted (ideal) coordinates
    double xNorm = normalize(ux);
    double yNorm = normalize(uy);
    double xNorm = normalize(ux, m_width,  m_height);
    double yNorm = normalize(uy, m_height, m_width);

    // i, j are distorted coordinates
    double iNorm = xNorm;
@@ -146,6 +149,11 @@ namespace Isis {
       * F_vec(i,j) = [ initialX - ( A1 * chi' ) / ( A3 * chi' ) ]
       *              [ initialY - ( A2 * chi' ) / ( A3 * chi' ) ]
      */
      m_width = 0.0; 
      m_height = 0.0; // Below we call SetFocalPlane(). This method normalizes its inputs, i.e.
                      // iNorm and jNorm in this case. Since they are already normalized, we 
                      // set height = weight = 0.0 so that normalize(value) just
                      // returns value.

      if (SetFocalPlane(iNorm, jNorm) ) {
        double xPredict = p_undistortedFocalPlaneX;
@@ -203,47 +211,58 @@ namespace Isis {
      }

    }
    m_width = 2048;
    m_height = 2048;

    p_undistortedFocalPlaneX = ux;
    p_undistortedFocalPlaneY = uy;
    // denormalize distorted (i,j) coordinates
    p_focalPlaneX = denormalize(iNorm);
    p_focalPlaneY = denormalize(jNorm);
    p_focalPlaneX = denormalize(iNorm, m_width,  m_height);
    p_focalPlaneY = denormalize(jNorm, m_height, m_width);
    return true;
  }


  /**
   * Normalize the value using the dimensions of the CCD, 2048 x 2048. This 
   * method uses the formula below to normalize the given value: 
   * Normalize the value using the given scalars. This method uses the formula 
   * below to normalize the given value: 
   *  
   *  @f[ norm = \frac{ value - \frac{2048}{2} }{ 2048 + 2048 } @f]
   *  @f[ norm = \frac{ value - \frac{a}{2} }{ a + b } @f]
   * 
   * @param value Value to be normalize.
   * @param a Primary scaling value.
   * @param b Secondary scaling value.
   * 
   * @return @b double The normalized value.
   */
  double TgoCassisDistortionMap::normalize(double value) {
    // use scaling factor based on size of CCD:
    // CCD width = CCD height = 2048
    return (value - 2048 / 2) / 4096;
  double TgoCassisDistortionMap::normalize(double value, double a, double b) {
    double sum = a + b;
    if (sum == 0) {
      return value;
    }
    return (value - a / 2) / sum;
  }


  /**
   * De-normalize the value using the dimensions of the CCD, 2048 x 2048. 
   * This method is the inverse function of the normalize() function. It 
   * uses the formula below to denormalize the given value: 
   * De-normalize the value using the given scalars. This method is the 
   * inverse function of the normalize() function. It uses the formula below 
   * to denormalize the given value: 
   *  
   *  @f[ denorm = value * (2048 + 2048) + \frac{2048}{2} @f]
   *  @f[ denorm = value * (a + b) + \frac{a}{2} @f]
   * 
   * @param value Value to be normalize.
   * @param a Primary scaling value.
   * @param b Secondary scaling value.
   * 
   * @return @b double The normalized value.
   */
  double TgoCassisDistortionMap::denormalize(double value) {
    // use scaling factor based on size of CCD:
    // CCD width = CCD height = 2048
    return value * 4096 + 2048 / 2;
  double TgoCassisDistortionMap::denormalize(double value, double a, double b) {
    double sum = a + b;
    if (sum == 0) {
      return value;
    }
    return value * sum + a / 2;
  }
  
}
+6 −2
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ namespace Isis {
   *
   * @internal
   *   @history 2017-04-03 Jeannie Walldren - Original version.
   *   @history 2017-04-06 Jeannie Walldren - Fixed bugs and updated unitTest.
   */
  class TgoCassisDistortionMap : public CameraDistortionMap {
    public:
@@ -54,8 +55,11 @@ namespace Isis {
      virtual bool SetUndistortedFocalPlane(const double ux, const double uy);

    private:
      double normalize(double value);
      double denormalize(double value);
      double normalize(double value, double a, double b);
      double denormalize(double value, double a, double b);

      double m_width;   //!< The width of the CaSSIS CCD, used to normalize/denormalize variables.
      double m_height;  //!< The height of the CaSSIS CCD, used to normalize/denormalize variables.

      QList<double> m_A1; //!< First row of parameters of rational distortion model.
      QList<double> m_A2; //!< Second row of parameters of rational distortion model.
+3 −6
Original line number Diff line number Diff line
@@ -45,13 +45,10 @@ int main(void) {
    // These should be lat/lon at center of image. To obtain these numbers for a new cube/camera,
    // set both the known lat and known lon to zero and copy the unit test output
    // "Latitude off by: " and "Longitude off by: " values directly into these variables.
    double knownLat = 4.26586442746858552;
    double knownLon = 322.710822868154423;
    // orginal before distortion model: double knownLat = 4.1185046573490665;
    // orginal before distortion model: double knownLon = 322.6163976791718824;
    double knownLat = 4.33164869218781323; // before distortion model:   4.1185046573490665;
    double knownLon = 322.715872037511133; // before distortion model: 322.6163976791718824;

//    Cube c("$tgo/testData/CAS-MCO-2016-11-22T16.38.39.354-NIR-02036-B1.cub", "r");
    Cube c("CAS-MCO-2016-11-22T16.38.39.354-NIR-02036-B1.cub", "r");
    Cube c("$tgo/testData/CAS-MCO-2016-11-22T16.38.39.354-NIR-02036-00.cub", "r");
    TgoCassisCamera *cam = (TgoCassisCamera *) CameraFactory::Create(c);
    qDebug() << "FileName: " << FileName(c.fileName()).name();
    qDebug() << "CK Frame: " << cam->instrumentRotation()->Frame();