Unverified Commit 12364003 authored by kledmundson's avatar kledmundson Committed by GitHub
Browse files

Fixed bug in noproj where some temporary files were not deleted after completion (#5403)

* Fixed noproj bug where some temporary files were not cleaned up (deleted) after call to cam2cam. Also reworked how these temporary files are identified. Addresses #4813.

* Added copyright statement at top of source and header files. Addresses #4813.
parent 17fe70dd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ release.
## [Unreleased]

### Fixed
- Fixed <i>noproj</i> bug where some temporary files were not deleted after call to cam2cam.  Issue: [#4813](https://github.com/USGS-Astrogeology/ISIS3/issues/4813)
- Fixed <i>noproj</i> bug where missing shapemodel-related keywords (RayTraceEngine, BulletParts, Tolerance) are dropped when the output label is created. This resulted in the Bullet collision detection engine not being used. Issue: [#5377](https://github.com/USGS-Astrogeology/ISIS3/issues/5377)

## [8.1.0] - 2024-01-08
+7 −0
Original line number Diff line number Diff line
/** This is free and unencumbered software released into the public domain.

The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */
#define GUIHELPERS
#include "Isis.h"

+55 −25
Original line number Diff line number Diff line
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include "noproj.h"

#include <iostream>
#include <sstream>
#include <QString>
#include <QStringList>

#include "AlphaCube.h"
#include "Application.h"
#include "Blob.h"
#include "cam2cam.h"
#include "CameraDetectorMap.h"
#include "CameraFocalPlaneMap.h"
#include "History.h"
#include "iTime.h"
#include "Process.h"
#include "ProgramLauncher.h"
#include "Pvl.h"
#include "PvlObject.h"

@@ -27,6 +31,8 @@ namespace Isis {
                  QString oldName, QString spiceName,
                  double constantCoeff, double multiplierCoeff, bool putMultiplierInX);

  QStringList findAllDetachedFiles(const PvlObject &object);

  /**
   * Remove camera distortions in a raw level 1 cube.
   *
@@ -191,6 +197,7 @@ namespace Isis {
    //   1) the idealInstrument pvl if there or
    //   2) the input size expanded by user specified percentage
    Cube *ocube = p.SetOutputCube(matchCubeFile.expanded(), cao, 1, 1, 1);
    
    // Extract the times and the target from the instrument group
    QString startTime = inst["StartTime"];
    QString stopTime;
@@ -355,12 +362,13 @@ namespace Isis {
    // Now adjust the label to fake the true size of the image to match without
    // taking all the space it would require for the image data
    Pvl label;
    label.read(matchCubeFileNoExt + ".lbl");
    QString matchLbl = matchCubeFileNoExt + ".lbl";
    label.read(matchLbl);
    PvlGroup &dims = label.findGroup("Dimensions", Pvl::Traverse);
    dims["Lines"] = toString(numberLines);
    dims["Samples"] = toString(detectorSamples);
    dims["Bands"] = toString(numberBands);
    label.write(matchCubeFileNoExt + ".lbl");
    label.write(matchLbl);

    // And run cam2cam to apply the transformation
    QVector<QString> args = {"to=" + ui.GetCubeName("TO"), "INTERP=" + ui.GetString("INTERP")};
@@ -370,21 +378,19 @@ namespace Isis {
    cam2cam(icube, &matchCube, cam2camUI);

    // Cleanup by deleting the match files
    remove((matchCubeFileNoExt + ".History.IsisCube").toStdString().c_str());
    remove((matchCubeFileNoExt + ".lbl").toStdString().c_str());
    remove(matchCubeFile.expanded().toStdString().c_str());
    remove((matchCubeFileNoExt + ".OriginalLabel.IsisCube").toStdString().c_str());
    remove((matchCubeFileNoExt + ".Table.BodyRotation").toStdString().c_str());
    remove((matchCubeFileNoExt + ".Table.HiRISE Ancillary").toStdString().c_str());
    remove((matchCubeFileNoExt + ".Table.HiRISE Calibration Ancillary").toStdString().c_str());
    remove((matchCubeFileNoExt + ".Table.HiRISE Calibration Image").toStdString().c_str());
    remove((matchCubeFileNoExt + ".Table.InstrumentPointing").toStdString().c_str());
    remove((matchCubeFileNoExt + ".Table.InstrumentPosition").toStdString().c_str());
    remove((matchCubeFileNoExt + ".Table.SunPosition").toStdString().c_str());
    QStringList detfiles = findAllDetachedFiles( label );
    detfiles.append(matchLbl);

    // Now actually remove the files
    foreach (const QString &dfile, detfiles ) {
      std::string  dtf = dfile.toStdString();
      remove ( dtf.c_str() );
    }

    // Finally finish by adding the OriginalInstrument group to the TO cube
    Cube toCube;
    toCube.open(ui.GetCubeName("TO"), "rw");
  
    // Extract label and create cube object
    Pvl *toLabel = toCube.label();
    PvlObject &o = toLabel->findObject("IsisCube");
@@ -396,6 +402,7 @@ namespace Isis {
    if (o.hasGroup("AlphaCube")) {
      o.deleteGroup("AlphaCube");
    }

    toCube.close();
  }

@@ -421,4 +428,27 @@ namespace Isis {
      naifKeywordsObject->addKeyword(spiceKeyword, Pvl::Replace);
    }
  }

  // Find all detached filenames specified in objects in the label
  QStringList findAllDetachedFiles(const PvlObject &object) {

    // Check this object for a detached file spec
    QStringList detfiles;
    QString dfilename = "^" + object.name();
    if ( object.hasKeyword(dfilename) ) {
      QString detname = object[dfilename];
      detfiles.append(detname);
    }

    // Now check all objects contain in this object
    for (int i_obj = 0; i_obj <  object.objects(); i_obj++) {
      const PvlObject &obj = object.object(i_obj);
      QStringList files = findAllDetachedFiles(obj);
      if ( files.size() > 0 ) {
        detfiles.append(files);
      }    
    }
  
    return ( detfiles );
  }  
}
+8 −1
Original line number Diff line number Diff line
/** This is free and unencumbered software released into the public domain.

The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */
#ifndef noproj_h
#define noproj_h

@@ -5,8 +12,8 @@
#include "UserInterface.h"

namespace Isis{
  extern void noproj(Cube *icube, Cube *mcube, UserInterface &ui);
  extern void noproj(UserInterface &ui);
  extern void noproj(Cube *icube, Cube *mcube, UserInterface &ui);
}

#endif
+8 −0
Original line number Diff line number Diff line
@@ -73,9 +73,17 @@
          BulletParts, and Tolerance. These parameters must be included in the
          output label in order for cam2cam to run and subsequent use is consistent.
    </change>
    <change name="Kris Becker" date="2021-09-22">
          Rework how temporary external files are identified in UofA OSIRIS-REx
          ISIS code base after use by cam2cam and ensure they are all deleted. Fixes
          #4813.
    </change>
    <change name="Ken Edmundson" date="2023-12-14">
          Incorporated Kris Becker's 2021-05-06 bug fix above into USGS code base.
    </change>
    <change name="Ken Edmundson" date="2024-01-09">
          Incorporated Kris Becker's 2021-09-22 bug fix above into USGS code base.
    </change>
  </history>

  <category>