Skip to content

Commit

Permalink
Stretch functional tests (#4154)
Browse files Browse the repository at this point in the history
* stretch updates

* pull request changes

* modified setoutputcube to remove seg fault

* merge with dev + fixed bug

* updating test files

* modified stretch app

* updated mvix

* modified setoutputcube functions with null ui parameter

* modified stretch test and reverted changes involving setoutputcube

* modified setoutputcube function call

* made new setoutputcube for stretch

* added +1 back to user interface, removed duplicate test

* pull request changes

Co-authored-by: Kelvin <[email protected]>
  • Loading branch information
robotprogrammer22 and Kelvin authored Dec 16, 2020
1 parent 936e6fc commit 87c8432
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 107 deletions.
88 changes: 15 additions & 73 deletions isis/src/base/apps/stretch/main.cpp
Original file line number Diff line number Diff line change
@@ -1,84 +1,26 @@
#include "Isis.h"
#include "TextFile.h"
#include "Statistics.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"
#include "Stretch.h"
#include "PvlGroup.h"
#include "PvlKeyword.h"

#include "Application.h"
#include "UserInterface.h"

#include "stretch_app.h"

using namespace std;
using namespace Isis;

void stretch(Buffer &in, Buffer &out);
Stretch str;
Statistics stats;

void IsisMain() {
ProcessByLine p;
Cube *inCube = p.SetInputCube("FROM");

UserInterface &ui = Application::GetUserInterface();

QString pairs;

// first just get the pairs from where ever and worry about
// whether they are dn values or %'s later
if(ui.GetBoolean("READFILE")) {
FileName pairsFileName = ui.GetFileName("INPUTFILE");
TextFile pairsFile;
pairsFile.SetComment("#");
pairsFile.Open(pairsFileName.expanded());

// concat all non-comment lines into one string (pairs)
QString line = "";
while(pairsFile.GetLine(line, true)) {
pairs += " " + line;
}
pairs += line;
Pvl results;
try{
stretch(ui, &results);
}
else {
if(ui.WasEntered("PAIRS"))
pairs = ui.GetString("PAIRS");
}

if(ui.GetBoolean("USEPERCENTAGES")) {
str.Parse(pairs, inCube->histogram());
catch(...){
for (int resultIndex = 0; resultIndex < results.groups(); resultIndex++) {
Application::Log(results.group(resultIndex));
}
throw;
}
else
str.Parse(pairs);

// Setup new mappings for special pixels if necessary
if(ui.WasEntered("NULL"))
str.SetNull(StringToPixel(ui.GetString("NULL")));
if(ui.WasEntered("LIS"))
str.SetLis(StringToPixel(ui.GetString("LIS")));
if(ui.WasEntered("LRS"))
str.SetLrs(StringToPixel(ui.GetString("LRS")));
if(ui.WasEntered("HIS"))
str.SetHis(StringToPixel(ui.GetString("HIS")));
if(ui.WasEntered("HRS"))
str.SetHrs(StringToPixel(ui.GetString("HRS")));

p.SetOutputCube("TO");

// Start the processing
p.StartProcess(stretch);
p.EndProcess();

PvlKeyword dnPairs = PvlKeyword("StretchPairs");
dnPairs.addValue(str.Text());

PvlGroup results = PvlGroup("Results");
results.addKeyword(dnPairs);

Application::Log(results);

}

// Line processing routine
void stretch(Buffer &in, Buffer &out) {
for(int i = 0; i < in.size(); i++) {
out[i] = str.Map(in[i]);
for (int resultIndex = 0; resultIndex < results.groups(); resultIndex++) {
Application::Log(results.group(resultIndex));
}
}
94 changes: 94 additions & 0 deletions isis/src/base/apps/stretch/stretch_app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "TextFile.h"
#include "Statistics.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"
#include "Stretch.h"
#include "PvlGroup.h"
#include "PvlKeyword.h"

#include "stretch_app.h"

namespace Isis {
void stretchProcess(Buffer &in, Buffer &out);
Stretch str;
Statistics stats;

void stretch(UserInterface &ui, Pvl *log) {
Cube *cubeFile = new Cube();
CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
if (inAtt.bands().size() != 0) {
cubeFile->setVirtualBands(inAtt.bands());
}
cubeFile->open(ui.GetFileName("FROM"), "r");

QString pairs;

// first just get the pairs from where ever and worry about
// whether they are dn values or %'s later
if(ui.GetBoolean("READFILE")) {
FileName pairsFileName = ui.GetFileName("INPUTFILE");
TextFile pairsFile;
pairsFile.SetComment("#");
pairsFile.Open(pairsFileName.expanded());

// concat all non-comment lines into one string (pairs)
QString line = "";
while(pairsFile.GetLine(line, true)) {
pairs += " " + line;
}
pairs += line;
}
else {
if(ui.WasEntered("PAIRS"))
pairs = ui.GetString("PAIRS");
}

stretch(cubeFile, pairs, ui, log);
}

void stretch(Cube *inCube, QString &pairs, UserInterface &ui, Pvl *log) {
ProcessByLine p;
p.SetInputCube(inCube);

if(ui.GetBoolean("USEPERCENTAGES")) {
str.Parse(pairs, inCube->histogram());
}
else
str.Parse(pairs);

// Setup new mappings for special pixels if necessary
if(ui.WasEntered("NULL"))
str.SetNull(StringToPixel(ui.GetString("NULL")));
if(ui.WasEntered("LIS"))
str.SetLis(StringToPixel(ui.GetString("LIS")));
if(ui.WasEntered("LRS"))
str.SetLrs(StringToPixel(ui.GetString("LRS")));
if(ui.WasEntered("HIS"))
str.SetHis(StringToPixel(ui.GetString("HIS")));
if(ui.WasEntered("HRS"))
str.SetHrs(StringToPixel(ui.GetString("HRS")));

p.SetOutputCubeStretch("TO", &ui);

// Start the processing
p.StartProcess(stretchProcess);
p.EndProcess();

PvlKeyword dnPairs = PvlKeyword("StretchPairs");
dnPairs.addValue(str.Text());

PvlGroup results = PvlGroup("Results");
results.addKeyword(dnPairs);

if (log){
log->addGroup(results);
}
}

// Line processing routine
void stretchProcess(Buffer &in, Buffer &out) {
for(int i = 0; i < in.size(); i++) {
out[i] = str.Map(in[i]);
}
}
}
14 changes: 14 additions & 0 deletions isis/src/base/apps/stretch/stretch_app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef stretch_app_h
#define stretch_app_h

#include "PvlGroup.h"
#include "PvlKeyword.h"
#include "UserInterface.h"

namespace Isis {
extern void stretch(UserInterface &ui, Pvl *log=nullptr);

extern void stretch(Cube *inCube, QString &pairs, UserInterface &ui, Pvl *log=nullptr);
}

#endif
88 changes: 84 additions & 4 deletions isis/src/base/objs/Process/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,38 @@ namespace Isis {
return SetOutputCube(parameter, ns, nl, nb);
}

/**
* Allocates a user-specified output cube whose size matches the first input
* cube.
*
* @return Cube*
*
* @param parameter User specified output file. For example, "TO" is a popular
* user parameter. If the user specified TO=output.cub, then
* this routine would allocate the file output.cub with size
* specified by the first opened input cube. The output pixel
* type will be propagated from the first loaded input cube or
* will use the value in the application XML file for
* pixelType.
*
* @param ui A user interface used to get the attributes needed for SetOutputCube.
*
* @throws Isis::iException::Message
*/
Isis::Cube *Process::SetOutputCubeStretch(const QString &parameter, UserInterface *ui) {
// Make sure we have an input cube to get a default size from
if(InputCubes.size() == 0) {
QString message = "No input images have been selected ... therefore";
message += "the output image size can not be determined";
throw IException(IException::Programmer, message, _FILEINFO_);
}

int nl = InputCubes[0]->lineCount();
int ns = InputCubes[0]->sampleCount();
int nb = InputCubes[0]->bandCount();
return SetOutputCubeStretch(parameter, ns, nl, nb, ui);
}

/**
* Allocates a user specified output cube whose size is specified by the
* programmer.
Expand Down Expand Up @@ -308,11 +340,59 @@ namespace Isis {
<< ",nb=" << nb << "]";
throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
}
QString fname = Application::GetUserInterface().GetFileName(parameter);
Isis::CubeAttributeOutput &atts = Application::GetUserInterface().GetOutputAttribute(parameter);
QString fname;
Isis::CubeAttributeOutput atts;
fname = Application::GetUserInterface().GetFileName(parameter);
atts = Application::GetUserInterface().GetOutputAttribute(parameter);
return SetOutputCube(fname, atts, ns, nl, nb);
}
}

/**
* Allocates a user specified output cube whose size is specified by the
* programmer.
*
* @return Cube*
*
* @param parameter User specified output file. For example, "TO" is a popular
* user parameter. If the user specified TO=output.cub, then
* this routine would allocate the file output.cub with size
* specified by the first opened input cube. The output pixel
* type will be propagated from the first loaded input cube or
* will use the value in the application XML file for
* pixelType.
*
* @param ns Number of samples to allocate
*
* @param nl Number of lines to allocate
*
* @param nb Number of bands to allocate
*
* @param ui A user interface used to get the attributes needed. If null, the
* user interface will be obtained from the application.
*
* @throws Isis::iException::Message
*/
Isis::Cube *Process::SetOutputCubeStretch(const QString &parameter, const int ns,
const int nl, const int nb, UserInterface *ui) {
// Make sure we have good dimensions
if((ns <= 0) || (nl <= 0) || (nb <= 0)) {
ostringstream message;
message << "Invalid cube size specifications [ns=" << ns << ",nl=" << nl
<< ",nb=" << nb << "]";
throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
}
QString fname;
Isis::CubeAttributeOutput atts;
if(ui==nullptr){
fname = Application::GetUserInterface().GetFileName(parameter);
atts = Application::GetUserInterface().GetOutputAttribute(parameter);
}
else{
fname = ui->GetFileName(parameter);
atts = ui->GetOutputAttribute(parameter);
}
return SetOutputCube(fname, atts, ns, nl, nb);
}

/**
* Allocates a output cube whose name and size is specified by the programmer.
Expand Down Expand Up @@ -408,7 +488,7 @@ namespace Isis {

// Allocate the cube
cube->create(fname);

// Transfer labels from the first input cube
if((p_propagateLabels) && (InputCubes.size() > 0)) {
Isis::PvlObject &incube =
Expand Down
3 changes: 3 additions & 0 deletions isis/src/base/objs/Process/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ namespace Isis {


virtual Isis::Cube *SetOutputCube(const QString &parameter);
virtual Isis::Cube *SetOutputCubeStretch(const QString &parameter, UserInterface *ui=nullptr);
virtual Isis::Cube *SetOutputCube(const QString &parameter, const int nsamps,
const int nlines, const int nbands = 1);
virtual Isis::Cube *SetOutputCubeStretch(const QString &parameter, const int nsamps,
const int nlines, const int nbands = 1, UserInterface *ui=nullptr);
virtual Isis::Cube *SetOutputCube(const QString &fname,
const Isis::CubeAttributeOutput &att,
const int nsamps, const int nlines,
Expand Down
Loading

0 comments on commit 87c8432

Please sign in to comment.