Skip to content

Commit

Permalink
Fixed bug in noproj where some temporary files were not deleted after…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
kledmundson authored Jan 19, 2024
1 parent 17fe70d commit 1236400
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions isis/src/base/apps/noproj/main.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
80 changes: 55 additions & 25 deletions isis/src/base/apps/noproj/noproj.cpp
Original file line number Diff line number Diff line change
@@ -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 <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"

Expand All @@ -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.
*
Expand All @@ -44,7 +50,7 @@ namespace Isis {
if((ui.WasEntered("MATCH"))) {
mcube.open(ui.GetCubeName("MATCH"));
}

noproj(&icube, &mcube, ui);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<QString> 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");
Expand All @@ -396,6 +402,7 @@ namespace Isis {
if (o.hasGroup("AlphaCube")) {
o.deleteGroup("AlphaCube");
}

toCube.close();
}

Expand All @@ -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 );
}
}
9 changes: 8 additions & 1 deletion isis/src/base/apps/noproj/noproj.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/** 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

#include "Cube.h"
#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 changes: 8 additions & 0 deletions isis/src/base/apps/noproj/noproj.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 1236400

Please sign in to comment.