Commit 0e48cc9cc646f4fc684c85edc06e228c5f7cb6d4

Authored by heziqi
1 parent fc712213

Ziqi added getBand( T* p, Double) in bsq.h

Showing 1 changed file with 49 additions and 1 deletions   Show diff stats
envi/bsq.h
... ... @@ -33,7 +33,7 @@ public:
33 33 }
34 34  
35 35 //save one band of the file into the memory, and return the pointer
36   - bool getBand( T * p, unsigned int page){
  36 + bool band_index( T * p, unsigned int page){
37 37  
38 38 if (page >= header.bands){ //make sure the bank number is right
39 39 std::cout<<"ERROR: page out of range"<<std::endl;
... ... @@ -44,6 +44,52 @@ public:
44 44 return true;
45 45 }
46 46  
  47 + bool getBand( T * p, double wavelength){
  48 +
  49 + unsigned int XY = header.samples * header.lines; //calculate the number of pixels in a band
  50 +
  51 + unsigned page=0; //bands around the wavelength
  52 + T * p1;
  53 + T * p2;
  54 +
  55 + //get the bands numbers around the wavelength
  56 +
  57 + //if wavelength is smaller than the first one in header file
  58 + if ( header.wavelength[page] > wavelength ){
  59 + band_index(p, page);
  60 + return true;
  61 + }
  62 +
  63 + while( header.wavelength[page] < wavelength )
  64 + {
  65 + page++;
  66 + //if wavelength is larger than the last wavelength in header file
  67 + if (page == header.bands) {
  68 + getSlice(p, 2, header.bands-1);
  69 + return true;
  70 + }
  71 + }
  72 + if ( wavelength < header.wavelength[page] )
  73 + {
  74 + p1=(T*)malloc( XY * sizeof(T)); //memory allocation
  75 + p2=(T*)malloc( XY * sizeof(T));
  76 + band_index(p1, page - 1);
  77 + band_index(p2, page );
  78 + for(unsigned i=0; i < XY; i++){
  79 + double r = (double) (wavelength - header.wavelength[page-1]) / (double) (header.wavelength[page] - header.wavelength[page-1]);
  80 + p[i] = (p2[i] - p1[i]) * r + p1[i];
  81 + }
  82 + }
  83 + else //if the wavelength is equal to a wavelength in header file
  84 + {
  85 + getSlice(p, 2, page);
  86 + }
  87 +
  88 + free(p1);
  89 + free(p2);
  90 + return true;
  91 + }
  92 +
47 93 //save one pixel of the file into the memory, and return the pointer
48 94 bool getSpectrum(T * p, unsigned x, unsigned y){
49 95  
... ... @@ -61,6 +107,8 @@ public:
61 107 file.seekg((header.lines * header.samples - 1) * sizeof(T), std::ios::cur); //go to the next band
62 108 }
63 109  
  110 + free(p1);
  111 + free(p2);
64 112 return true;
65 113 }
66 114  
... ...