-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
936e6fc
commit 87c8432
Showing
9 changed files
with
305 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.