Skip to content

Commit

Permalink
Photrim has been converted to a callable app. Corresponding Makefile …
Browse files Browse the repository at this point in the history
…tests have been converted to gtests and removed. Addresses DOI-USGS#5581.
  • Loading branch information
kledmundson committed Aug 10, 2024
1 parent 96381e8 commit cefcf11
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 154 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 backplane options for SunIllumination and SurfaceObliqueDetectorResolution to phocube [#5467](https://github.com/DOI-USGS/ISIS3/issues/5467)

### Changed
- Photrim has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5581](https://github.com/USGS-Astrogeology/ISIS3/issues/5581)
- Bandtrim has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5571](https://github.com/USGS-Astrogeology/ISIS3/issues/5571)
- Modified kaguyasp2isis to work with new (detached) data [#5436](https://github.com/DOI-USGS/ISIS3/issues/5436)
- Added jigsaw error message for csminit'd images without csm parameters[#5486](https://github.com/DOI-USGS/ISIS3/issues/5486)
Expand Down
95 changes: 11 additions & 84 deletions isis/src/base/apps/photrim/main.cpp
Original file line number Diff line number Diff line change
@@ -1,93 +1,20 @@
#include "Isis.h"
#include "Camera.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"
/** This is free and unencumbered software released into the public domain.
using namespace std;
using namespace Isis;
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. **/

// Global variables
Camera *cam;
Cube *icube;
bool usedem;
double minPhase;
double maxPhase;
double minEmission;
double maxEmission;
double minIncidence;
double maxIncidence;
int lastBand;
/* SPDX-License-Identifier: CC0-1.0 */

void photrim(Buffer &in, Buffer &out);
#include "Isis.h"

void IsisMain() {
// We will be processing by line
ProcessByLine p;
#include "photrim.h"

// Setup the input and get the camera model
icube = p.SetInputCube("FROM");
cam = icube->camera();
#include "Application.h"

// Create the output cube
p.SetOutputCube("TO");
using namespace Isis;

// Get the trim angles
void IsisMain() {
UserInterface &ui = Application::GetUserInterface();

minPhase = ui.GetDouble("MINPHASE");
maxPhase = ui.GetDouble("MAXPHASE");
minEmission = ui.GetDouble("MINEMISSION");
maxEmission = ui.GetDouble("MAXEMISSION");
minIncidence = ui.GetDouble("MININCIDENCE");
maxIncidence = ui.GetDouble("MAXINCIDENCE");

usedem = ui.GetBoolean("USEDEM");

if (!usedem) {
cam->IgnoreElevationModel(true);

}

// Start the processing
lastBand = 0;
p.StartProcess(photrim);
p.EndProcess();
}


// Line processing routine
void photrim(Buffer &in, Buffer &out) {
// See if there is a change in band which would change the camera model
if (in.Band() != lastBand) {
lastBand = in.Band();
cam->SetBand(icube->physicalBand(lastBand));
}

// Loop for each pixel in the line.
double samp, phase, emission, incidence;
double line = in.Line();
for (int i = 0; i < in.size(); i++) {
samp = in.Sample(i);
cam->SetImage(samp, line);
if (cam->HasSurfaceIntersection()) {
if (((phase = cam->PhaseAngle()) < minPhase) || (phase > maxPhase)) {
out[i] = Isis::NULL8;
}
else if (((emission = cam->EmissionAngle()) < minEmission) ||
(emission > maxEmission)) {
out[i] = Isis::NULL8;
}
else if (((incidence = cam->IncidenceAngle()) < minIncidence) ||
(incidence > maxIncidence)) {
out[i] = Isis::NULL8;
}
else {
out[i] = in[i];
}
}
// Trim outerspace
else {
out[i] = Isis::NULL8;
}
}
photrim(ui);
}
115 changes: 115 additions & 0 deletions isis/src/base/apps/photrim/photrim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/** 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 "photrim.h"

#include "Camera.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"

namespace Isis {

/*
* The photrim program trims pixels outside of the phase, incidence,
* and emission angles by setting them to "null" within all bands of
* the cube. A user can either trim using the program's default method
* or the USEDEM method.
*
* @param ui UserInterface object containing parameters
*/
void photrim(UserInterface &ui) {

// open input cube
Cube icube;
icube.open(ui.GetCubeName("FROM"));

photrim(&icube, ui);
}


/*
* The photrim program trims pixels outside of the phase, incidence,
* and emission angles by setting them to "null" within all bands of
* the cube. A user can either trim using the program's default method
* or the USEDEM method.
*
* @param iCube Input cube
* @param ui UserInterface object containing parameters
*/
void photrim(Cube *icube, UserInterface &ui) {
// processing by line
ProcessByLine p;

// Setup input cube and get the camera model
p.SetInputCube(icube);

Camera* cam = icube->camera();

// Create the output cube
QString fname = ui.GetCubeName("TO");
CubeAttributeOutput &atts = ui.GetOutputAttribute("TO");
p.SetOutputCube(fname, atts);

// Get the trim angles
double minPhase = ui.GetDouble("MINPHASE");
double maxPhase = ui.GetDouble("MAXPHASE");
double minEmission = ui.GetDouble("MINEMISSION");
double maxEmission = ui.GetDouble("MAXEMISSION");
double minIncidence = ui.GetDouble("MININCIDENCE");
double maxIncidence = ui.GetDouble("MAXINCIDENCE");

bool usedem = ui.GetBoolean("USEDEM");

if (!usedem) {
cam->IgnoreElevationModel(true);
}

// Start the processing
int lastBand = 0;

// lambda function with captures to process by line
auto photrimLineProcess = [&](Buffer &in, Buffer &out)->void {
// See if there is a change in band which would change the camera model
if (in.Band() != lastBand) {
lastBand = in.Band();
cam->SetBand(icube->physicalBand(lastBand));
}

// Loop for each pixel in the line.
double samp, phase, emission, incidence;
double line = in.Line();
for (int i = 0; i < in.size(); i++) {
samp = in.Sample(i);
cam->SetImage(samp, line);
if (cam->HasSurfaceIntersection()) {
if (((phase = cam->PhaseAngle()) < minPhase) || (phase > maxPhase)) {
out[i] = Isis::NULL8;
}
else if (((emission = cam->EmissionAngle()) < minEmission) ||
(emission > maxEmission)) {
out[i] = Isis::NULL8;
}
else if (((incidence = cam->IncidenceAngle()) < minIncidence) ||
(incidence > maxIncidence)) {
out[i] = Isis::NULL8;
}
else {
out[i] = in[i];
}
}
// Trim outerspace
else {
out[i] = Isis::NULL8;
}
}
};

p.StartProcess(photrimLineProcess);
p.EndProcess();
}
}
19 changes: 19 additions & 0 deletions isis/src/base/apps/photrim/photrim.h
Original file line number Diff line number Diff line change
@@ -0,0 +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 photrim_h
#define photrim_h

#include "UserInterface.h"

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

#endif
3 changes: 3 additions & 0 deletions isis/src/base/apps/photrim/photrim.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<change name="Marjorie Hahn" date="2016-08-05">
Added the option to use the digital elevation model when trimming the image.
Created examples for using the DEM and not using the DEM. Fixes #4181.
<change name="Ken Edmundson" date="2024-08-09">
Converted to callable app and converted Makefile tests to gtests.
</change>
</change>
</history>

Expand Down
4 changes: 0 additions & 4 deletions isis/src/base/apps/photrim/tsts/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions isis/src/base/apps/photrim/tsts/base/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions isis/src/base/apps/photrim/tsts/emission/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions isis/src/base/apps/photrim/tsts/incidence/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions isis/src/base/apps/photrim/tsts/phase/Makefile

This file was deleted.

14 changes: 0 additions & 14 deletions isis/src/base/apps/photrim/tsts/usedem/Makefile

This file was deleted.

Loading

0 comments on commit cefcf11

Please sign in to comment.