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

Photrim has been refactored to be callable; old Makefile tests have been...

Photrim has been refactored to be callable; old Makefile tests have been converted to gtests and removed. (#5582)

* Photrim has been converted to a callable app. Corresponding Makefile tests have been converted to gtests and removed. Addresses #5581.

* Tweaks to FunctionalTestsPhotrim.cpp. Addresses #5581.
parent ab5ed1dd
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ release.
- Added backplane options for SunIllumination and SurfaceObliqueDetectorResolution to phocube [#5467](https://github.com/DOI-USGS/ISIS3/issues/5467)
- Added backplane options for SunIllumination and SurfaceObliqueDetectorResolution to phocube [#5467](https://github.com/DOI-USGS/ISIS3/issues/5467)


### Changed
### 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)
- 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)
- 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)
- Added jigsaw error message for csminit'd images without csm parameters[#5486](https://github.com/DOI-USGS/ISIS3/issues/5486)
+11 −84
Original line number Original line Diff line number Diff line
#include "Isis.h"
/** This is free and unencumbered software released into the public domain.
#include "Camera.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"


using namespace std;
The authors of ISIS do not claim copyright on the contents of this file.
using namespace Isis;
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
/* SPDX-License-Identifier: CC0-1.0 */
Camera *cam;
Cube *icube;
bool usedem;
double minPhase;
double maxPhase;
double minEmission;
double maxEmission;
double minIncidence;
double maxIncidence;
int lastBand;


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


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


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


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


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

  photrim(ui);
  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;
    }
  }
}
}
+115 −0
Original line number Original line 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 "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 −0
Original line number Original line 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 photrim_h
#define photrim_h

#include "UserInterface.h"

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

#endif
+3 −0
Original line number Original line Diff line number Diff line
@@ -70,6 +70,9 @@
    <change name="Marjorie Hahn" date="2016-08-05">
    <change name="Marjorie Hahn" date="2016-08-05">
      Added the option to use the digital elevation model when trimming the image.
      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.
      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>
    </change>
  </history>
  </history>


Loading