Unverified Commit faaddcbc authored by Summer Stapleton's avatar Summer Stapleton Committed by GitHub
Browse files

Merge pull request #379 from jessemapel/tracking_offset

Added an offset to TrackingTable to account for 0-2 being special pixels. References #971
parents f1d32bfd b22d7234
Loading
Loading
Loading
Loading
+54 −41
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "FileName.h"
#include "IException.h"
#include "Pvl.h"
#include "SpecialPixel.h"
#include "Table.h"
#include "TableField.h"
#include "TableRecord.h"
@@ -100,7 +101,7 @@ namespace Isis {
    TableRecord dummyRecord;
    TableField fileNameField("FileName", TableField::Text, fieldLength);
    TableField serialNumberField("SerialNumber", TableField::Text, fieldLength);
    TableField indexField("Index", TableField::Integer);
    TableField indexField("PixelValue", TableField::Integer);
    dummyRecord += fileNameField;
    dummyRecord += serialNumberField;
    dummyRecord += indexField;
@@ -111,7 +112,7 @@ namespace Isis {

      fileNameField = m_fileList[i].first.name();
      serialNumberField = m_fileList[i].second;
      indexField = i;
      indexField = (int) (i + VALID_MINUI4);

      TableRecord record;
      record += fileNameField;
@@ -127,15 +128,24 @@ namespace Isis {


  /**
  * Returns the FileName at the given index within m_fileList.
  * Returns the FileName that corresponds to a pixel value.
  *
  * @param index The index to find the filename for
  * @returns FileName The FileName at the index specified
  * @param pixel The pixel value to find the filename for
  * @returns @b FileName The FileName represented by the pixel value
  */
  FileName TrackingTable::indexToFileName(unsigned int index) {
  FileName TrackingTable::pixelToFileName(unsigned int pixel) {
    if (pixel < VALID_MINUI4) {
      QString msg = "Cannot convert pixel [" + toString(pixel)
                  + "] to a filename, pixel is below valid minimum ["
                  + toString(VALID_MINUI4) + "].";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }

    unsigned int index = pixel - VALID_MINUI4;
    if (index >= (unsigned int)m_fileList.size()) {
      QString msg = "Cannot convert index [" + toString(index)
                  + "] to a filename, index is out of bounds.";
      QString msg = "Cannot convert pixel [" + toString(pixel)
                  + "] to a filename, pixel is above valid maximum ["
                  + toString(VALID_MINUI4 + m_fileList.size()) + "].";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }

@@ -144,23 +154,26 @@ namespace Isis {


  /**
  * Returns the index of the filename/serialnumber combination.
  * Returns the pixel value of the filename/serialnumber combination.
  *
  * @param file The FileName within m_fileList to find the pixel value of
  * @param serialNumber The QString of the serial number within m_fileList
  *                     to find the pixel value of
  *
  * @param file The FileName within m_fileList to find the index of
  * @param serialNumber The QString of the serial number within m_fileList to find the index of
  * @return unsighned int The index of the filename/serialnumber combination
  * @return  @b unsigned  @b int The pixel value corresponding to the
  *                              filename/serialnumber combination
  */
  unsigned int TrackingTable::fileNameToIndex(FileName file, QString serialNumber) {
  unsigned int TrackingTable::fileNameToPixel(FileName file, QString serialNumber) {
    for (int i = 0; i < m_fileList.size(); i++) {
      if (m_fileList[i].first == file) {
        return i;
        return i + VALID_MINUI4;
      }
    }

    // At this point, the file is not in the internal file list so append it
    // and return its new index.
    m_fileList.append(QPair<FileName, QString>(file, serialNumber));
    return m_fileList.size() - 1;
    return m_fileList.size() - 1 + VALID_MINUI4;
  }

}
+15 −13
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ namespace Isis {
   * @author 2018-07-19 Jesse Mapel & Summer Stapleton
   *
   * @internal
   *   @history 2018-07-26 Jesse Mapel - Added offset based on minimum unsigned integer value.
   *                           Renamed methods to better convey output/input meaning.
   */
  class TrackingTable{

@@ -59,9 +61,9 @@ namespace Isis {

      Table toTable();

      FileName indexToFileName(unsigned int index);
      FileName pixelToFileName(unsigned int pixel);

      unsigned int fileNameToIndex(FileName file, QString serialNumber);
      unsigned int fileNameToPixel(FileName file, QString serialNumber);

    private:

+28 −20
Original line number Diff line number Diff line
@@ -11,30 +11,38 @@ Second record: fileName2.cub, 123
Third record : fileName3.dat, 456789
TrackingTable object created

Testing the indexToFileName method ...
FileName at index 0: fileName1.cub
FileName at index 1: fileName2.cub
FileName at index 2: fileName3.dat
FileName at index 3 does not exist and an exception is thrown.
**PROGRAMMER ERROR** Cannot convert index [3] to a filename, index is out of bounds.

Testing the fileNameToIndex method ...
Index of FileName fileName1.cub: 0
Index of FileName fileName2.cub: 1
Index of FileName fileName3.cub: 2
Index of the non-existent FileName fileName4.cub (demonstrating its addition): 3
Testing the pixelToFileName method ...
FileName with pixel value 2 does not exist and an exception is thrown.
**PROGRAMMER ERROR** Cannot convert pixel [2] to a filename, pixel is below valid minimum [3].
FileName with pixel value 3: fileName1.cub
FileName with pixel value 4: fileName2.cub
FileName with pixel value 5: fileName3.dat
FileName with pixel value 6 does not exist and an exception is thrown.
**PROGRAMMER ERROR** Cannot convert pixel [6] to a filename, pixel is above valid maximum [6].

Testing the fileNameToPixel method ...
Pixel value of FileName fileName1.cub: 3
Pixel value of FileName fileName2.cub: 4
Pixel value of FileName fileName3.cub: 5
Pixel value of the non-existent FileName fileName4.cub (demonstrating its addition): 6

Testing the toTable method ...
First record : fileName1.cub, 1234567890
Second record: fileName2.cub, 123
Third record : fileName3.dat, 456789
Fourth record: fileName4.cub, 12345678901234567890
First record : fileName1.cub, 1234567890, 3
Second record: fileName2.cub, 123, 4
Third record : fileName3.dat, 456789, 5
Fourth record: fileName4.cub, 12345678901234567890, 6

Creating a new TrackingTable object with the table returned from toTable method ...
New TrackingTable object created

Verifying that the pixel values are the same ...
Pixel value of FileName fileName1.cub: 3
Pixel value of FileName fileName2.cub: 4
Pixel value of FileName fileName3.cub: 5
Pixel value of FileName fileName4.cub: 6

Testing that the Table returned from toTable on new TrackingTable matches ...
First record : fileName1.cub, 1234567890
Second record: fileName2.cub, 123
Third record : fileName3.dat, 456789
Fourth record: fileName4.cub, 12345678901234567890
First record : fileName1.cub, 1234567890, 3
Second record: fileName2.cub, 123, 4
Third record : fileName3.dat, 456789, 5
Fourth record: fileName4.cub, 12345678901234567890, 6
+97 −66
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ int main(int argc, char *argv[]) {

    TrackingTable trackingTable1;

    trackingTable1.fileNameToIndex("fileName1.cub", "1");
    trackingTable1.fileNameToPixel("fileName1.cub", "1");

    Table tableOut1 = trackingTable1.toTable();

@@ -68,14 +68,16 @@ int main(int argc, char *argv[]) {
    cout << endl;


    cout << "Testing the indexToFileName method ..." << endl;
    cout << "Testing the pixelToFileName method ..." << endl;

    for (int i = 0; i < 4; i++) {
    for (int i = 2; i < 7; i++) {
      try {
        cout << "FileName at index " << i << ": " << trackingTable2.indexToFileName(i).name() << endl;
        cout << "FileName with pixel value " << i << ": "
             << trackingTable2.pixelToFileName(i).name() << endl;
      }
      catch (IException e) {
        cout << "FileName at index " << i << " does not exist and an exception is thrown." << endl;
        cout << "FileName with pixel value " << i
             << " does not exist and an exception is thrown." << endl;
        e.print();
      }
    }
@@ -83,16 +85,16 @@ int main(int argc, char *argv[]) {
    cout << endl;


    cout << "Testing the fileNameToIndex method ..." << endl;
    cout << "Testing the fileNameToPixel method ..." << endl;

    cout << "Index of FileName fileName1.cub: " 
           << trackingTable2.fileNameToIndex("fileName1.cub", "1234567890") << endl;
    cout << "Index of FileName fileName2.cub: " 
           << trackingTable2.fileNameToIndex("fileName2.cub", "123") << endl;
    cout << "Index of FileName fileName3.cub: " 
           << trackingTable2.fileNameToIndex("fileName3.dat", "456789") << endl;
    cout << "Index of the non-existent FileName fileName4.cub (demonstrating its addition): " 
           << trackingTable2.fileNameToIndex("fileName4.cub", "12345678901234567890") << endl;
    cout << "Pixel value of FileName fileName1.cub: "
           << trackingTable2.fileNameToPixel("fileName1.cub", "1234567890") << endl;
    cout << "Pixel value of FileName fileName2.cub: "
           << trackingTable2.fileNameToPixel("fileName2.cub", "123") << endl;
    cout << "Pixel value of FileName fileName3.cub: "
           << trackingTable2.fileNameToPixel("fileName3.dat", "456789") << endl;
    cout << "Pixel value of the non-existent FileName fileName4.cub (demonstrating its addition): "
           << trackingTable2.fileNameToPixel("fileName4.cub", "12345678901234567890") << endl;

    cout << endl;

@@ -101,10 +103,18 @@ int main(int argc, char *argv[]) {

    Table tableOut2 = trackingTable2.toTable();

    cout << "First record : " << QString(tableOut2[0][0]) << ", " << QString(tableOut2[0][1]) << endl;
    cout << "Second record: " << QString(tableOut2[1][0]) << ", " << QString(tableOut2[1][1]) << endl;
    cout << "Third record : " << QString(tableOut2[2][0]) << ", " << QString(tableOut2[2][1]) << endl;
    cout << "Fourth record: " << QString(tableOut2[3][0]) << ", " << QString(tableOut2[3][1]) << endl;
    cout << "First record : " << QString(tableOut2[0][0]) << ", "
                              << QString(tableOut2[0][1]) << ", "
                              << int(tableOut2[0][2]) << endl;
    cout << "Second record: " << QString(tableOut2[1][0]) << ", "
                              << QString(tableOut2[1][1]) << ", "
                              << int(tableOut2[1][2]) << endl;
    cout << "Third record : " << QString(tableOut2[2][0]) << ", "
                              << QString(tableOut2[2][1]) << ", "
                              << int(tableOut2[2][2]) << endl;
    cout << "Fourth record: " << QString(tableOut2[3][0]) << ", "
                              << QString(tableOut2[3][1]) << ", "
                              << int(tableOut2[3][2]) << endl;

    cout << endl;

@@ -117,15 +127,36 @@ int main(int argc, char *argv[]) {

    cout << endl;

    cout << "Verifying that the pixel values are the same ..." << endl;

    cout << "Pixel value of FileName fileName1.cub: "
         << trackingTable3.fileNameToPixel("fileName1.cub", "1234567890") << endl;
    cout << "Pixel value of FileName fileName2.cub: "
         << trackingTable3.fileNameToPixel("fileName2.cub", "123") << endl;
    cout << "Pixel value of FileName fileName3.cub: "
         << trackingTable3.fileNameToPixel("fileName3.dat", "456789") << endl;
    cout << "Pixel value of FileName fileName4.cub: "
         << trackingTable3.fileNameToPixel("fileName4.cub", "12345678901234567890") << endl;

    cout << endl;


    cout << "Testing that the Table returned from toTable on new TrackingTable matches ..." << endl;

    Table tableOut3 = trackingTable3.toTable();

    cout << "First record : " << QString(tableOut3[0][0]) << ", " << QString(tableOut3[0][1]) << endl;
    cout << "Second record: " << QString(tableOut3[1][0]) << ", " << QString(tableOut3[1][1]) << endl;
    cout << "Third record : " << QString(tableOut3[2][0]) << ", " << QString(tableOut3[2][1]) << endl;
    cout << "Fourth record: " << QString(tableOut3[3][0]) << ", " << QString(tableOut3[3][1]) << endl;
    cout << "First record : " << QString(tableOut3[0][0]) << ", "
                              << QString(tableOut3[0][1]) << ", "
                              << int(tableOut3[0][2]) << endl;
    cout << "Second record: " << QString(tableOut3[1][0]) << ", "
                              << QString(tableOut3[1][1]) << ", "
                              << int(tableOut3[1][2]) << endl;
    cout << "Third record : " << QString(tableOut3[2][0]) << ", "
                              << QString(tableOut3[2][1]) << ", "
                              << int(tableOut3[2][2]) << endl;
    cout << "Fourth record: " << QString(tableOut3[3][0]) << ", "
                              << QString(tableOut3[3][1]) << ", "
                              << int(tableOut3[3][2]) << endl;

  }
  catch (IException &e) {