00001 #include "ImageCube.h" 00002 00003 ImageCube::ImageCube(int x, int y, int w, int h, ImageInterface* theimage){ 00004 image = theimage; 00005 00006 width = w; 00007 height = h; 00008 layers = image->getBands(); 00009 00010 lowestPoint.x = x; 00011 lowestPoint.y = y; 00012 lowestPoint.z = -1; 00013 00014 highestPoint.x = (x+w)-1; 00015 highestPoint.y = (y+h)-1; 00016 highestPoint.z = -1; 00017 00018 addBands(image->getCubeAllBands((int)(lowestPoint.x + 0.5), 00019 (int)(lowestPoint.y + 0.5), 00020 (int)(highestPoint.x + 0.5), 00021 (int)(highestPoint.y + 0.5))); 00022 } 00023 00024 ImageCube::ImageCube(int x, int y, int w, int h){ 00025 00026 width = w; 00027 height = h; 00028 layers = 0; 00029 00030 lowestPoint.x = x; 00031 lowestPoint.y = y; 00032 lowestPoint.z = -1; 00033 00034 highestPoint.x = (x+w)-1; 00035 highestPoint.y = (y+h)-1; 00036 highestPoint.z = -1; 00037 00038 } 00039 00040 00041 ImageCube::~ImageCube() { 00042 for(unsigned int i = 0 ; i < theCube.size() ; i++){ 00043 delete theCube[i].values; 00044 } 00045 } 00046 00047 00048 std::vector<double> * ImageCube::getValuesOf(int z) { 00049 return theCube[z].values ; 00050 } 00051 00052 00053 double ImageCube::getValueAtLocal(int x, int y, int z){ 00054 if (x < 0 || y < 0) { 00055 return -99.99 ; 00056 } 00057 00058 int index = z; 00059 00060 if(theCube[z].layernum != z){//if the layers aren't in order 00061 for(unsigned int i = 0 ; i < theCube.size() ; i++){ 00062 if(theCube[i].layernum == z) {//find the correct layer 00063 index = i; 00064 break; 00065 } 00066 } 00067 if(index == z) return 0;//if the layer isn't there... 00068 } 00069 00070 return (*(theCube[index].values))[((y*(width))+(x))] ; 00071 } 00072 00073 00074 double ImageCube::getValueAtOverall(int x, int y, int z){ 00075 int nx = (int)(x - lowestPoint.x) ; 00076 int ny = (int)(y - lowestPoint.y) ; 00077 return getValueAtLocal(nx, ny, z); 00078 } 00079 00080 ImageCube::ThreeDPoint ImageCube::getLowestPoint(){ 00081 return lowestPoint; 00082 } 00083 00084 ImageCube::ThreeDPoint ImageCube::getHighestPoint(){ 00085 return highestPoint; 00086 } 00087 00088 bool ImageCube::addBand(std::vector<double>* vals){ 00089 Layer* templayer = new Layer(); 00090 templayer->values = vals; 00091 templayer->layernum = layers; 00092 00093 theCube.push_back(*templayer); 00094 layers++; 00095 00096 return true; 00097 } 00098 00099 bool ImageCube::addBand(std::vector<double>* vals, int layernum){ 00100 00101 Layer* templayer = new Layer(); 00102 templayer->values = vals; 00103 templayer->layernum = layernum; 00104 00105 std::vector<Layer>::iterator it = theCube.begin(); 00106 bool inserted = false; 00107 while ( it != theCube.end() && !inserted ){ 00108 if((*it).layernum > layernum){ 00109 theCube.insert(it, *templayer); 00110 inserted = true; 00111 } 00112 it++; 00113 } 00114 00115 00116 if(!inserted){ 00117 theCube.push_back(*templayer); 00118 } 00119 layers++; 00120 return true; 00121 00122 } 00123 00124 00125 bool ImageCube::addBands(std::vector<double>* vals){ 00126 int blocksize = width * height; 00127 00128 if(((vals->size()) % blocksize) != 0) { 00129 QMessageBox::information( 0, "ImageCube Error", "Input vector size does not match expected." ); 00130 return false; 00131 } 00132 00133 int blocknum = (vals->size()) / blocksize; 00134 std::vector<double>* temp = new std::vector<double>(blocksize); 00135 00136 for(int i = 0 ; i < blocknum ; i++){ 00137 for(int j = 0 ; j < blocksize ; j++){ 00138 (*temp)[j] = (*vals)[(i*blocksize)+j]; 00139 } 00140 00141 addBand(temp); 00142 temp = new std::vector<double>(blocksize); 00143 } 00144 00145 return true; 00146 00147 } 00148 00149
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |