Skip to content

Commit

Permalink
The explode application has been refactored to be callable and Makefi…
Browse files Browse the repository at this point in the history
…le test converted to a gtest. (DOI-USGS#5590)

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

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

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

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

---------

Co-authored-by: Adam Paquette <acpaquette@usgs.gov>
  • Loading branch information
kledmundson and acpaquette authored Sep 11, 2024
1 parent c6b5df4 commit 5e5b1d9
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 66 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
97 changes: 97 additions & 0 deletions isis/src/base/apps/explode/explode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/** 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 changes: 19 additions & 0 deletions isis/src/base/apps/explode/explode.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 explode_h
#define explode_h

#include "UserInterface.h"

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

#endif
3 changes: 3 additions & 0 deletions isis/src/base/apps/explode/explode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
67 changes: 12 additions & 55 deletions isis/src/base/apps/explode/main.cpp
Original file line number Diff line number Diff line change
@@ -1,63 +1,20 @@
#include "Isis.h"
#include "ProcessByLine.h"
#include "IException.h"
#include "FileName.h"

using namespace std;
using namespace Isis;

void CopyBand(Buffer &in, Buffer &out);
/** This is free and unencumbered software released into the public domain.
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");
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. **/

// Loop and extract each band
for(int band = 1; band <= bands; band++) {
int pband = icube->physicalBand(band);
QString sband(toString(pband));
/* SPDX-License-Identifier: CC0-1.0 */

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);
}
4 changes: 0 additions & 4 deletions isis/src/base/apps/explode/tsts/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions isis/src/base/apps/explode/tsts/case01/Makefile

This file was deleted.

80 changes: 80 additions & 0 deletions isis/tests/FunctionalTestsExplode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "explode.h"

#include <QFileInfo>
#include <QString>

#include "CameraFixtures.h"
#include "Cube.h"
#include "Histogram.h"

#include "gtest/gtest.h"

using namespace Isis;

static QString APP_XML = FileName("$ISISROOT/bin/xml/explode.xml").expanded();

/**
* ExplodeDefault Test
*
* ExplodeDefault test given a single 5x5 input cube with 2 bands.
*
* The output cube is verified by checking the histogram statistics
* for each band.
*
* INPUT: testCube from DefaultCube fixture resized to 5x5x1
*
* OUTPUT: 1) explodeOut.band0001.cub
* 2) explodeOut.band0002.cub
*/
TEST_F(DefaultCube, FunctionalTestExplodeDefault) {

// reduce test cube size and create two bands
resizeCube(5, 5, 2);

// close and reopen test cube to ensure dn buffer is available
testCube->reopen("r");

// run explode
QVector<QString> args = {"to=" + tempDir.path() + "/explodeOut"};
UserInterface ui(APP_XML, args);

try {
explode(testCube, ui);
}
catch(IException &e) {
FAIL() << e.toString().toStdString().c_str() << std::endl;
}

// validate band 1 output cube
Cube outCube1(tempDir.path() + "/explodeOut.band0001.cub");

ASSERT_EQ(outCube1.sampleCount(), 5);
ASSERT_EQ(outCube1.lineCount(), 5);
ASSERT_EQ(outCube1.bandCount(), 1);

std::unique_ptr<Histogram> inCubeBand1Hist (testCube->histogram(1));
std::unique_ptr<Histogram> outCube1Hist (outCube1.histogram(1));

EXPECT_NEAR(outCube1Hist->Average(), inCubeBand1Hist->Average(), .000001);
EXPECT_NEAR(outCube1Hist->Sum(), inCubeBand1Hist->Sum(), .000001);
EXPECT_EQ(outCube1Hist->ValidPixels(), inCubeBand1Hist->ValidPixels());
EXPECT_EQ(outCube1Hist->TotalPixels(), inCubeBand1Hist->TotalPixels());
EXPECT_NEAR(outCube1Hist->StandardDeviation(), inCubeBand1Hist->StandardDeviation(), .000001);

// validate band 2 output cube
Cube outCube2(tempDir.path() + "/explodeOut.band0002.cub");

ASSERT_EQ(outCube2.sampleCount(), 5);
ASSERT_EQ(outCube2.lineCount(), 5);
ASSERT_EQ(outCube2.bandCount(), 1);

std::unique_ptr<Histogram> inCubeBand2Hist (testCube->histogram(2));
std::unique_ptr<Histogram> outCube2Hist (outCube2.histogram(1));

EXPECT_NEAR(outCube2Hist->Average(), inCubeBand2Hist->Average(), .000001);
EXPECT_NEAR(outCube2Hist->Sum(), inCubeBand2Hist->Sum(), .000001);
EXPECT_EQ(outCube2Hist->ValidPixels(), inCubeBand2Hist->ValidPixels());
EXPECT_EQ(outCube2Hist->TotalPixels(), inCubeBand2Hist->TotalPixels());
EXPECT_NEAR(outCube2Hist->StandardDeviation(), inCubeBand2Hist->StandardDeviation(), .000001);
}

0 comments on commit 5e5b1d9

Please sign in to comment.