envi.h 1.42 KB
#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{

	envi_header header;

	void* file;		//void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type)

public:

	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<float>());

		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(header.data_type ==envi_header::float32)
				return ((bsq<float>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength);

		//handle other permutations.....

		exit(1);
	}

	bool normalize(std::string outfile, double band){

		if(header.interleave == envi_header::BSQ)
			if(header.data_type ==envi_header::float32)
				return ((bsq<float>*)file)->normalize(outfile, band);

		exit(1);
	}

	bool save_header(std::string filename){

		//save the header file here
		header.save(filename);

		return true;
	}





};

}	//end namespace rts

#endif