Commit 9ee80d2c authored by Christopher Combs's avatar Christopher Combs
Browse files

Prog: Changed loop counters to long ints to prevent overflow. Fixes #4611

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7784 41f8697f-d340-4b68-9986-7bafba869bb8
parent b2d1fd6f
Loading
Loading
Loading
Loading
+164 −139
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@
#include "UniqueIOCachingAlgorithm.h"

using namespace std;


namespace Isis {
  /**
   * Constructs a ProcessRubberSheet class with the default tile size range
@@ -46,6 +48,7 @@ namespace Isis {
   * @param endSize Minimum size of output tiles for reverse driven geom
   */
  ProcessRubberSheet::ProcessRubberSheet(int startSize, int endSize) {

    p_bandChangeFunct = NULL;

    // Information used only in the tile transform method (StartProcess)
@@ -63,6 +66,7 @@ namespace Isis {
    m_patchLineIncrement = 4;
  };


  /**
   * This method allows the programmer to override the default values for patch
   * parameters used in the patch transform method (processPatchTransform)
@@ -113,6 +117,7 @@ namespace Isis {
  void ProcessRubberSheet::setPatchParameters(int startSample, int startLine,
                             int samples, int lines,
                             int sampleIncrement, int lineIncrement) {

    m_patchStartSample = startSample;
    m_patchStartLine = startLine;
    m_patchSamples = samples;
@@ -121,6 +126,7 @@ namespace Isis {
    m_patchLineIncrement = lineIncrement;
  }


  /**
   * Applies a Transform and an Interpolator to every pixel in the output cube.
   * The output cube is written using an Tile and the input cube is read using
@@ -140,6 +146,7 @@ namespace Isis {
   */
  void ProcessRubberSheet::StartProcess(Transform &trans,
                                        Interpolator &interp) {

    // Error checks ... there must be one input and one output
    if (InputCubes.size() != 1) {
      string m = "You must specify exactly one input cube";
@@ -177,9 +184,9 @@ namespace Isis {
      InputCubes[0]->addCachingAlgorithm(new UniqueIOCachingAlgorithm(2 * InputCubes[0]->bandCount()));
      OutputCubes[0]->addCachingAlgorithm(new BoxcarCachingAlgorithm());

      int tilesPerBand = otile.Tiles() / OutputCubes[0]->bandCount();
      long long int tilesPerBand = otile.Tiles() / OutputCubes[0]->bandCount();

      for(int tile = 1; tile <= tilesPerBand; tile++) {
      for (long long int tile = 1; tile <= tilesPerBand; tile++) {
        bool useLastTileMap = false;
        for (int band = 1; band <= OutputCubes[0]->bandCount(); band++) {
          otile.SetTile(tile, band);
@@ -224,6 +231,8 @@ namespace Isis {
    p_sampMap.clear();
    p_lineMap.clear();
  }


  /**
   * Registers a function to be called when the current output cube band number
   * changes. This includes the first time. If and application does NOT need to
@@ -235,11 +244,14 @@ namespace Isis {
   *                              changes.
   */
  void ProcessRubberSheet::BandChange(void (*funct)(const int band)) {

    p_bandChangeFunct = funct;
  }


  void ProcessRubberSheet::SlowGeom(TileManager &otile, Portal &iportal,
                                    Transform &trans, Interpolator &interp) {

    double outputSamp, outputLine;
    double inputSamp, inputLine;
    int outputBand = otile.Band();
@@ -269,9 +281,11 @@ namespace Isis {
    }
  }


  void ProcessRubberSheet::QuadTree(TileManager &otile, Portal &iportal,
                                    Transform &trans, Interpolator &interp,
                                    bool useLastTileMap) {

    // Initializations
    vector<Quad *> quadTree;

@@ -329,6 +343,7 @@ namespace Isis {
   */
  bool ProcessRubberSheet::TestLine(Transform &trans, int ssamp, int esamp,
                                    int sline, int eline, int increment) {

    for (int line = sline; line <= eline; line += increment) {
      for (int sample = ssamp; sample <= esamp; sample += increment) {
        double sjunk = 0.0;
@@ -343,11 +358,13 @@ namespace Isis {
    return false;
  }


  // Process a quad trying to find input positions for output positions
  void ProcessRubberSheet::ProcessQuad(std::vector<Quad *> &quadTree,
                           Transform &trans,
                           std::vector< std::vector<double> > &lineMap,
                           std::vector< std::vector<double> > &sampMap) {

    Quad *quad = quadTree[0];
    double oline[4], osamp[4];
    double iline[4], isamp[4];
@@ -618,8 +635,10 @@ namespace Isis {
    quadTree.erase(quadTree.begin());
  }


  // Break input quad into four pieces
  void ProcessRubberSheet::SplitQuad(std::vector<Quad *> &quadTree) {

    // Get the quad to split
    Quad *quad = quadTree[0];
    int n = (quad->eline - quad->sline + 1) / 2;
@@ -662,8 +681,8 @@ namespace Isis {
  void ProcessRubberSheet::SlowQuad(std::vector<Quad *> &quadTree,
                                    Transform &trans,
                                    std::vector< std::vector<double> > &lineMap,
                                    std::vector< std::vector<double> > &sampMap) 
  {
                                    std::vector< std::vector<double> > &sampMap) {

    // Get the quad
    Quad *quad = quadTree[0];
    double iline, isamp;
@@ -691,8 +710,10 @@ namespace Isis {
    quadTree.erase(quadTree.begin());
  }


  // Determinate method for 4x4 matrix using cofactor expansion
  double ProcessRubberSheet::Det4x4(double m[4][4]) {

    double cofact[3][3];

    cofact [0][0] = m[1][1];
@@ -742,8 +763,10 @@ namespace Isis {
    return det;
  }


  // Determinate for 3x3 matrix
  double ProcessRubberSheet::Det3x3(double m[3][3]) {

    return m[0][0] * m[1][1] * m[2][2] -
           m[0][0] * m[1][2] * m[2][1] -
           m[0][1] * m[1][0] * m[2][2] +
@@ -752,6 +775,7 @@ namespace Isis {
           m[0][2] * m[1][1] * m[2][0];
  }


 /**
 * Applies a Transform and an Interpolator to small patches. The transform
 * should define a mapping from input pixel coordinates to output pixel
@@ -774,9 +798,9 @@ namespace Isis {
 *
 * @throws iException::Message
 */

  void ProcessRubberSheet::processPatchTransform(Transform &trans,
                                                 Interpolator &interp) {

    // Error checks ... there must be one input and one output
    if (InputCubes.size() != 1) {
      string m = "You must specify exactly one input cube";
@@ -1061,6 +1085,7 @@ namespace Isis {
    }
  }


  // Private method used to split up input patches if the patch is too big to
  // process
  void ProcessRubberSheet::splitPatch(double ssamp, double esamp,
+5 −3
Original line number Diff line number Diff line
@@ -111,6 +111,8 @@ namespace Isis {
   *                                            inheritance between Process and its
   *                                            child classes.  Made destructor virtual.
   *                                            References #2215.
   *   @history 2017-06-09 Christopher Combs - Changed loop counter int in
                               StartProcess to long long int. References #4611.
   *
   *   @todo 2005-02-11 Stuart Sides - finish documentation and add coded and
   *                        implementation example to class documentation
@@ -146,7 +148,7 @@ namespace Isis {
       * @param end End position; must be at least 4, a power of 2 and less than
       *          start
       */
      void SetTiling(int start, int end) {
      void SetTiling(long long start, long long end) {
        p_startQuadSize = start;
        p_endQuadSize = end;
      }
@@ -219,8 +221,8 @@ namespace Isis {
      double p_forceSamp; //!<
      double p_forceLine; //!<

      int p_startQuadSize; //!<
      int p_endQuadSize;   //!<
      long long p_startQuadSize; //!<
      long long p_endQuadSize;   //!<

      int m_patchStartSample;
      int m_patchStartLine;