00001 #include "ImageArithmaticCube.h" 00002 00003 00004 ImageArithmaticCube::ImageArithmaticCube(int x1, int y1, int w1, int h1) : 00005 ImageCube( x1, y1, w1, h1){ 00006 eqset = false; 00007 calculatedLayer = new std::vector<double>(); 00008 } 00009 00010 00011 ImageArithmaticCube::~ImageArithmaticCube() { 00012 // for(int i=0; i<theCube.size(); i++){ 00013 // delete theCube[i].values; 00014 // } 00015 } 00016 00017 00018 void ImageArithmaticCube::setEquation(std::string eq){ 00019 parser.SetExpr(eq.c_str()); 00020 eqset = true; 00021 } 00022 00023 00024 std::vector<double>* ImageArithmaticCube::calculateLayer(){ 00025 if(!eqset) return NULL;//if the equation is not set, we can't do anythin 00026 bool success = calculate(); 00027 if (success) { 00028 return calculatedLayer; 00029 } 00030 else { 00031 return NULL ; 00032 } 00033 } 00034 00035 00036 bool ImageArithmaticCube::calculate(){ 00037 00038 //holds the variables for the parser 00039 std::vector<double> vars (layers); 00040 00041 //this sets up the variable that will represent the layers 00042 for(int i=0; i<layers; i++){ 00043 std::stringstream ss; 00044 00045 //the layer varible is a b followd by the layer num 00046 //these start at 0 00047 ss << "b" << (theCube[i]).layernum; 00048 00049 //this defines the variable for the parser 00050 parser.DefineVar((ss.str()).c_str(), &(vars[i])) ; 00051 } 00052 00053 00054 int layersize = width * height; 00055 00056 for(int j = 0 ; j < layersize ; j++) { //for each pixel 00057 00058 //set up the variables with the data from that location 00059 for(unsigned int k = 0 ; k < vars.size() ; k++){ 00060 vars[k] = (*(theCube[k].values))[j]; 00061 } 00062 00063 //caculates this location 00064 try { 00065 calculatedLayer->push_back( parser.Eval() ); 00066 } 00067 catch (Parser::exception_type &e) { 00068 QMessageBox::information( 0, "Parsing Error", (e.GetMsg()).c_str()) ; 00069 return false ; 00070 } 00071 } 00072 return true ; 00073 } 00074 00075 00076 std::vector<double>* ImageArithmaticCube::getCalculatedLayer(){ 00077 return calculatedLayer; 00078 } 00079
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |