diff --git a/stim/grids/grid.h b/stim/grids/grid.h new file mode 100644 index 0000000..8b29714 --- /dev/null +++ b/stim/grids/grid.h @@ -0,0 +1,78 @@ +#ifndef STIM_GRID_H +#define STIM_GRID_H + +#include +#include +#include +#include + +#include "../cuda/threads.h" +#include "../cuda/error.h" +#include "../cuda/devices.h" +#include "../math/vector.h" + + +namespace stim{ + +//This object describes a generic D-dimensional grid containing data of type T + // data can be loaded in the form of images + // data can be saved in the form of binary files +template +class grid{ + +protected: + + stim::vec R; //elements in each dimension + T* ptr; //pointer to the data (on the GPU or CPU) + + //return the total number of values in the binary file + unsigned long samples(){ + + unsigned long s = 1; + for(unsigned int d = 0; d < D; d++) + s *= R[d]; + + return s; + + } + +public: + + //write data to disk + void write(std::string filename){ + + std::fstream file; + + //open the file as binary for reading + file.open(filename.c_str(), std::ios::out | std::ios::binary); + + //write file to disk + file.write((char *)ptr, samples() * sizeof(T)); + } + + //load a binary file from disk + // header size is in bytes + void read(std::string filename, stim::vec S, unsigned long header = 0){ + + R = S; //set the sample resolution + + std::fstream file; + + //open the file as binary for writing + file.open(filename.c_str(), std::ios::in | std::ios::binary); + + //seek past the header + file.seekg(header, std::ios::beg); + + //read the data + file.read((char *)ptr, samples() * sizeof(T)); + } + + + +}; + +} + + +#endif diff --git a/stim/grids/grid_data.h b/stim/grids/grid_data.h deleted file mode 100644 index 8b29714..0000000 --- a/stim/grids/grid_data.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef STIM_GRID_H -#define STIM_GRID_H - -#include -#include -#include -#include - -#include "../cuda/threads.h" -#include "../cuda/error.h" -#include "../cuda/devices.h" -#include "../math/vector.h" - - -namespace stim{ - -//This object describes a generic D-dimensional grid containing data of type T - // data can be loaded in the form of images - // data can be saved in the form of binary files -template -class grid{ - -protected: - - stim::vec R; //elements in each dimension - T* ptr; //pointer to the data (on the GPU or CPU) - - //return the total number of values in the binary file - unsigned long samples(){ - - unsigned long s = 1; - for(unsigned int d = 0; d < D; d++) - s *= R[d]; - - return s; - - } - -public: - - //write data to disk - void write(std::string filename){ - - std::fstream file; - - //open the file as binary for reading - file.open(filename.c_str(), std::ios::out | std::ios::binary); - - //write file to disk - file.write((char *)ptr, samples() * sizeof(T)); - } - - //load a binary file from disk - // header size is in bytes - void read(std::string filename, stim::vec S, unsigned long header = 0){ - - R = S; //set the sample resolution - - std::fstream file; - - //open the file as binary for writing - file.open(filename.c_str(), std::ios::in | std::ios::binary); - - //seek past the header - file.seekg(header, std::ios::beg); - - //read the data - file.read((char *)ptr, samples() * sizeof(T)); - } - - - -}; - -} - - -#endif -- libgit2 0.21.4