diff --git a/isis/src/base/apps/explode/explode.cpp b/isis/src/base/apps/explode/explode.cpp new file mode 100644 index 0000000000..220365616c --- /dev/null +++ b/isis/src/base/apps/explode/explode.cpp @@ -0,0 +1,99 @@ +/** 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" + +using namespace std; + +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]; + } + } +} diff --git a/isis/src/base/apps/explode/explode.h b/isis/src/base/apps/explode/explode.h new file mode 100644 index 0000000000..43e7d21d7b --- /dev/null +++ b/isis/src/base/apps/explode/explode.h @@ -0,0 +1,20 @@ +/** 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 "FileName.h" +#include "UserInterface.h" + +namespace Isis{ + extern void explode(UserInterface &ui); + extern void explode(Cube *icube, UserInterface &ui); +} + +#endif diff --git a/isis/src/base/apps/explode/explode.xml b/isis/src/base/apps/explode/explode.xml index adaef0f307..fdd508ea45 100644 --- a/isis/src/base/apps/explode/explode.xml +++ b/isis/src/base/apps/explode/explode.xml @@ -35,6 +35,9 @@ Removed references to CubeInfo + + Converted to callable app and converted Makefile test to gtest. + diff --git a/isis/src/base/apps/explode/main.cpp b/isis/src/base/apps/explode/main.cpp index 7a75d1ccba..f2ff2442ee 100644 --- a/isis/src/base/apps/explode/main.cpp +++ b/isis/src/base/apps/explode/main.cpp @@ -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); } diff --git a/isis/src/base/apps/explode/tsts/Makefile b/isis/src/base/apps/explode/tsts/Makefile deleted file mode 100644 index 46d84c74c2..0000000000 --- a/isis/src/base/apps/explode/tsts/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -BLANKS = "%-6s" -LENGTH = "%-40s" - -include $(ISISROOT)/make/isismake.tststree diff --git a/isis/src/base/apps/explode/tsts/case01/Makefile b/isis/src/base/apps/explode/tsts/case01/Makefile deleted file mode 100644 index e58baa1d0d..0000000000 --- a/isis/src/base/apps/explode/tsts/case01/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -APPNAME = explode - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(APPNAME) from=$(INPUT)/isisTruth.cub \ - to= $(OUTPUT)/explTruth1 > /dev/null; diff --git a/isis/tests/FunctionalTestsExplode.cpp b/isis/tests/FunctionalTestsExplode.cpp new file mode 100644 index 0000000000..155389c56e --- /dev/null +++ b/isis/tests/FunctionalTestsExplode.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include + +#include "Pvl.h" +#include "PvlGroup.h" +#include "explode.h" + +#include "gtest/gtest.h" + +using namespace std; +using namespace Isis; + +static QString APP_XML = FileName("$ISISROOT/bin/xml/explode.xml").expanded(); + +/** + * Explode Case01 Test + * + * Export (i.e. Explode) each band of an input + * cube with two bands into individual cubes. + * + * INPUT: isisTruth.cub + * + * OUTPUT: 1) explTruth1.band0001.cub + * 2) explTruth1.band0002.cub + */ +TEST(Explode, ExplodeCase01) { + QTemporaryDir tempDir; + + // run explode + QVector args = {"from=data/explode/isisTruth.cub", + "to=" + tempDir.path() + "/explTruth1" + }; + + UserInterface ui(APP_XML, args); + + try { + explode(ui); + } + catch(IException &e) { + FAIL() << e.toString().toStdString().c_str() << std::endl; + } + + // validate band 1 output cube + Cube cubeBand1(tempDir.path() + "/explTruth1.band0001.cub"); + Pvl *band1Label = cubeBand1.label(); + + // Core Object keywords + PvlObject &core = band1Label->findObject("Core", Pvl::Traverse); + ASSERT_EQ(int(core["StartByte"]), 65537); + ASSERT_EQ(core["Format"][0].toStdString(), "Tile"); + ASSERT_EQ(int(core["TileSamples"]), 126); + ASSERT_EQ(int(core["TileLines"]), 126); + + // Dimensions Group + ASSERT_EQ(cubeBand1.sampleCount(), 126); + ASSERT_EQ(cubeBand1.lineCount(), 126); + ASSERT_EQ(cubeBand1.bandCount(), 1); + + // Pixels Group + ASSERT_EQ(PixelTypeName(cubeBand1.pixelType()), "Real"); + ASSERT_EQ(ByteOrderName(cubeBand1.byteOrder()), "Lsb"); + ASSERT_DOUBLE_EQ(cubeBand1.base(), 0.0); + ASSERT_DOUBLE_EQ(cubeBand1.multiplier(), 1.0); + + // Test Group + PvlGroup &test = band1Label->findGroup("Test", Pvl::Traverse); + ASSERT_EQ(test["KeyWord"][0].toStdString(), "This is a test"); + + // validate band 2 output cube + Cube cubeBand2(tempDir.path() + "/explTruth1.band0002.cub"); + Pvl *band2Label = cubeBand2.label(); + + // Core Object keywords + core = band2Label->findObject("Core", Pvl::Traverse); + ASSERT_EQ(int(core["StartByte"]), 65537); + ASSERT_EQ(core["Format"][0].toStdString(), "Tile"); + ASSERT_EQ(int(core["TileSamples"]), 126); + ASSERT_EQ(int(core["TileLines"]), 126); + + // Dimensions Group + ASSERT_EQ(cubeBand2.sampleCount(), 126); + ASSERT_EQ(cubeBand2.lineCount(), 126); + ASSERT_EQ(cubeBand2.bandCount(), 1); + + // Pixels Group + ASSERT_EQ(PixelTypeName(cubeBand2.pixelType()), "Real"); + ASSERT_EQ(ByteOrderName(cubeBand2.byteOrder()), "Lsb"); + ASSERT_DOUBLE_EQ(cubeBand2.base(), 0.0); + ASSERT_DOUBLE_EQ(cubeBand2.multiplier(), 1.0); + + // Test Group + test = band2Label->findGroup("Test", Pvl::Traverse); + ASSERT_EQ(test["KeyWord"][0].toStdString(), "This is a test"); +} + diff --git a/isis/tests/data/explode/isisTruth.cub b/isis/tests/data/explode/isisTruth.cub new file mode 100644 index 0000000000..47f5741008 Binary files /dev/null and b/isis/tests/data/explode/isisTruth.cub differ