forked from DOI-USGS/ISIS3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Algebra has been refactored to be callable; old Makefile tests have b…
…een converted to gtests and removed. Addresses DOI-USGS#5594.
- Loading branch information
1 parent
2e5c3be
commit 647f7b6
Showing
12 changed files
with
735 additions
and
198 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
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,178 @@ | ||
/** 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 "algebra.h" | ||
|
||
#include "Cube.h" | ||
#include "FileName.h" | ||
#include "ProcessByLine.h" | ||
#include "SpecialPixel.h" | ||
|
||
namespace Isis { | ||
|
||
/* | ||
* Algebra | ||
* | ||
* This program performs simple algebra on either one or two | ||
* cubes. The two cubes may be added, subtracted, multiplied or divided. | ||
* | ||
* The following equations are used: | ||
* UNARY: out = (A * from1) + C | ||
* ADD: out = ((from1 - D) * A) + ((from2 - E) * B) + C | ||
* SUBTRACT: out = ((from1 - D) * A) - ((from2 - E) * B) + C | ||
* MULTIPLY: out = ((from1 - D) * A) * ((from2 - E) * B) + C | ||
* DIVIDE: out = ((from1 - D) * A) / ((from2 - E) * B) + C | ||
* | ||
* The FROM2 cube must have either one band or the same number of bands | ||
* as the FROM cube. If the FROM2 cube has one band, then the algebraic | ||
* formula will be applied to all bands in FROM using that single band | ||
* in FROM2. If FROM2 is a multi-band cube, the algebra will be performed | ||
* between corresponding bands from FROM and FROM2. | ||
* | ||
* @param ui UserInterface object containing parameters | ||
*/ | ||
void algebra(UserInterface &ui) { | ||
Cube* icube1 = new Cube(); | ||
icube1->open(ui.GetCubeName("FROM")); | ||
|
||
Cube* icube2 = nullptr; | ||
if(ui.WasEntered("FROM2")) { | ||
icube2 = new Cube(); | ||
icube2->open(ui.GetCubeName("FROM2")); | ||
} | ||
|
||
algebra(icube1, ui, icube2); | ||
} | ||
|
||
|
||
/* | ||
* Algebra | ||
* | ||
* This program performs simple algebra on either one or two | ||
* cubes. The two cubes may be added, subtracted, multiplied or divided. | ||
* | ||
* The following equations are used: | ||
* UNARY: out = (A * from1) + C | ||
* ADD: out = ((from1 - D) * A) + ((from2 - E) * B) + C | ||
* SUBTRACT: out = ((from1 - D) * A) - ((from2 - E) * B) + C | ||
* MULTIPLY: out = ((from1 - D) * A) * ((from2 - E) * B) + C | ||
* DIVIDE: out = ((from1 - D) * A) / ((from2 - E) * B) + C | ||
* | ||
* The FROM2 cube must have either one band or the same number of bands | ||
* as the FROM cube. If the FROM2 cube has one band, then the algebraic | ||
* formula will be applied to all bands in FROM using that single band | ||
* in FROM2. If FROM2 is a multi-band cube, the algebra will be performed | ||
* between corresponding bands from FROM and FROM2. | ||
* | ||
* @param icube1 Cube* input cube1 | ||
* @param ui UserInterface object containing parameters | ||
* @param icube2 Cube* input cube2; optional second input cube | ||
*/ | ||
void algebra(Cube* icube1, UserInterface &ui, Cube* icube2) { | ||
|
||
// Processing by line | ||
ProcessByLine p; | ||
|
||
// Set input cubes and attributes into ProcessByLine p | ||
CubeAttributeInput inatts1 = ui.GetInputAttribute("FROM"); | ||
CubeAttributeInput inatts2; | ||
p.SetInputCube(icube1->fileName(), inatts1); | ||
if(icube2 != nullptr) { | ||
inatts2 = ui.GetInputAttribute("FROM2"); | ||
p.SetInputCube(icube2->fileName(), inatts2); | ||
} | ||
|
||
// Set output cube and attributes into ProcessByLine p | ||
QString outCubeFname = ui.GetCubeName("TO"); | ||
CubeAttributeOutput &outatts = ui.GetOutputAttribute("TO"); | ||
p.SetOutputCube(outCubeFname, outatts); | ||
|
||
// Get the coefficients | ||
double Isisa = ui.GetDouble("A"); | ||
double Isisb = ui.GetDouble("B"); | ||
double Isisc = ui.GetDouble("C"); | ||
double Isisd = ui.GetDouble("D"); | ||
double Isise = ui.GetDouble("E"); | ||
|
||
QString op = ui.GetString("OPERATOR"); | ||
|
||
//***************************************** | ||
// Lambda functions to perform operations * | ||
//***************************************** | ||
|
||
// operatorProcess for add, subtract, multiply, divide | ||
auto operatorProcess = [&](std::vector<Buffer *> &in, std::vector<Buffer *> &out)->void { | ||
Buffer &inp1 = *in[0]; | ||
Buffer &inp2 = *in[1]; | ||
Buffer &outp = *out[0]; | ||
|
||
// Loop for each pixel in the line | ||
// Special pixel propagation: | ||
// 1) special pixels in inp1 propagate to output cube unchanged | ||
// 2) if inp1 is not special and inp2 is, the output pixel is set to Null | ||
for(int i = 0; i < inp1.size(); i++) { | ||
if(IsSpecial(inp1[i])) { | ||
outp[i] = inp1[i]; | ||
} | ||
else if(IsSpecial(inp2[i])) { | ||
outp[i] = NULL8; | ||
} | ||
else { | ||
double operand1 = (inp1[i] - Isisd) * Isisa; | ||
double operand2 = (inp2[i] - Isise) * Isisb; | ||
if(op == "ADD") { | ||
outp[i] = (operand1 + operand2) + Isisc; | ||
} | ||
if(op == "SUBTRACT") { | ||
outp[i] = (operand1 - operand2) + Isisc; | ||
} | ||
if(op == "MULTIPLY") { | ||
outp[i] = (operand1 * operand2) + Isisc; | ||
} | ||
if(op == "DIVIDE") { | ||
if((inp2[i] - Isise) * Isisb == 0.0) { | ||
outp[i] = NULL8; | ||
} | ||
else { | ||
outp[i] = (operand1 / operand2) + Isisc; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// Unary process | ||
auto unaryProcess = [&](Buffer &in, Buffer &out)->void { | ||
// Loop for each pixel in the line. | ||
// Special pixels propagate directly to output | ||
for(int i = 0; i < in.size(); i++) { | ||
if(IsSpecial(in[i])) { | ||
out[i] = in[i]; | ||
} | ||
else { | ||
out[i] = in[i] * Isisa + Isisc; | ||
} | ||
} | ||
}; | ||
|
||
//***************************************** | ||
// End Lambda functions * | ||
//***************************************** | ||
|
||
// Start processing based on the operator | ||
if(op == "UNARY") { | ||
p.ProcessCube(unaryProcess); | ||
} | ||
else { | ||
p.ProcessCubes(operatorProcess); // add, subtract, multiply, divide | ||
} | ||
|
||
p.EndProcess(); | ||
} | ||
} | ||
|
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,19 @@ | ||
/** 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 algebra_h | ||
#define algebra_h | ||
|
||
#include "UserInterface.h" | ||
|
||
namespace Isis{ | ||
extern void algebra(UserInterface &ui); | ||
extern void algebra(Cube* icube1, UserInterface &ui, Cube* icube2=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,146 +1,21 @@ | ||
#include "Isis.h" | ||
#include "ProcessByBrick.h" | ||
#include "ProcessByLine.h" | ||
#include "SpecialPixel.h" | ||
#include "IException.h" | ||
|
||
using namespace std; | ||
using namespace Isis; | ||
/** This is free and unencumbered software released into the public domain. | ||
void add(vector<Buffer *> &in, | ||
vector<Buffer *> &out); | ||
void sub(vector<Buffer *> &in, | ||
vector<Buffer *> &out); | ||
void mult(vector<Buffer *> &in, | ||
vector<Buffer *> &out); | ||
void divide(vector<Buffer *> &in, | ||
vector<Buffer *> &out); | ||
void unaryFunction(Buffer &in, Buffer &out); | ||
|
||
double Isisa, Isisb, Isisc, Isisd, Isise; | ||
|
||
void IsisMain() { | ||
std::cout << "algebra - got to main...\n"; | ||
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. **/ | ||
|
||
// We will be processing by line | ||
ProcessByLine p; | ||
|
||
// Setup the input and output files | ||
UserInterface &ui = Application::GetUserInterface(); | ||
// Setup the input and output cubes | ||
p.SetInputCube("FROM"); | ||
if(ui.WasEntered("FROM2")) p.SetInputCube("FROM2"); | ||
p.SetOutputCube("TO"); | ||
|
||
// Get the coefficients | ||
Isisa = ui.GetDouble("A"); | ||
Isisb = ui.GetDouble("B"); | ||
Isisc = ui.GetDouble("C"); | ||
Isisd = ui.GetDouble("D"); | ||
Isise = ui.GetDouble("E"); | ||
|
||
// Start the processing based on the operator | ||
QString op = ui.GetString("OPERATOR"); | ||
if(op == "ADD") p.ProcessCubes(&add); | ||
if(op == "SUBTRACT") p.ProcessCubes(&sub); | ||
if(op == "MULTIPLY") p.ProcessCubes(&mult); | ||
if(op == "DIVIDE") p.ProcessCubes(÷); | ||
if(op == "UNARY") p.ProcessCube(&unaryFunction); | ||
} | ||
/* SPDX-License-Identifier: CC0-1.0 */ | ||
|
||
// Add routine | ||
void add(vector<Buffer *> &in, vector<Buffer *> &out) { | ||
Buffer &inp1 = *in[0]; | ||
Buffer &inp2 = *in[1]; | ||
Buffer &outp = *out[0]; | ||
// Loop for each pixel in the line. | ||
for(int i = 0; i < inp1.size(); i++) { | ||
if(IsSpecial(inp1[i])) { | ||
outp[i] = inp1[i]; | ||
} | ||
else if(IsSpecial(inp2[i])) { | ||
outp[i] = NULL8; | ||
} | ||
else { | ||
outp[i] = ((inp1[i] - Isisd) * Isisa) + ((inp2[i] - Isise) * Isisb) + Isisc; | ||
} | ||
} | ||
} | ||
|
||
// Sub routine | ||
void sub(vector<Buffer *> &in, vector<Buffer *> &out) { | ||
Buffer &inp1 = *in[0]; | ||
Buffer &inp2 = *in[1]; | ||
Buffer &outp = *out[0]; | ||
|
||
// Loop for each pixel in the line. | ||
for(int i = 0; i < inp1.size(); i++) { | ||
if(IsSpecial(inp1[i])) { | ||
outp[i] = inp1[i]; | ||
} | ||
else if(IsSpecial(inp2[i])) { | ||
outp[i] = NULL8; | ||
} | ||
else { | ||
outp[i] = ((inp1[i] - Isisd) * Isisa) - ((inp2[i] - Isise) * Isisb) + Isisc; | ||
} | ||
} | ||
} | ||
#include "Isis.h" | ||
|
||
// Sub routine | ||
void mult(vector<Buffer *> &in, vector<Buffer *> &out) { | ||
Buffer &inp1 = *in[0]; | ||
Buffer &inp2 = *in[1]; | ||
Buffer &outp = *out[0]; | ||
#include "algebra.h" | ||
|
||
// Loop for each pixel in the line. | ||
for(int i = 0; i < inp1.size(); i++) { | ||
if(IsSpecial(inp1[i])) { | ||
outp[i] = inp1[i]; | ||
} | ||
else if(IsSpecial(inp2[i])) { | ||
outp[i] = NULL8; | ||
} | ||
else { | ||
outp[i] = ((inp1[i] - Isisd) * Isisa) * ((inp2[i] - Isise) * Isisb) + Isisc; | ||
} | ||
} | ||
} | ||
#include "Application.h" | ||
|
||
// Div routine | ||
void divide(vector<Buffer *> &in, vector<Buffer *> &out) { | ||
Buffer &inp1 = *in[0]; | ||
Buffer &inp2 = *in[1]; | ||
Buffer &outp = *out[0]; | ||
using namespace Isis; | ||
|
||
// Loop for each pixel in the line. | ||
for(int i = 0; i < inp1.size(); i++) { | ||
if(IsSpecial(inp1[i])) { | ||
outp[i] = inp1[i]; | ||
} | ||
else if(IsSpecial(inp2[i])) { | ||
outp[i] = NULL8; | ||
} | ||
else { | ||
if((inp2[i] - Isise) * Isisb == 0.0) { | ||
outp[i] = NULL8; | ||
} | ||
else { | ||
outp[i] = ((inp1[i] - Isisd) * Isisa) / ((inp2[i] - Isise) * Isisb) + Isisc; | ||
} | ||
} | ||
} | ||
void IsisMain() { | ||
UserInterface &ui = Application::GetUserInterface(); | ||
algebra(ui); | ||
} | ||
|
||
// Unary routine | ||
void unaryFunction(Buffer &in, Buffer &out) { | ||
// Loop for each pixel in the line. | ||
for(int i = 0; i < in.size(); i++) { | ||
if(IsSpecial(in[i])) { | ||
out[i] = in[i]; | ||
} | ||
else { | ||
out[i] = in[i] * Isisa + Isisc; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.