Skip to content
Snippets Groups Projects
Unverified Commit 340f4122 authored by Kaitlyn Lee's avatar Kaitlyn Lee Committed by GitHub
Browse files

Adds image data to the default cube fixture and enlarge tests (#3840)

* refactored enlarge.

* Added setinputcube call.

* Removed return from setinputcube.

* Removed print.

* Added fixture for adding image data to a cube.

* Need to add changed files to a different machine.

* Changed SetOutputCube call so we can pass in the ui object.

* Added enlarge tests.

* Removed Makefile tests.

* Added CubeAttribute.

* Fixed typo.

* Refactored opening input cube
parent ffa861eb
No related branches found
No related tags found
No related merge requests found
...@@ -74,6 +74,15 @@ ...@@ -74,6 +74,15 @@
<change name="Sharmila Prasad" date="2011-09-15"> <change name="Sharmila Prasad" date="2011-09-15">
Fixed issue 0000280 - enlarge fails when run with a batchlist Fixed issue 0000280 - enlarge fails when run with a batchlist
</change> </change>
<change name="Kaitlyn Lee" date="2020-04-09">
The SetOutputCube method from Process we were originally using called
Application::GetUserInterface(), but this became a problem when trying to
call enlarge(), or run the application, programmatically since we are no
longer using Application in the application's cpp file. Changed the call
to the one that takes in a CubeAttribute object. Also, removed the check
to see if an invalid interpolation method was passed in since the UserInterface
class checks and throws the exception and it was unreachable code.
</change>
</history> </history>
<category> <category>
......
#include "enlarge_app.h"
#include "CubeAttribute.h"
#include "Enlarge.h"
#include "IException.h"
#include "ProcessRubberSheet.h"
using namespace std;
using namespace Isis;
namespace Isis{
void enlarge(UserInterface &ui, Pvl *log) {
Cube icube;
CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
if (inAtt.bands().size() != 0) {
icube.setVirtualBands(inAtt.bands());
}
icube.open(ui.GetFileName("FROM"));
enlarge(&icube, ui, log);
}
void enlarge(Cube *icube, UserInterface &ui, Pvl *log) {
ProcessRubberSheet p;
p.SetInputCube(icube);
// Input number of samples, lines, and bands
int ins = icube->sampleCount();
int inl = icube->lineCount();
int inb = icube->bandCount();
// Output samples and lines
int ons, onl;
// Scaling factors
double sampleScale, lineScale;
if(ui.GetString("MODE") == "SCALE") {
// Retrieve the provided scaling factors
sampleScale = ui.GetDouble("SSCALE");
lineScale = ui.GetDouble("LSCALE");
// Calculate the output size. If there is a fractional pixel, round up
ons = (int)ceil(ins * sampleScale);
onl = (int)ceil(inl * lineScale);
}
else {
// Retrieve the provided sample/line dimensions in the output
ons = ui.GetInteger("ONS");
onl = ui.GetInteger("ONL");
// Calculate the scaling factors
sampleScale = (double)ons / (double)ins;
lineScale = (double)onl / (double)inl;
}
// Ensure that the calculated number of output samples and lines is greater
// than the input
if(ons < ins || onl < inl) {
string msg = "Number of output samples/lines must be greater than or equal";
msg = msg + " to the input samples/lines.";
throw IException(IException::User, msg, _FILEINFO_);
}
// Set up the interpolator
Interpolator *interp;
if(ui.GetString("INTERP") == "NEARESTNEIGHBOR") {
interp = new Interpolator(Interpolator::NearestNeighborType);
}
else if(ui.GetString("INTERP") == "BILINEAR") {
interp = new Interpolator(Interpolator::BiLinearType);
}
else { // CUBICCONVOLUTION
interp = new Interpolator(Interpolator::CubicConvolutionType);
}
// Allocate the output file, the number of bands does not change in the output
QString outputFileName = ui.GetFileName("TO");
CubeAttributeOutput &att = ui.GetOutputAttribute("TO");
Cube *ocube = p.SetOutputCube(outputFileName, att, ons, onl, inb);
// Set up the transform object with the calculated scale and number of
// output pixels
//Transform *transform = new Enlarge(icube, sampleScale, lineScale);
Enlarge *transform = new Enlarge(icube, sampleScale, lineScale);
p.StartProcess(*transform, *interp);
PvlGroup resultsGrp = transform->UpdateOutputLabel(ocube);
// Cleanup
icube->close();
ocube->close();
p.EndProcess();
delete transform;
delete interp;
// Write the results to the log
log->addGroup(resultsGrp);
}
}
#ifndef enlarge_app_h
#define enlarge_app_h
#include "Cube.h"
#include "Pvl.h"
#include "UserInterface.h"
namespace Isis{
extern void enlarge(Cube *icube, UserInterface &ui, Pvl *log);
extern void enlarge(UserInterface &ui, Pvl *log);
}
#endif
#include "Isis.h" #include "Isis.h"
#include "Enlarge.h" #include "enlarge_app.h"
#include "IException.h"
#include "ProcessRubberSheet.h" #include "Application.h"
#include "Pvl.h"
using namespace std; using namespace std;
using namespace Isis; using namespace Isis;
void IsisMain() { void IsisMain() {
ProcessRubberSheet p;
// Open the input cube
Cube *icube = p.SetInputCube("FROM");
// Input number of samples, lines, and bands
int ins = icube->sampleCount();
int inl = icube->lineCount();
int inb = icube->bandCount();
// Output samples and lines
int ons, onl;
// Scaling factors
double sampleScale, lineScale;
UserInterface &ui = Application::GetUserInterface(); UserInterface &ui = Application::GetUserInterface();
if(ui.GetString("MODE") == "SCALE") { Pvl appLog;
// Retrieve the provided scaling factors try {
sampleScale = ui.GetDouble("SSCALE"); enlarge(ui, &appLog);
lineScale = ui.GetDouble("LSCALE");
// Calculate the output size. If there is a fractional pixel, round up
ons = (int)ceil(ins * sampleScale);
onl = (int)ceil(inl * lineScale);
} }
else { catch (...) {
// Retrieve the provided sample/line dimensions in the output for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
ons = ui.GetInteger("ONS"); Application::Log(*grpIt);
onl = ui.GetInteger("ONL");
// Calculate the scaling factors
sampleScale = (double)ons / (double)ins;
lineScale = (double)onl / (double)inl;
} }
throw;
// Ensure that the calculated number of output samples and lines is greater
// than the input
if(ons < ins || onl < inl) {
string msg = "Number of output samples/lines must be greater than or equal";
msg = msg + " to the input samples/lines.";
throw IException(IException::User, msg, _FILEINFO_);
} }
// Set up the interpolator for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
Interpolator *interp; Application::Log(*grpIt);
if(ui.GetString("INTERP") == "NEARESTNEIGHBOR") {
interp = new Interpolator(Interpolator::NearestNeighborType);
} }
else if(ui.GetString("INTERP") == "BILINEAR") {
interp = new Interpolator(Interpolator::BiLinearType);
} }
\ No newline at end of file
else if(ui.GetString("INTERP") == "CUBICCONVOLUTION") {
interp = new Interpolator(Interpolator::CubicConvolutionType);
}
else {
QString msg = "Unknown value for INTERP [" +
ui.GetString("INTERP") + "]";
throw IException(IException::Programmer, msg, _FILEINFO_);
}
// Allocate the output file, the number of bands does not change in the output
Cube *ocube = p.SetOutputCube("TO", ons, onl, inb);
// Set up the transform object with the calculated scale and number of
// output pixels
//Transform *transform = new Enlarge(icube, sampleScale, lineScale);
Enlarge *transform = new Enlarge(icube, sampleScale, lineScale);
p.StartProcess(*transform, *interp);
PvlGroup resultsGrp = transform->UpdateOutputLabel(ocube);
// Cleanup
icube->close();
ocube->close();
p.EndProcess();
delete transform;
delete interp;
// Write the results to the log
Application::Log(resultsGrp);
}
BLANKS = "%-6s"
LENGTH = "%-40s"
include $(ISISROOT)/make/isismake.tststree
APPNAME = enlarge
peaks2.cub.TOLERANCE = 16
include $(ISISROOT)/make/isismake.tsts
commands:
$(APPNAME) from=$(INPUT)/peaks.cub \
to=$(OUTPUT)/peaks.cub \
sscale=1.0 \
lscale=1.5 \
interp=bilinear > /dev/null;
lowpass from=$(OUTPUT)/peaks.cub samples=1 lines=5 \
to=$(OUTPUT)/peaks2.cub > /dev/null;
$(RM) $(OUTPUT)/peaks.cub
APPNAME = enlarge
include $(ISISROOT)/make/isismake.tsts
commands:
$(APPNAME) from=$(INPUT)/isisTruth.cub \
to=$(OUTPUT)/total.cub \
mode=total \
ons=126 \
onl=189 \
interp=nearestneighbor > /dev/null;
$(APPNAME) from=$(INPUT)/isisTruth.cub \
to=$(OUTPUT)/scale.cub \
sscale=1.0 \
lscale=1.5 \
interp=nearestneighbor > /dev/null;
cubediff from=$(OUTPUT)/total.cub \
from2=$(OUTPUT)/scale.cub \
to=$(OUTPUT)/comparisonTruth.txt > /dev/null;
rm -f $(OUTPUT)/total.cub;
rm -f $(OUTPUT)/scale.cub;
...@@ -308,12 +308,12 @@ namespace Isis { ...@@ -308,12 +308,12 @@ namespace Isis {
<< ",nb=" << nb << "]"; << ",nb=" << nb << "]";
throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_); throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
} }
QString fname = Application::GetUserInterface().GetFileName(parameter); QString fname = Application::GetUserInterface().GetFileName(parameter);
Isis::CubeAttributeOutput &atts = Application::GetUserInterface().GetOutputAttribute(parameter); Isis::CubeAttributeOutput &atts = Application::GetUserInterface().GetOutputAttribute(parameter);
return SetOutputCube(fname, atts, ns, nl, nb); return SetOutputCube(fname, atts, ns, nl, nb);
} }
/** /**
* Allocates a output cube whose name and size is specified by the programmer. * Allocates a output cube whose name and size is specified by the programmer.
* *
...@@ -350,7 +350,6 @@ namespace Isis { ...@@ -350,7 +350,6 @@ namespace Isis {
cube->setByteOrder(att.byteOrder()); cube->setByteOrder(att.byteOrder());
cube->setFormat(att.fileFormat()); cube->setFormat(att.fileFormat());
cube->setLabelsAttached(att.labelAttachment() == AttachedLabel); cube->setLabelsAttached(att.labelAttachment() == AttachedLabel);
if(att.propagatePixelType()) { if(att.propagatePixelType()) {
if(InputCubes.size() > 0) { if(InputCubes.size() > 0) {
cube->setPixelType(InputCubes[0]->pixelType()); cube->setPixelType(InputCubes[0]->pixelType());
...@@ -468,7 +467,6 @@ namespace Isis { ...@@ -468,7 +467,6 @@ namespace Isis {
delete cube; delete cube;
throw; throw;
} }
// Everything is fine so save the cube on the stack // Everything is fine so save the cube on the stack
AddOutputCube(cube); AddOutputCube(cube);
return cube; return cube;
......
#include "Fixtures.h" #include "Fixtures.h"
#include "LineManager.h"
namespace Isis { namespace Isis {
...@@ -21,6 +23,14 @@ namespace Isis { ...@@ -21,6 +23,14 @@ namespace Isis {
testCube = new Cube(); testCube = new Cube();
testCube->fromIsd(tempDir.path() + "/default.cub", label, isd, "rw"); testCube->fromIsd(tempDir.path() + "/default.cub", label, isd, "rw");
LineManager line(*testCube);
for(line.begin(); !line.end(); line++) {
for(int i = 0; i < line.size(); i++) {
line[i] = (double) 1;
}
testCube->write(line);
}
projTestCube = new Cube(); projTestCube = new Cube();
projTestCube->fromIsd(tempDir.path() + "/default.level2.cub", projLabel, isd, "rw"); projTestCube->fromIsd(tempDir.path() + "/default.level2.cub", projLabel, isd, "rw");
} }
......
...@@ -11,11 +11,10 @@ ...@@ -11,11 +11,10 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "IException.h"
#include "PvlGroup.h"
#include "Cube.h" #include "Cube.h"
#include "IException.h"
#include "Pvl.h" #include "Pvl.h"
#include "PvlGroup.h"
#include "PvlObject.h" #include "PvlObject.h"
#include "ControlNet.h" #include "ControlNet.h"
#include "FileList.h" #include "FileList.h"
......
#include "enlarge_app.h"
#include <QTemporaryFile>
#include <QTextStream>
#include <QStringList>
#include "Fixtures.h"
#include "PvlGroup.h"
#include "TestUtilities.h"
#include "gmock/gmock.h"
using namespace Isis;
static QString APP_XML = FileName("$ISISROOT/bin/xml/enlarge.xml").expanded();
TEST_F(DefaultCube, FunctionalTestEnlargeDefaultParameters) {
QVector<QString> args = {"to=" + tempDir.path()+"/output.cub"};
UserInterface options(APP_XML, args);
Pvl appLog;
enlarge(testCube, options, &appLog);
PvlGroup groundPoint = appLog.findGroup("Results");
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("InputLines"), 10);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("InputSamples"), 10);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("StartingLine"), 1);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("StartingSample"), 1);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("EndingLine"), 10);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("EndingSample"), 10);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("LineIncrement"), 1.0);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("SampleIncrement"), 1.0);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputLines"), 10);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputSamples"), 10);
}
TEST_F(DefaultCube, FunctionalTestEnlargeScale) {
QVector<QString> args = {"to=" + tempDir.path()+"/output.cub", "sscale=2", "lscale=4"};
UserInterface options(APP_XML, args);
Pvl appLog;
enlarge(testCube, options, &appLog);
PvlGroup groundPoint = appLog.findGroup("Results");
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("LineIncrement"), .25);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("SampleIncrement"), .5);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputLines"), 40);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputSamples"), 20);
}
TEST_F(DefaultCube, FunctionalTestEnlargeTotal) {
QVector<QString> args = {"to=" + tempDir.path()+"/output.cub", "mode=total", "ons=20", "onl=40"};
UserInterface options(APP_XML, args);
Pvl appLog;
enlarge(testCube, options, &appLog);
PvlGroup groundPoint = appLog.findGroup("Results");
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("LineIncrement"), .25);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("SampleIncrement"), .5);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputLines"), 40);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputSamples"), 20);
}
TEST_F(DefaultCube, FunctionalTestEnlargeSmallDimensions) {
QVector<QString> args = {"to=" + tempDir.path()+"/output.cub", "mode=total", "ons=10", "onl=1"};
UserInterface options(APP_XML, args);
Pvl appLog;
QString message = "Number of output samples/lines must be greater than or equal";
try {
enlarge(testCube, options, &appLog);
FAIL() << "Expected an exception to be thrown";
}
catch(Isis::IException &e) {
EXPECT_PRED_FORMAT2(Isis::AssertIExceptionMessage, e, message);
}
catch(...) {
FAIL() << "Expected error message: \"" << message.toStdString() << "\"";
}
}
TEST_F(DefaultCube, FunctionalTestEnlargeNearestNeighbor) {
QVector<QString> args = {"to=" + tempDir.path()+"/output.cub", "interp=nearestneighbor"};
UserInterface options(APP_XML, args);
Pvl appLog;
enlarge(testCube, options, &appLog);
PvlGroup groundPoint = appLog.findGroup("Results");
// Just make sure the applications runs without error. Tests the interpolation method in
// the enlarge object.
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("LineIncrement"), 1.0);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("SampleIncrement"), 1.0);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputLines"), 10);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputSamples"), 10);
}
TEST_F(DefaultCube, FunctionalTestEnlargeBilinear) {
QVector<QString> args = {"to=" + tempDir.path()+"/output.cub", "interp=bilinear"};
UserInterface options(APP_XML, args);
Pvl appLog;
enlarge(testCube, options, &appLog);
PvlGroup groundPoint = appLog.findGroup("Results");
// Just make sure the applications runs without error. Tests the interpolation method in
// the enlarge object.
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("LineIncrement"), 1.0);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("SampleIncrement"), 1.0);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputLines"), 10);
EXPECT_DOUBLE_EQ( (double) groundPoint.findKeyword("OutputSamples"), 10);
}
\ No newline at end of file
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment