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

Fixed bug in the calculation of the local normal vector for DEMs with...

Fixed bug in the calculation of the local normal vector for DEMs with non-equatorial cylindrical projections. Fixes #2243

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6171 41f8697f-d340-4b68-9986-7bafba869bb8
parent c411474b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -39,8 +39,7 @@ int main(int argc, char *argv[]) {
  catch (IException &e) {
    qDebug();
    qDebug();
    IException(e, IException::Programmer,
              "\n------------Unit Test Failed.------------",
              _FILEINFO_).print();
    QString msg = "**************** UNIT TEST FAILED! **************** ";
    IException(e, IException::Unknown, msg, _FILEINFO_).print();
  }
}
+21 −13
Original line number Diff line number Diff line
@@ -1250,15 +1250,24 @@ namespace Isis {
      return;
    }

    QVector<double *> cornerNeighborPoints(4);
    // The DEM shape model (and it's child classes) will use 4 surrounding neighbor
    // points to find the local normal. The SetImage() calls used to find the
    // neighbors is potentially expensive, so we will not calculate the neighbors
    // for shape models whose calculateLocalNormal() method won't use them.
    bool computed = p_pointComputed;
    if (QString::compare(shapeModel->name(), "DemShape", Qt::CaseInsensitive) == 0) {
      // If the shape model is not DEM, we don't use the neighbor points.
      // So, to avoid the potetially expesive SetImage() calls used to find the neighbors,
      // just pass in empty vector to shape model's calculateLocalNormal() method
      shapeModel->calculateLocalNormal(cornerNeighborPoints);
    if (!shapeModel->isDEM()) {
      // Non-DEM case: Ellipsoid, NAIF DSK, or Plane --
      // Pass in a vector where all of the "neighbors" are the origin (shape model center).
      // We do this so that if the implementation of the calculateLocalNormal() method in
      // any of the non-DEM shape model classes is modified to use this vector, then an error
      // should be thrown instead of a segmentation fault.
      QVector<double *> unusedNeighborPoints(4);
      double origin[3] = {0, 0, 0};
      unusedNeighborPoints.fill(origin);
      shapeModel->calculateLocalNormal(unusedNeighborPoints);
    }
    else { // attempt to find local normal for DEM shapes using 4 surrounding points on the image
      QVector<double *> cornerNeighborPoints(4);

      // As documented in the doxygen above, the goal of this method is to
      // calculate a normal vector to the surface using the 4 corner surrounding points.
@@ -1294,9 +1303,8 @@ namespace Isis {

          // If the original point fails too, we can't get a normal.  Clean up and return.
          if (!(SetImage(surroundingPoints[i].first, surroundingPoints[i].second))) {
            normal[0] = 0.;
            normal[1] = 0.;
            normal[2] = 0.;

            normal[0] = normal[1] = normal[2] = 0.0;

            // restore input state
            if (computed) {
@@ -1329,9 +1337,8 @@ namespace Isis {
          surroundingPoints[0].second == surroundingPoints[1].second) ||
         (surroundingPoints[2].first == surroundingPoints[3].first &&
          surroundingPoints[2].second == surroundingPoints[3].second)) {
        normal[0] = 0.;
        normal[1] = 0.;
        normal[2] = 0.;

        normal[0] = normal[1] = normal[2] = 0.0;

        // restore input state
        if (!computed) {
@@ -1353,8 +1360,9 @@ namespace Isis {
      shapeModel->calculateLocalNormal(cornerNeighborPoints);

      // free memory
      for (int i = 0; i < cornerNeighborPoints.size(); i++)
      for (int i = 0; i < cornerNeighborPoints.size(); i++) {
        delete [] cornerNeighborPoints[i];
      }
   
    }

+2 −0
Original line number Diff line number Diff line
@@ -244,6 +244,8 @@ namespace Isis {
   *   @history 2015-03-14 Jeannie Backer - Modified GetLocalNormal() to call non-DEM shapes'
   *                           calculateLocalNormal() with an empty vector of neighbors since only
   *                           DemShape uses this vector. References #2035.
   *   @history 2015-04-30 Jeannie Backer - Fixed bug in GetLocalNormal() introduced in prior
   *                           check-in. Fixes #2243.
   */

  class Camera : public Sensor {
+23 −13
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ Line: 453, Sample: 534
Lat: 18.221, Lon: 226.671
RightAscension: 347.016, Declination: -51.2677

SetImage (sample, line): 1
SetImage (sample, line): Yes

NorthAzimuth: 269.544
SunAzimuth: 168.17
@@ -220,7 +220,7 @@ Point = -2225 -2359 1068
Test Forward/Reverse Camera Calculations At Center Of Image...
Sample = 480
Line = 702
SetImage (sample, line): 1
SetImage (sample, line): Yes
Latitude = 22.6
Longitude = 228
Radius = 3.4e+06
@@ -262,7 +262,7 @@ Longitude Range: -180 to 180
Test Forward/Reverse Camera Calculations At Center Of Image...
Sample = 192
Line = 144
SetImage (sample, line): 1
SetImage (sample, line): Yes
Latitude = 89.18
Longitude = 13.54
Radius = 1.736e+06
@@ -278,7 +278,7 @@ Flat DEM Surface...
Camera* from: $base/testData/f319b18_ideal_flat.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = 0.03228, 0.1276, -0.9913
Phase = 57.32
Emission = 59.59
@@ -288,7 +288,7 @@ Incidence = 2.835
Camera* from: $base/testData/f319b18_ideal_45left.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = 0.7105, -0.08428, -0.6986
Phase = 57.32
Emission = 60.94
@@ -298,7 +298,7 @@ Incidence = 46.41
Camera* from: $base/testData/f319b18_ideal_45top.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = 0.1945, 0.7705, -0.607
Phase = 57.32
Emission = 17.41
@@ -308,7 +308,7 @@ Incidence = 42.49
Camera* from: $base/testData/f319b18_ideal_45right.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = -0.6648, 0.264, -0.6988
Phase = 57.32
Emission = 76.84
@@ -318,7 +318,7 @@ Incidence = 44.07
Camera* from: $base/testData/f319b18_ideal_45bottom.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = -0.1491, -0.5904, -0.7932
Phase = 57.32
Emission = 103.8
@@ -328,7 +328,7 @@ Incidence = 47.67
Camera* from: $base/testData/f319b18_ideal_80left.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = 0.9617, -0.2209, -0.1622
Phase = 57.32
Emission = 74.77
@@ -338,7 +338,7 @@ Incidence = 81.75
Camera* from: $base/testData/f319b18_ideal_80top.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = 0.2423, 0.9696, -0.03452
Phase = 57.32
Emission = 23.84
@@ -348,7 +348,7 @@ Incidence = 77.87
Camera* from: $base/testData/f319b18_ideal_80right.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = -0.9512, 0.2624, -0.1626
Phase = 57.32
Emission = 95.57
@@ -358,7 +358,7 @@ Incidence = 79.42
Camera* from: $base/testData/f319b18_ideal_80bottom.cub
Sample = 625
Line = 575
SetImage (sample, line): 1
SetImage (sample, line): Yes
Normal = -0.231, -0.9267, -0.2965
Phase = 57.32
Emission = 138.2
@@ -368,10 +368,20 @@ Point Does Not Intersect DEM...
Camera* from: $base/testData/f319b18_ideal_flat.cub
Sample = 1
Line = 1
SetImage (sample, line): 0
SetImage (sample, line): No
Normal = 0, 0, 0
Angles could not be calculated.

Cube with Ellipsoidal Shape Model...
Camera* from: $base/testData/CM_1515945709_1.ir.cub
Sample = 20
Line = 20
SetImage (sample, line): Yes
Normal = -0.4343, -0.2875, -0.8536
Phase = 35.54
Emission = 48.1
Incidence = 59.11


Testing non-square pixel Ifov using Hires vims cube
Camera* from: $base/testData/CM_1515945709_1.ir.cub
+56 −13
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include "CameraFactory.h"
#include "Cube.h"
#include "IException.h"
#include "IString.h"
#include "Latitude.h"
#include "Longitude.h"
#include "PixelIfov.h"
@@ -35,6 +36,22 @@
using namespace std;
using namespace Isis;


/**
 * Unit test for Camera class
 *
 *
 * @author 2010-07-30 Debbie A. Cook
 *
 * @internal
 *   @history 2015-04-30 Jeannie Backer - Added call to GetLocalNormal() for cube ellipsoidal
 *                           (i.e. non-DEM) shape model. References #2243.
 *  
 *  
 *  
 *   testcoverage 2015-04-30 - 43.262% scope, 61.561% line, 87.5% function
 */

class MyCamera : public Camera {
  public:
    MyCamera(Cube &cube) : Camera(cube) { }
@@ -58,6 +75,7 @@ class MyCamera : public Camera {
};

int main() {
  try {
    Preference::Preferences(true);
    QString inputFile = "$mgs/testData/ab102401.lev2.cub";
    Cube cube;
@@ -83,7 +101,7 @@ int main() {
    cout << "Lat: " << lat.degrees() << ", Lon: " << lon.degrees() << endl;
    cout << "RightAscension: " << ra << ", Declination: " << dec << endl << endl;

  cout << "SetImage (sample, line): " << c->SetImage(sample, line)
    cout << "SetImage (sample, line): " << toString(c->SetImage(sample, line))
         << endl << endl;

    cout << "NorthAzimuth: " << c->NorthAzimuth() << endl;
@@ -201,7 +219,7 @@ int main() {
    line = c->Lines() / 2.0;
    cout << "Sample = " << setprecision(3) << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << c->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(c->SetImage(sample, line)) << endl;
    cout << "Latitude = " << c->UniversalLatitude() << endl;
    cout << "Longitude = " << c->UniversalLongitude() << endl;
    cout << "Radius = " << c->LocalRadius().meters() << endl;
@@ -269,7 +287,7 @@ int main() {
    line = cam2->Lines() / 2.0;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam2->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam2->SetImage(sample, line)) << endl;
    cout << "Latitude = " << cam2->UniversalLatitude() << endl;
    cout << "Longitude = " << cam2->UniversalLongitude() << endl;
    cout << "Radius = " << cam2->LocalRadius().meters() << endl;
@@ -300,7 +318,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam3->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam3->SetImage(sample, line)) << endl;
    double normal[3];
    cam3->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
@@ -331,7 +349,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam4->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam4->SetImage(sample, line)) << endl;
    cam4->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam4->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -357,7 +375,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam5->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam5->SetImage(sample, line)) << endl;
    cam5->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam5->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -383,7 +401,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam6->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam6->SetImage(sample, line)) << endl;
    cam6->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam6->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -409,7 +427,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam7->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam7->SetImage(sample, line)) << endl;
    cam7->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam7->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -435,7 +453,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam8->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam8->SetImage(sample, line)) << endl;
    cam8->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam8->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -461,7 +479,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam9->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam9->SetImage(sample, line)) << endl;
    cam9->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam9->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -487,7 +505,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam10->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam10->SetImage(sample, line)) << endl;
    cam10->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam10->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -513,7 +531,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam11->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam11->SetImage(sample, line)) << endl;
    cam11->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam11->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -539,7 +557,7 @@ int main() {
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
  cout << "SetImage (sample, line): " << cam12->SetImage(sample, line) << endl;
    cout << "SetImage (sample, line): " << toString(cam12->SetImage(sample, line)) << endl;
    cam12->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam12->LocalPhotometricAngles(phase,emission,incidence,success);
@@ -555,11 +573,30 @@ int main() {

    //  Test PixelIfov for Vims which sets the field of view if it in hires mode.  The Ifov is
    //  rectangular instead of square.
    cout << endl << "Cube with Ellipsoidal Shape Model..." << endl;
    inputFile = "$base/testData/CM_1515945709_1.ir.cub";
    cube.open(inputFile);
    Camera *cam13 = CameraFactory::Create(cube);
    cube.close();

    sample = 20.0;
    line = 20.0;
    cout << "Camera* from: " << inputFile << endl;
    cout << "Sample = " << sample << endl;
    cout << "Line = " << line << endl;
    cout << "SetImage (sample, line): " << toString(cam13->SetImage(sample, line)) << endl;
    cam13->GetLocalNormal(normal);
    cout << "Normal = " << normal[0] << ", " << normal[1] << ", " << normal[2] << endl;
    cam13->LocalPhotometricAngles(phase,emission,incidence,success);
    if (success) {
      cout << "Phase = " << phase.degrees() << endl;
      cout << "Emission = " << emission.degrees() << endl;
      cout << "Incidence = " << incidence.degrees() << endl;
    } 
    else {
      cout << "Angles could not be calculated." << endl;
    }

    cout << endl << endl << "Testing non-square pixel Ifov using Hires vims cube" << endl;
    cout << "Camera* from: " << inputFile << endl;
    ifovOffsets = cam13->PixelIfovOffsets();
@@ -569,3 +606,9 @@ int main() {
    }
    delete cam13;
  }
  catch (IException &e) {
    cout << endl << endl;
    QString msg = "**************** UNIT TEST FAILED! **************** ";
    IException(e, IException::Unknown, msg, _FILEINFO_).print();
  }
}
Loading