From 12364003053321e783a5abdd12924f9c345ddad5 Mon Sep 17 00:00:00 2001
From: kledmundson <6842706+kledmundson@users.noreply.github.com>
Date: Fri, 19 Jan 2024 13:12:02 -0700
Subject: [PATCH] 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.
---
CHANGELOG.md | 1 +
isis/src/base/apps/noproj/main.cpp | 7 +++
isis/src/base/apps/noproj/noproj.cpp | 80 +++++++++++++++++++---------
isis/src/base/apps/noproj/noproj.h | 9 +++-
isis/src/base/apps/noproj/noproj.xml | 8 +++
5 files changed, 79 insertions(+), 26 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89a2b7a7cf..231b336062 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@ release.
## [Unreleased]
### Fixed
+- Fixed noproj bug where some temporary files were not deleted after call to cam2cam. Issue: [#4813](https://github.com/USGS-Astrogeology/ISIS3/issues/4813)
- Fixed noproj 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
diff --git a/isis/src/base/apps/noproj/main.cpp b/isis/src/base/apps/noproj/main.cpp
index 3939b21132..0805486aea 100644
--- a/isis/src/base/apps/noproj/main.cpp
+++ b/isis/src/base/apps/noproj/main.cpp
@@ -1,3 +1,10 @@
+/** 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"
diff --git a/isis/src/base/apps/noproj/noproj.cpp b/isis/src/base/apps/noproj/noproj.cpp
index 968fddd59d..746b8395b6 100644
--- a/isis/src/base/apps/noproj/noproj.cpp
+++ b/isis/src/base/apps/noproj/noproj.cpp
@@ -1,19 +1,23 @@
+/** 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
#include
#include
+#include
#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.
*
@@ -44,7 +50,7 @@ namespace Isis {
if((ui.WasEntered("MATCH"))) {
mcube.open(ui.GetCubeName("MATCH"));
}
-
+
noproj(&icube, &mcube, ui);
}
@@ -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;
@@ -352,40 +359,39 @@ namespace Isis {
p.EndProcess();
- // 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
+ // 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
+ // And run cam2cam to apply the transformation
QVector args = {"to=" + ui.GetCubeName("TO"), "INTERP=" + ui.GetString("INTERP")};
UserInterface cam2camUI(FileName("$ISISROOT/bin/xml/cam2cam.xml").expanded(), args);
Cube matchCube;
matchCube.open(matchCubeFile.expanded(), "rw");
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());
-
- // Finally finish by adding the OriginalInstrument group to the TO cube
+ // Cleanup by deleting the match files
+ 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
+
+ // Extract label and create cube object
Pvl *toLabel = toCube.label();
PvlObject &o = toLabel->findObject("IsisCube");
o.deleteGroup("OriginalInstrument");
@@ -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 );
+ }
}
diff --git a/isis/src/base/apps/noproj/noproj.h b/isis/src/base/apps/noproj/noproj.h
index 4813527ecb..8063819205 100644
--- a/isis/src/base/apps/noproj/noproj.h
+++ b/isis/src/base/apps/noproj/noproj.h
@@ -1,3 +1,10 @@
+/** 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
diff --git a/isis/src/base/apps/noproj/noproj.xml b/isis/src/base/apps/noproj/noproj.xml
index 4e5f68144f..ca270a2d60 100644
--- a/isis/src/base/apps/noproj/noproj.xml
+++ b/isis/src/base/apps/noproj/noproj.xml
@@ -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.
+
+ 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.
+
Incorporated Kris Becker's 2021-05-06 bug fix above into USGS code base.
+
+ Incorporated Kris Becker's 2021-09-22 bug fix above into USGS code base.
+