Commit dde0a9a6 authored by Jeannie Backer's avatar Jeannie Backer
Browse files

Fixed ProcessMosaic to populate tables properly and ensure that table records...

Fixed ProcessMosaic to populate tables properly and ensure that table records are the proper size. Fixes #1178

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6389 41f8697f-d340-4b68-9986-7bafba869bb8
parent 3d82fb09
Loading
Loading
Loading
Loading
+70 −46
Original line number Diff line number Diff line
@@ -655,17 +655,19 @@ namespace Isis {
   * @author Sharmila Prasad (8/28/2009)
   */
  void ProcessMosaic::SetMosaicOrigin(int &index) {
    // Get only the file name
    QString sInputFile = FileName(InputCubes[0]->fileName()).name();
    QString sTableName = TRACKING_TABLE_NAME;
    // Get the name of the file to be added
    QString inputFileName   = FileName(InputCubes[0]->fileName()).name();
    QString tableName       = TRACKING_TABLE_NAME;
    int inputFileNameLength = inputFileName.length();

    // Get the serial number
    QString sSerialNumber = SerialNumber::Compose(*(InputCubes[0]));
    int iFileNameLen  = sInputFile.length();
    int iSerialNumLen = sSerialNumber.length();
    int iFieldLength = iSerialNumLen;
    if (iFileNameLen > iSerialNumLen) {
      iFieldLength = iFileNameLen;
    QString inputFileSerialNumber   = SerialNumber::Compose(*(InputCubes[0]));
    int inputFileSerialNumberLength = inputFileSerialNumber.length();

    // the fields will be equal length, so choose the larger value
    int fieldLength = inputFileSerialNumberLength;
    if (inputFileNameLength > inputFileSerialNumberLength) {
      fieldLength = inputFileNameLength;
    }

    // Get output file name
@@ -677,59 +679,56 @@ namespace Isis {
    TableRecord cFileRecord;

    // Populate with File Name
    TableField cFileField("FileName", TableField::Text, iFieldLength);
    cFileField = sInputFile;
    TableField cFileField("FileName", TableField::Text, fieldLength);
    cFileField = inputFileName;
    cFileRecord += cFileField;

    // Populate with Serial Number
    TableField cSNField("SerialNumber", TableField::Text, iFieldLength);
    cSNField = sSerialNumber;
    TableField cSNField("SerialNumber", TableField::Text, fieldLength);
    cSNField = inputFileSerialNumber;
    cFileRecord += cSNField;

    int iNumObjs = cPvlOut->objects();
    PvlObject cPvlObj;

    // Check if the Table exists
    // Check if a Table exists in the mosaic cube
    if (cPvlOut->hasObject("Table")) {
      for (int i = 0; i < iNumObjs; i++) {
        cPvlObj = cPvlOut->object(i);
        if (cPvlObj.hasKeyword("Name", Pvl::Traverse)) {
          PvlKeyword cNameKey = cPvlObj.findKeyword("Name", Pvl::Traverse);
          if (cNameKey[0] == sTableName) {
            PvlKeyword cFieldKey = cPvlObj.findGroup("Field").findKeyword("Size");
          if (cNameKey[0] == tableName) {
            int existingTableFieldLength = toInt(QString(cPvlObj.findGroup("Field")
                                                         .findKeyword("Size")));

            //set the tracker flag to true as the tracking table exists
            m_trackingEnabled = true;

            // Create a new blank table
            Table cFileTable(sTableName);
            Table cFileTable(tableName);

            // Read and make a copy of the existing tracking table
            Table cFileTable_Copy = Table(sTableName);
            Table cFileTable_Copy = Table(tableName);
            OutputCubes[0]->read(cFileTable_Copy);

            // Records count
            int iRecs = cFileTable_Copy.Records();
            int existingTableRecords = cFileTable_Copy.Records();

            // Check if the image index can be accomadated in the pixel size
            bool bFull = false;
            switch (sizeof(OutputCubes[0]->pixelType())) {
              case 1:
                // Index is 1 based as 0=Null invalid value
                if (iRecs >= (VALID_MAX1 - 1))
                  bFull = true;
                if (existingTableRecords >= (VALID_MAX1 - 1)) bFull = true;
                break;
              case 2:
                // Signed 16bits with some special pixels
                if (iRecs > (VALID_MAX2 - VALID_MIN2 + 1))
                  bFull = true;
                if (existingTableRecords > (VALID_MAX2 - VALID_MIN2 + 1)) bFull = true;
                break;

              case 4:
                // Max float mantissa
                if (iRecs > (FLOAT_STORE_INT_PRECISELY_MAX_VALUE -
                             FLOAT_STORE_INT_PRECISELY_MIN_VALUE + 1))
                  bFull = true;
                if (existingTableRecords > (FLOAT_STORE_INT_PRECISELY_MAX_VALUE -
                                            FLOAT_STORE_INT_PRECISELY_MIN_VALUE + 1)) bFull = true;
                break;
            }

@@ -738,7 +737,7 @@ namespace Isis {
              throw IException(IException::Programmer, msg, _FILEINFO_);
            }

            for (int i = 0; i < iRecs; i++) {
            for (int i = 0;i < existingTableRecords;i++) {
              // Get the file name and trim out the characters filled due to resizing
              QString sTableFile = QString(QString(cFileTable_Copy[i][0]).toAscii().data());
              int found = sTableFile.lastIndexOf(".cub");
@@ -747,40 +746,65 @@ namespace Isis {
                sTableFile.remove(found + 4);
              }

              if (sTableFile == sInputFile) {
              if (sTableFile == inputFileName) {
                index += i;
                return;
              }

              // To initialize the new table, on the first file name comparison, check the size of
              // the existing table record with the size of the new record being added
              if (!i) {
                if (toInt(QString(cFieldKey[0])) < iFieldLength) {
                  TableRecord cFileRecordUpdate;
                  TableField cFileFieldUpdate("FileName", TableField::Text, iFieldLength);

              // compare the length of the fields in the current table to the length of the fields
              // in the record to be added to the table, then create the new record to be added
              TableRecord record;
              if (existingTableFieldLength < fieldLength) {
                // if the new field length is larger, create the new record to be added
                // from the updated field size (i.e. resize each record in the exisiting
                // table)
                TableField  cFileFieldUpdate("FileName", TableField::Text, fieldLength);
                cFileFieldUpdate  = (QString)cFileTable_Copy[i][0];
                  cFileRecordUpdate += cFileFieldUpdate;
                record += cFileFieldUpdate;

                // Populate with Serial Number
                  TableField cSNFieldUpdate("SerialNumber", TableField::Text, iFieldLength);
                TableField cSNFieldUpdate("SerialNumber", TableField::Text, fieldLength);
                cSNFieldUpdate = (QString)cFileTable_Copy[i][1];
                  cFileRecordUpdate += cSNFieldUpdate;
                  // add new record and set the size for all the other records
                  cFileTable = Table(sTableName, cFileRecordUpdate);
                record += cSNFieldUpdate;
              }
              else {
                  cFileTable = Table(sTableName, cFileTable_Copy[i]);
                }
                // otherwise, keep the original record size
                record = cFileTable_Copy[i];
              }
              
              // Add the existing records into the new table
              cFileTable += cFileTable_Copy[i]; // what if record size was resized above??? new record does not match table record size
              // if this is the first record, initialize the new table with by adding the record
              // created above (this will also set the appropriate record size)
              if (i == 0) {
                cFileTable = Table(tableName, record);
                cFileTable += record;
              }
              else {
                // Add all other records from the existing table into the new table
                cFileTable += record;
              }
            }
            // Get the current image file index
            index += iRecs;
            index += existingTableRecords;

            // if we kept the original table record size and this record is smaller, then we
            // need to resize
            if (cFileRecord.RecordSize() < cFileTable.RecordSize()) { // fieldLength < existingTableFieldLength
              TableRecord updateNewRecord;
              TableField  cFileFieldUpdate("FileName", TableField::Text, existingTableFieldLength);
              cFileFieldUpdate = (QString)cFileRecord[0];
              updateNewRecord += cFileFieldUpdate;

              // Populate with Serial Number
              TableField cSNFieldUpdate("SerialNumber", TableField::Text, existingTableFieldLength);
              cSNFieldUpdate = (QString)cFileRecord[1];
              updateNewRecord += cSNFieldUpdate;
              cFileTable +=  updateNewRecord;
            }
            else {
              // Add the current input image record to the new table
              cFileTable +=  cFileRecord;
            }

            // Copy the new table to the output Mosaic
            OutputCubes[0]->write(cFileTable);
@@ -792,7 +816,7 @@ namespace Isis {

    //creating new table if track flag is true
    if (m_createOutputMosaic && m_trackingEnabled) {
      Table cFileTable(sTableName, cFileRecord);
      Table cFileTable(tableName, cFileRecord);
      cFileTable += cFileRecord;
      OutputCubes[0]->write(cFileTable);
      //reset the origin band based on pixel type
+5 −5
Original line number Diff line number Diff line
@@ -184,11 +184,11 @@ namespace Isis {
   *                           automos. Fixes #1620. Fixes #1623.
   *   @history 2014-07-23 Janet Barrett - Fixed the StartProcess method to allow the overlay of
   *                           an input file on a pre-existing output file. Fixed #751.
   *   @history 2015-01-15 Sasha Brownsberger - Added virtual keyword to several 
   *                                            functions to ensure successful 
   *                                            inheritance between Process and its
   *                                            child classes.  Made destructor virtual.
   *                                            References #2215.
   *   @history 2015-01-15 Sasha Brownsberger - Added virtual keyword to several functions to ensure
   *                           successful inheritance between Process and its child classes.
   *                           Made destructor virtual. References #2215.
   *   @history 2015-10-04 Jeannie Backer - Fixed SetMosaicOrigin() method to populate the input
   *                           images table properly. Fixes #1178
   */

  class ProcessMosaic : public Process {
+1173 −267

File changed.

Preview size limit exceeded, changes collapsed.

+141 −64

File changed.

Preview size limit exceeded, changes collapsed.

+45 −0
Original line number Diff line number Diff line
@@ -65,6 +65,51 @@
        </filter>
        <default><item>isisMosaic_02.cub</item></default>
      </parameter>
      <parameter name="INPUT_LEFT">
        <type>cube</type>
        <fileMode>input</fileMode>
        <pixelType>Real</pixelType>
        <brief>
          Test cube
        </brief>
        <description>
          Test cube
        </description>
        <filter>
          *.cub
        </filter>
        <default><item>isisTruth2.left.cub</item></default>
      </parameter>
      <parameter name="INPUT_RIGHT">
        <type>cube</type>
        <fileMode>input</fileMode>
        <pixelType>Real</pixelType>
        <brief>
          Test cube
        </brief>
        <description>
          Test cube
        </description>
        <filter>
          *.cub
        </filter>
        <default><item>isisTruth2.left.cub</item></default>
      </parameter>
      <parameter name="MOSAIC_LEFT_RIGHT">
        <type>cube</type>
        <fileMode>output</fileMode>
        <pixelType>Real</pixelType>
        <brief>
          Test cube
        </brief>
        <description>
          Test cube
        </description>
        <filter>
          *.cub
        </filter>
        <default><item>isisMosaic_03.cub</item></default>
      </parameter>
    </group>
  </groups>
</application>
Loading