#ifndef STIM_ENVI_H #define STIM_ENVI_H #include "../envi/envi_header.h" #include "../envi/bsq.h" #include "../envi/bip.h" #include "../envi/bil.h" namespace rts{ //container class for an ENVI binary file reader class envi{ void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type) public: envi_header header; bool allocate(){ file = NULL; //set file to a NULL pointer if(header.interleave == envi_header::BSQ){ if(header.data_type ==envi_header::float32) return(file = new bsq()); else if(header.data_type == envi_header::float64) return(file = new bsq()); } else if(header.interleave == envi_header::BIP){ if(header.data_type ==envi_header::float32) return(file = new bip()); else if(header.data_type == envi_header::float64) return(file = new bip()); } else if(header.interleave == envi_header::BIL){ if(header.data_type ==envi_header::float32) return(file = new bil()); else if(header.data_type == envi_header::float64) return(file = new bil()); } exit(1); //if the function hasn't already returned, we don't handle this state } bool open(std::string filename, std::string headername){ //allocate memory allocate(); //load the header header.load(headername); //load the file if(header.interleave == envi_header::BSQ) { //if the infile is bsq file if(header.data_type == envi_header::float32) { return ((bsq*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); } else if(header.data_type == envi_header::float64) { return ((bsq*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); } else return false; } else if(header.interleave == envi_header::BIL) { //if the infile is bil file if(header.data_type == envi_header::float32) { return ((bil*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); } else if(header.data_type == envi_header::float64) { return ((bil*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); } else return false; } else if(header.interleave == envi_header::BIP) { //if the infile is bip file if(header.data_type == envi_header::float32) { return ((bip*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); } else if(header.data_type == envi_header::float64) { return ((bip*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); } else return false; } else{ std::cout<<"ERROR: unidentified type file "<*)file)->normalize(outfile, band); else if(header.data_type == envi_header::float64) return ((bsq*)file)->normalize(outfile,band); else std::cout<<"ERROR: unidentified data type"<*)file)->normalize(outfile, band); else if(header.data_type == envi_header::float64) return ((bil*)file)->normalize(outfile,band); else std::cout<<"ERROR: unidentified data type"<*)file)->normalize(outfile, band); else if(header.data_type == envi_header::float64) return ((bip*)file)->normalize(outfile,band); else std::cout<<"ERROR: unidentified data type"< w){ if(header.interleave == envi_header::BSQ){ //if the infile is bsq file if(header.data_type ==envi_header::float32) return ((bsq*)file)->baseline(outfile, w); else if(header.data_type == envi_header::float64) return ((bsq*)file)->baseline(outfile,w); else{ std::cout<<"ERROR: unidentified data type"<*)file)->baseline(outfile, w); else if(header.data_type == envi_header::float64) return ((bil*)file)->baseline(outfile, w); else{ std::cout<<"ERROR: unidentified data type"<*)file)->baseline(outfile, w); else if(header.data_type == envi_header::float64) return ((bip*)file)->baseline(outfile, w); else{ std::cout<<"ERROR: unidentified data type"<*)file)->bil(outfile); else if(interleave == envi_header::BIP) //if the target file is bip file return ((bsq*)file)->bip(outfile); } else if(header.data_type == envi_header::float64){ //if the data type is float if(interleave == envi_header::BSQ){ std::cout<<"ERROR: is already BSQ file"<*)file)->bil(outfile); else if(interleave == envi_header::BIP) return ((bsq*)file)->bip(outfile); } else{ std::cout<<"ERROR: unidentified data type"<*)file)->bsq(outfile); else if(interleave == envi_header::BIP) //if the target file is bip file return ((bil*)file)->bip(outfile); } else if(header.data_type == envi_header::float64){ //if the data type is float if(interleave == envi_header::BIL){ std::cout<<"ERROR: is already BIL file"<*)file)->bsq(outfile); else if(interleave == envi_header::BIP) return ((bil*)file)->bip(outfile); } else{ std::cout<<"ERROR: unidentified data type"<*)file)->bil(outfile); else if(interleave == envi_header::BSQ) //if the target file is bsq file return ((bip*)file)->bsq(outfile); } else if(header.data_type == envi_header::float64){ //if the data type is float if(interleave == envi_header::BIP){ std::cout<<"ERROR: is already BIP file"<*)file)->bil(outfile); else if(interleave == envi_header::BSQ) //if the target file is bsq file return ((bip*)file)->bsq(outfile); } else{ std::cout<<"ERROR: unidentified data type"<*)file)->mask(p, mask_band, threshold); else if(header.data_type == envi_header::float64) return ((bsq*)file)->mask(p, mask_band, threshold); else std::cout<<"ERROR: unidentified data type"<*)file)->mask(p, mask_band, threshold); else if(header.data_type == envi_header::float64) return ((bil*)file)->mask(p, mask_band, threshold); else std::cout<<"ERROR: unidentified data type"<*)file)->mask(p, mask_band, threshold); else if(header.data_type == envi_header::float64) return ((bip*)file)->mask(p, mask_band, threshold); else std::cout<<"ERROR: unidentified data type"<*)file)->area(lb, rb); else if(header.data_type == envi_header::float64) return ((bsq*)file)->area(lb, rb); else std::cout<<"ERROR: unidentified data type"<*)file)->area(lb, rb); else if(header.data_type == envi_header::float64) return ((bil*)file)->area(lb, rb); else std::cout<<"ERROR: unidentified data type"<*)file)->area(lb, rb); else if(header.data_type == envi_header::float64) return ((bip*)file)->area(lb, rb); else std::cout<<"ERROR: unidentified data type"<*)file)->close(); else if(header.data_type == envi_header::float64) return ((bsq*)file)->close(); else{ std::cout<<"ERROR: unidentified data type"<*)file)->close(); else if(header.data_type == envi_header::float64) return ((bil*)file)->close(); else{ std::cout<<"ERROR: unidentified data type"<*)file)->close(); else if(header.data_type == envi_header::float64) return ((bip*)file)->close(); else{ std::cout<<"ERROR: unidentified data type"<