From f92397d251bb523e5de835f4117573eaa5a8acc2 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 27 Jan 2016 13:52:36 -0600 Subject: [PATCH] fixed a Win32 bug in stim::filename, added support for non-zero headers in stim::binary and stim::envi --- stim/envi/binary.h | 18 ++++++++++++++---- stim/envi/envi.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- stim/parser/filename.h | 7 +++++-- 3 files changed, 73 insertions(+), 39 deletions(-) diff --git a/stim/envi/binary.h b/stim/envi/binary.h index 7c431a0..22dafec 100644 --- a/stim/envi/binary.h +++ b/stim/envi/binary.h @@ -66,6 +66,12 @@ protected: } + /// Private helper function that resets the file pointer to the beginning of the data + + void reset(){ + file.seekg(header, std::ios_base::beg); + } + /// Private helper file that opens a specified binary file. /// @param filename is the name of the binary file to stream @@ -89,12 +95,14 @@ protected: if(test_file_size()) //test the file size return true; } - + return false; } + + public: unsigned int get_thread_data(){ @@ -119,6 +127,8 @@ public: if(!open_file(filename)) return false; //open the binary file + //reset(); + return test_file_size(); } @@ -158,7 +168,7 @@ public: exit(1); } - file.seekg(R[1] * R[0] * page * sizeof(T), std::ios::beg); //seek to the desired location on disk + file.seekg(R[1] * R[0] * page * sizeof(T) + header, std::ios::beg); //seek to the desired location on disk file.write((char *)p, R[0] * R[1] * sizeof(T)); //write binary data return true; @@ -175,7 +185,7 @@ public: return false; } - file.seekg(R[1] * R[0] * page * sizeof(T), std::ios::beg); //write into memory from the binary file + file.seekg(R[1] * R[0] * page * sizeof(T) + header, std::ios::beg); //write into memory from the binary file file.read((char *)p, R[0] * R[1] * sizeof(T)); return true; @@ -220,7 +230,7 @@ public: file.seekg((z * R[0] * R[1] + y * R[0]) * sizeof(T), std::ios::beg); //seek to the start of the line file.read((char *)p, sizeof(T) * R[0]); //read the line - + return true; } diff --git a/stim/envi/envi.h b/stim/envi/envi.h index 240c49c..03ee5b3 100644 --- a/stim/envi/envi.h +++ b/stim/envi/envi.h @@ -15,7 +15,7 @@ namespace stim{ files are stored on disk as a large binary file with a corresponding header. Code for reading and processing ENVI header files is in the envi_header class. */ -class envi{ +class envi{ void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type) @@ -23,6 +23,14 @@ public: envi_header header; + /// Returns the size of the data type in bytes + unsigned int type_size(){ + if(header.data_type == envi_header::float32) return 4; + if(header.data_type == envi_header::float64) return 8; + + exit(1); + } + /// Returns the progress of the current processing operation as a percentage void reset_progress(){ @@ -123,17 +131,14 @@ public: } - /// Open an existing ENVI file given the file and header names. + /// Open an existing ENVI file given the filename and a header structure /// @param filename is the name of the ENVI binary file - /// @param headername is the name of the ENVI header file - bool open(std::string filename, std::string headername){ - - //allocate memory + /// @param header is an ENVI header structure + bool open(std::string filename, stim::envi_header h){ allocate(); - //load the header - header.load(headername); + header = h; //load the file if(header.interleave == envi_header::BSQ) { //if the infile is bsq file @@ -157,7 +162,7 @@ public: 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); @@ -166,14 +171,30 @@ public: 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 "< threshold (preventing division by small numbers) bool normalize(std::string outfile, double band, double threshold = 0.0){ - + if(header.interleave == envi_header::BSQ){ //if the infile is bsq file if(header.data_type ==envi_header::float32) return ((bsq*)file)->normalize(outfile, band, threshold); @@ -245,7 +266,7 @@ public: } } - else if(header.interleave == envi_header::BIP){ //if the infile is bip file + else if(header.interleave == envi_header::BIP){ //if the infile is bip file if(header.data_type ==envi_header::float32) return ((bip*)file)->baseline(outfile, w); else if(header.data_type == envi_header::float64) @@ -291,10 +312,10 @@ public: else if(interleave == envi_header::BIP) return ((bsq*)file)->bip(outfile); } - + else{ std::cout<<"ERROR: unidentified data type"<*)file)->bip(outfile); } - + else{ std::cout<<"ERROR: unidentified data type"<*)file)->bsq(outfile); } - + else{ std::cout<<"ERROR: unidentified data type"<*)file)->unsift(outfile, mask, samples, lines); else if (header.data_type == envi_header::float64) @@ -642,7 +663,7 @@ public: /// @param lb2 is the label value for the left baseline point for the second peak (denominator) /// @param rb2 is the label value for the right baseline point for the second peak (denominator) /// @param lab2 is the label value for the left bound (start of the integration) of the second peak (denominator) - /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator) + /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator) /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size bool pa_to_pa(double lb1, double rb1, double lab1, double rab1, double lb2, double rb2, double lab2, double rab2, void* result){ @@ -922,7 +943,7 @@ public: } return false; } - + /// Helper function that loads a mask into memory given a filename. /// @param mask is a pointer to pre-allocated memory of size X*Y diff --git a/stim/parser/filename.h b/stim/parser/filename.h index 2fa0db2..a5cbc9b 100644 --- a/stim/parser/filename.h +++ b/stim/parser/filename.h @@ -3,6 +3,7 @@ #include /* defines FILENAME_MAX */ #ifdef _WIN32 + #include #include #define GetCurrentDir _getcwd #define STIM_FILENAME_DIV '\\' @@ -17,6 +18,7 @@ #include #include #include +#include #include "../parser/parser.h" namespace stim{ @@ -203,7 +205,6 @@ public: #ifdef _WIN32 -#include //get a list of files matching the current template std::vector get_list(){ @@ -230,7 +231,7 @@ public: file_list.push_back(current_file); } FindClose(hFind); - + return file_list; } @@ -312,4 +313,6 @@ public: } //end namespace stim + #endif + -- libgit2 0.21.4