Commit 3fc1d46151e91bce5aedae676e81a9b1dd196e27

Authored by heziqi
1 parent 1f2ca8ec

Ziqi added saveBand, saveSpectrum in bsq.h

Showing 1 changed file with 64 additions and 0 deletions   Show diff stats
envi/bsq.h
  1 +#include "../envi/envi.h"
  2 +#include "../envi/binary.h"
  3 +
  4 +namespace rts{
  5 +
  6 +template <typename T>
  7 +
  8 +class bsq: public binary<T> {
  9 +
  10 +protected:
  11 +
  12 + envi header;
  13 +
  14 +public:
  15 +
  16 + //open a file, given the file and its header's names
  17 + bool open(std::string filename, std::string headername){
  18 +
  19 + if (header.load(headername)==false){
  20 + std::cout<<"ERROR: unable to load head file"<<std::endl;
  21 + return false;
  22 + }
  23 +
  24 + binary::open(filename, (header.samples, header.lines, header.bands), header.header_offset);
  25 + return true;
  26 +
  27 + }
  28 +
  29 + //save one band of the file into the memory, and return the pointer
  30 + bool saveBand( T * p, unsigned int page){
  31 +
  32 + if (page >= header.bands){ //make sure the bank number is right
  33 + std::cout<<"ERROR: page out of range"<<std::endl;
  34 + return false;
  35 + }
  36 +
  37 + file.seekg(header.lines * header.samples * page * sizeof(T), ios::beg); //write into memory from the binary file
  38 + file.read((char *)p, header.lines * header.samples * sizeof(T));
  39 +
  40 + return true;
  41 + }
  42 +
  43 + //save one pixel of the file into the memory, and return the pointer
  44 + bool saveSpectrum(T * p, unsigned x, unsigned y){
  45 +
  46 + unsigned int i;
  47 +
  48 + if ( x >= header.samples || y >= header.lines){ //make sure the sample and line number is right
  49 + std::cout<<"ERROR: sample or line out of range"<<std::endl;
  50 + return false;
  51 + }
  52 +
  53 + file.seekg((x + y * header.samples) * sizeof(T), ios::beg); //point to the certain sample and line
  54 + for (i = 0; i < header.bands; i++)
  55 + {
  56 + file.read((char *)(p + i), sizeof(T));
  57 + file.seekg((header.lines * header.samples - 1) * sizeof(T), ios::cur); //go to the next band
  58 + }
  59 +
  60 + return true;
  61 + }
  62 +
  63 + };
  64 +}
... ...