USGS

Isis 3.0 Application Source Code Reference

Home

poly.cpp

Go to the documentation of this file.
00001 #include <cmath>
00002 #include "Isis.h"
00003 #include "ProcessByLine.h"
00004 #include "SpecialPixel.h"
00005 #include "IException.h"
00006 
00007 using namespace std;
00008 using namespace Isis;
00009 
00010 void poly(Buffer &in, Buffer &out);
00011 
00012 double coefficients[8];
00013 double add;
00014 int order;
00015 
00016 void IsisMain() {
00017   // We will be processing by line
00018   ProcessByLine p;
00019 
00020   // Setup the input and output cubes
00021   p.SetInputCube("FROM");
00022   p.SetOutputCube("TO");
00023 
00024   //  Get user parameters
00025   UserInterface &ui = Application::GetUserInterface();
00026   coefficients[0] = ui.GetDouble("MULT1");
00027   coefficients[1] = ui.GetDouble("MULT2");
00028   coefficients[2] = ui.GetDouble("MULT3");
00029   coefficients[3] = ui.GetDouble("MULT4");
00030   coefficients[4] = ui.GetDouble("MULT5");
00031   coefficients[5] = ui.GetDouble("MULT6");
00032   coefficients[6] = ui.GetDouble("MULT7");
00033   coefficients[7] = ui.GetDouble("MULT8");
00034   add = ui.GetDouble("ADD");
00035 
00036   // Determine the order
00037   for(order = 7; order >= 0; order--) {
00038     if(coefficients[order] != 0.0) break;
00039   }
00040   order += 1;
00041 
00042   // Start the processing
00043   p.StartProcess(poly);
00044   p.EndProcess();
00045 }
00046 
00047 // Line processing routine
00048 void poly(Buffer &in, Buffer &out) {
00049   // Loop for each pixel in the line.
00050   for(int i = 0; i < in.size(); i++) {
00051     if(IsSpecial(in[i])) {
00052       out[i] = in[i];
00053     }
00054     else {
00055       out[i] = add;
00056       for(int j = 1; j <= order; j++) {
00057         out[i] += pow(in[i], j) * coefficients[j-1];
00058       }
00059     }
00060   }
00061 
00062 }