Unverified Commit 5e5b1d99 authored by kledmundson's avatar kledmundson Committed by GitHub
Browse files

The explode application has been refactored to be callable and Makefile test...


The explode application has been refactored to be callable and Makefile test converted to a gtest. (#5590)

* Updated explode application gtest to use DefaultCube fixture instead of cube in isis/tests/data. Addresses #5557.

* Cleaned up includes in default explode gtest. Added history entry to explode.xml. Addresses #5557.

* Updating main.cpp and removed Makefile tests for explode conversion to callable app. Addresses #5557.

* Added CHANGELOG entry for conversion of explode app to callable function. Addresses #5557.

---------

Co-authored-by: default avatarAdam Paquette <acpaquette@usgs.gov>
parent c6b5df47
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ release.
- Added backplane options for SunIllumination and SurfaceObliqueDetectorResolution to phocube [#5467](https://github.com/DOI-USGS/ISIS3/issues/5467)

### Changed
- Explode has been refactored to be callable; old Makefile test has been removed and replaced by a gtest. Issue: [#5557](https://github.com/USGS-Astrogeology/ISIS3/issues/5557)
- Isisminer has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5516](https://github.com/USGS-Astrogeology/ISIS3/issues/5516)
- Algebra has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5594](https://github.com/USGS-Astrogeology/ISIS3/issues/5594)
- 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)
+97 −0
Original line number 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 "explode.h"

#include "ProcessByLine.h"
#include "IException.h"
#include "FileName.h"

namespace Isis {
  
  // Line processing routine
  void CopyBand(Buffer &in, Buffer &out);

  /**
   * Extracts each band of the input cube into a separate one band cube file.
   * Given the output base name of "base", each output cube will be named
   * e.g. base.band#.cub. The appropiate BandBin group will be created.
   *
   * @param ui User Interface with application parameters
   */
  void explode(UserInterface &ui) {

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

    explode(&icube, ui);
  }


  /**
   * Extracts each band of the input cube into a separate one band cube file.
   * Given the output base name of "base", each output cube will be named
   * e.g. base.band#.cub. The appropiate BandBin group will be created.
   *
   * @param ui User Interface with application parameters
   * @param icube Input cube
   */
  void explode(Cube *icube, UserInterface &ui) {
    
    Process p;
    p.SetInputCube(icube);
    int samps = icube->sampleCount();
    int lines = icube->lineCount();
    int bands = icube->bandCount();
    QString infile = icube->fileName();

    // We get the output filename so we can add attributes and extensions
    QString outbase = ui.GetCubeName("TO");
    CubeAttributeOutput &outatt = ui.GetOutputAttribute("TO");

    // Loop and extract each band
    for(int band = 1; band <= bands; band++) {
      int pband = icube->physicalBand(band);
      QString sband(toString(pband));

      ProcessByLine p2;
      Progress *prog = p2.Progress();
      prog->SetText("Exploding band " + sband);

      CubeAttributeInput inatt("+" + sband);
      p2.SetInputCube(infile, inatt);

      QString outfile = outbase + ".band";
      if(pband / 1000 == 0) {
        outfile += "0";
        if(pband / 100 == 0) {
          outfile += "0";
          if(pband / 10 == 0) {
            outfile += "0";
          }
        }
      }
      outfile += sband + ".cub";
      p2.SetOutputCube(outfile, outatt, samps, lines, 1);

      p2.StartProcess(CopyBand);
      p2.EndProcess();
    }

    // Cleanup
    p.EndProcess();
  }

  // Line processing routine
  void CopyBand(Buffer &in, Buffer &out) {
    for(int i = 0; i < in.size(); i++) {
      out[i] = in[i];
    }
  }
}
+19 −0
Original line number 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 explode_h
#define explode_h

#include "UserInterface.h"

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

#endif
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@
    <change name="Steven Lambright" date="2008-05-12">
      Removed references to CubeInfo 
    </change>
    <change name="Ken Edmundson" date="2024-08-15">
      Converted to callable app and converted Makefile test to gtest. 
    </change>
  </history>

  <groups>
+12 −55
Original line number Diff line number Diff line
#include "Isis.h"
#include "ProcessByLine.h"
#include "IException.h"
#include "FileName.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. **/

void CopyBand(Buffer &in, Buffer &out);
/* SPDX-License-Identifier: CC0-1.0 */

void IsisMain() {
  // Get the cube to explode
  Process p;
  Cube *icube = p.SetInputCube("FROM");
  int samps = icube->sampleCount();
  int lines = icube->lineCount();
  int bands = icube->bandCount();
  QString infile = icube->fileName();

  // We the output filename so we can add attributes and extensions
  UserInterface &ui = Application::GetUserInterface();
  QString outbase = ui.GetCubeName("TO");
  CubeAttributeOutput &outatt = ui.GetOutputAttribute("TO");

  // Loop and extract each band
  for(int band = 1; band <= bands; band++) {
    int pband = icube->physicalBand(band);
    QString sband(toString(pband));

    ProcessByLine p2;
    Progress *prog = p2.Progress();
    prog->SetText("Exploding band " + sband);

    CubeAttributeInput inatt("+" + sband);
    p2.SetInputCube(infile, inatt);
#include "Isis.h"

    QString outfile = outbase + ".band";
    if(pband / 1000 == 0) {
      outfile += "0";
      if(pband / 100 == 0) {
        outfile += "0";
        if(pband / 10 == 0) {
          outfile += "0";
        }
      }
    }
    outfile += sband + ".cub";
    p2.SetOutputCube(outfile, outatt, samps, lines, 1);
#include "explode.h"

    p2.StartProcess(CopyBand);
    p2.EndProcess();
  }
#include "Application.h"

  // Cleanup
  p.EndProcess();
}
using namespace Isis;

// Line processing routine
void CopyBand(Buffer &in, Buffer &out) {
  for(int i = 0; i < in.size(); i++) {
    out[i] = in[i];
  }
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();
  explode(ui);
}
Loading