Skip to content

Commit

Permalink
Fixed noproj bug where some temporary files were not cleaned up (dele…
Browse files Browse the repository at this point in the history
…ted) after call to cam2cam. Also reworked how these temporary files are identified. Addresses DOI-USGS#4813.
  • Loading branch information
kledmundson committed Jan 10, 2024
1 parent d44f0f6 commit d6e5611
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ release.
- Added new csm plugins path to IsisPreferences [#5397](https://github.com/DOI-USGS/ISIS3/pull/5397)

### 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] - 2023-12-05
Expand Down
73 changes: 48 additions & 25 deletions isis/src/base/apps/noproj/noproj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
#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 +24,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 +43,7 @@ namespace Isis {
if((ui.WasEntered("MATCH"))) {
mcube.open(ui.GetCubeName("MATCH"));
}

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

Expand Down Expand Up @@ -191,6 +190,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 +352,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 +395,7 @@ namespace Isis {
if (o.hasGroup("AlphaCube")) {
o.deleteGroup("AlphaCube");
}

toCube.close();
}

Expand All @@ -421,4 +421,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 );
}
}
2 changes: 1 addition & 1 deletion isis/src/base/apps/noproj/noproj.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,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 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 d6e5611

Please sign in to comment.