From 7d43100a324109f10f92d2a4127868f320f39ead Mon Sep 17 00:00:00 2001 From: dmayerich Date: Tue, 10 Sep 2013 10:21:59 -0500 Subject: [PATCH] allow appending to binary files --- defaults.h | 3 ++- fileout.cu | 8 +++----- fileout.h | 4 +++- main.cpp | 4 ++-- options.h | 6 +++++- rtsEnvi.h | 610 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- scalarslice.cu | 6 +----- 7 files changed, 16 insertions(+), 625 deletions(-) delete mode 100644 rtsEnvi.h diff --git a/defaults.h b/defaults.h index d2bc201..dc5182f 100644 --- a/defaults.h +++ b/defaults.h @@ -32,6 +32,7 @@ //default flags #define DEFAULT_PLANEWAVE false #define DEFAULT_VECTORSIM false +#define DEFAULT_APPEND false //#define DEFAULT_OUTPUT_POINT fileoutStruct::imageObjective @@ -72,7 +73,7 @@ #define DEFAULT_PADDING 1 #define DEFAULT_SUPERSAMPLE 1 -#define DEFAULT_INTENSITY_FILE "out_di.bmp" +#define DEFAULT_INTENSITY_FILE "testappend" #define DEFAULT_TRANSMITTANCE_FILE "" #define DEFAULT_ABSORBANCE_FILE "" #define DEFAULT_NEAR_FILE "out_n.bmp" diff --git a/fileout.cu b/fileout.cu index 9dc7bcd..076ea1a 100644 --- a/fileout.cu +++ b/fileout.cu @@ -113,9 +113,7 @@ void fileoutStruct::saveDetector(microscopeStruct* scope) scalarslice I = scope->getIntensity(); if(is_binary(intFile)) - I.toEnvi(intFile, scope->nf.lambda); - else - I.toImage(intFile); + I.toEnvi(intFile, scope->nf.lambda, append); } //absorbance if(absFile != "") @@ -123,7 +121,7 @@ void fileoutStruct::saveDetector(microscopeStruct* scope) scalarslice I = scope->getAbsorbance(); if(is_binary(absFile)) - I.toEnvi(absFile, scope->nf.lambda); + I.toEnvi(absFile, scope->nf.lambda, append); else I.toImage(absFile); } @@ -133,7 +131,7 @@ void fileoutStruct::saveDetector(microscopeStruct* scope) scalarslice I = scope->getTransmittance(); if(is_binary(transFile)) - I.toEnvi(transFile, scope->nf.lambda); + I.toEnvi(transFile, scope->nf.lambda, append); else I.toImage(transFile); } diff --git a/fileout.h b/fileout.h index e3f8887..d312e8c 100644 --- a/fileout.h +++ b/fileout.h @@ -18,7 +18,9 @@ struct fileoutStruct{ std::string farFile; //far field filename std::string intFile; //detector intensity filename std::string absFile; //detector absorbance filename - std::string transFile; //detector transmission filename + std::string transFile; //detector transmission filename + + bool append; //append simulation results to existing binary files //output type enum field_type {fieldMag, fieldIntensity, fieldAbsorbance, fieldPolar, fieldImag, fieldReal, fieldAngularSpectrum}; diff --git a/main.cpp b/main.cpp index dfdba62..f5e80ca 100644 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,7 @@ microscopeStruct* SCOPE; #include "rts/rtsMatrix.h" #include "rts/rtsQuaternion.h" -#include "rtsEnvi.h" +#include "envi/rtsEnvi.h" #include "warnings.h" @@ -60,6 +60,6 @@ int main(int argc, char *argv[]) SCOPE->destroy(); - + } diff --git a/options.h b/options.h index dd0878e..8d76646 100644 --- a/options.h +++ b/options.h @@ -135,7 +135,7 @@ static void loadMaterials(po::variables_map vm) exit(1); } - + for(int i=0; i newM(vm["lambda"].as(), matVec[i], matVec[i+1]); @@ -252,6 +252,10 @@ static void loadMicroscopeParams(po::variables_map vm) static void loadOutputParams(po::variables_map vm) { + //append simulation results to previous binary files + gFileOut.append = DEFAULT_APPEND; + if(vm.count("append")) + gFileOut.append = true; //image parameters //component of the field to be saved diff --git a/rtsEnvi.h b/rtsEnvi.h deleted file mode 100644 index 250526c..0000000 --- a/rtsEnvi.h +++ /dev/null @@ -1,610 +0,0 @@ -#ifndef RTS_ENVI_H -#define RTS_ENVI_H - -#include -#include -#include -#include - -/* This is a class for reading and writing ENVI binary files. This class will be updated as needed. - -What this class CAN currently do: - *) Write band images to a BSQ file. - *) Append band images to a BSQ file. - -*/ - -//information from an ENVI header file -//A good resource can be found here: http://www.exelisvis.com/docs/enviheaderfiles.html -struct EnviHeader -{ - std::string name; - - std::string description; - - unsigned int samples; //x-axis - unsigned int lines; //y-axis - unsigned int bands; //spectral axis - unsigned int header_offset; //header offset for binary file (in bytes) - std::string file_type; //should be "ENVI Standard" - unsigned int data_type; //data representation; common value is 4 (32-bit float) - - enum interleaveType {BIP, BIL, BSQ}; //bip = Z,X,Y; bil = X,Z,Y; bsq = X,Y,Z - interleaveType interleave; - - std::string sensor_type; //not really used - - enum endianType {endianLittle, endianBig}; - endianType byte_order; //little = least significant bit first (most systems) - - double x_start, y_start; //coordinates of the upper-left corner of the image - std::string wavelength_units; //stored wavelength units - std::string z_plot_titles[2]; - - double pixel_size[2]; //pixel size along X and Y - - std::vector band_names; //name for each band in the image - std::vector wavelength; //wavelength for each band - - EnviHeader() - { - name = ""; - - //specify default values for a new or empty ENVI file - samples = 0; - lines = 0; - bands = 0; - header_offset = 0; - data_type = 4; - interleave = BSQ; - byte_order = endianLittle; - x_start = y_start = 0; - pixel_size[0] = pixel_size[1] = 1; - - //strings - file_type = "ENVI Standard"; - sensor_type = "Unknown"; - wavelength_units = "Unknown"; - z_plot_titles[0] = z_plot_titles[1] = "Unknown"; - } - - std::string trim(std::string line) - { - //trims whitespace from the beginning and end of line - int start_i, end_i; - for(start_i=0; start_i < line.length(); start_i++) - if(line[start_i] != 32) - { - break; - } - - for(end_i = line.length()-1; end_i >= start_i; end_i--) - if(line[end_i] != ' ') - { - break; - } - - return line.substr(start_i, end_i - start_i+1); - } - - - std::string get_token(std::string line) - { - //returns a variable name; in this case we look for the '=' sign - size_t i = line.find_first_of('='); - - std::string result; - if(i != std::string::npos) - result = trim(line.substr(0, i-1)); - - return result; - } - - std::string get_data_str(std::string line) - { - size_t i = line.find_first_of('='); - - std::string result; - if(i != std::string::npos) - result = trim(line.substr(i+1)); - else - { - std::cout<<"ENVI Header error - data not found for token: "< get_string_seq(std::string token, std::string sequence) - { - //this function returns a sequence of comma-delimited strings - std::vector result; - - std::string entry; - size_t i; - do - { - i = sequence.find_first_of(','); - entry = sequence.substr(0, i); - sequence = sequence.substr(i+1); - result.push_back(trim(entry)); - }while(i != std::string::npos); - - return result; - } - - std::vector get_double_seq(std::string token, std::string sequence) - { - //this function returns a sequence of comma-delimited strings - std::vector result; - - std::string entry; - size_t i; - do - { - i = sequence.find_first_of(','); - entry = sequence.substr(0, i); - sequence = sequence.substr(i+1); - result.push_back(atof(entry.c_str())); - }while(i != std::string::npos); - - return result; - } - - void load(std::string filename) - { - name = filename; - - //open the header file - std::ifstream file(name.c_str()); - - if(!file) - { - std::cout<<"ENVI header file not found: "< pxsize = get_double_seq(token, string_sequence); - pixel_size[0] = pxsize[0]; - pixel_size[1] = pxsize[1]; - } - else if(token == "z plot titles") - { - std::string string_sequence = get_brace_str(token, line, file); - std::vector titles = get_string_seq(token, string_sequence); - z_plot_titles[0] = titles[0]; - z_plot_titles[1] = titles[1]; - } - - else if(token == "samples") - samples = atoi(get_data_str(line).c_str()); - else if(token == "lines") - lines = atoi(get_data_str(line).c_str()); - else if(token == "bands") - bands = atoi(get_data_str(line).c_str()); - else if(token == "header offset") - header_offset = atoi(get_data_str(line).c_str()); - else if(token == "file type") - file_type = get_data_str(line); - else if(token == "data type") - data_type = atoi(get_data_str(line).c_str()); - else if(token == "interleave") - { - std::string interleave_str = get_data_str(line); - if(interleave_str == "bip") - interleave = BIP; - else if(interleave_str == "bil") - interleave = BIL; - else if(interleave_str == "bsq") - interleave = BSQ; - } - else if(token == "sensor type") - sensor_type = get_data_str(line); - else if(token == "byte order") - byte_order = (endianType)atoi(get_data_str(line).c_str()); - else if(token == "x start") - x_start = atof(get_data_str(line).c_str()); - else if(token == "y start") - y_start = atof(get_data_str(line).c_str()); - else if(token == "wavelength units") - wavelength_units = get_data_str(line); - } - - //close the file - file.close(); - } - - void save(std::string filename) - { - //open a file - std::ofstream outfile(filename.c_str()); - - //write the ENVI type identifier - outfile<<"ENVI"< 0) - { - outfile<<"band names = {"<