-
Notifications
You must be signed in to change notification settings - Fork 169
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 Co-authored-by: Kelvin <kelvinrr@icloud.com>
- Loading branch information
1 parent
10fe7dd
commit 16d9240
Showing
8 changed files
with
149 additions
and
98 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,93 @@ | ||
#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"); | ||
stretch(cubeFile, ui, log); | ||
} | ||
|
||
void stretch(Cube *inCube, UserInterface &ui, Pvl *log) { | ||
ProcessByLine p; | ||
p.SetInputCube(inCube); | ||
|
||
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"); | ||
} | ||
|
||
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.SetOutputCube("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, 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
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
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