diff --git a/stim/grids/grid.h b/stim/grids/grid.h index 8b29714..f8d6f2c 100644 --- a/stim/grids/grid.h +++ b/stim/grids/grid.h @@ -5,18 +5,16 @@ #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 +/**This object describes a generic D-dimensional grid containing data of type T. + Functions are provided for saving and loading binary data. + +**/ template class grid{ @@ -25,7 +23,7 @@ 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 + ///Return the total number of values in the binary file unsigned long samples(){ unsigned long s = 1; @@ -33,12 +31,55 @@ protected: s *= R[d]; return s; + } + + ///Initializes a grid by allocating the necessary memory and setting all values to zero + void init(){ + + //calculate the total number of values + unsigned long S = samples(); + + //allocate memory to store the grid + ptr = (T*)malloc(sizeof(T) * S); + + //initialize the memory to zero + memset(ptr, 0, sizeof(T) * S); } public: - //write data to disk + ///Constructor used to specify the grid size as a vector + + /// @param _R is a vector describing the grid resolution + grid( stim::vec _R){ + + //set the grid resolution + R = _R; + + init(); + } + + ///Constructor used to specify the grid size as a set of parameters + + /// @param X0... is a list of values describing the grid size along each dimension + grid( unsigned long X0, ...){ + + R[0] = X0; + + va_list ap; + va_start(ap, X0); + for(unsigned int d = 1; d S, unsigned long header = 0){ R = S; //set the sample resolution @@ -68,8 +112,69 @@ public: file.read((char *)ptr, samples() * sizeof(T)); } + ///Gets a single value from the grid given a set of coordinates + + /// @param x0... is a list of coordinates specifying the desired value + T get(unsigned long x0, ...){ + + va_list ap; + + unsigned long F = 1; + unsigned long p = x0; + + va_start(ap, x0); + for(unsigned int d = 1; d class image_stack : public virtual stim::grid{ @@ -22,6 +23,9 @@ protected: public: + ///Load an image stack based on a file mask. Images are loaded in alphanumeric order. + + /// @param file_mask is the mask describing images to be loaded void load_images(std::string file_mask){ stim::filename file_path(file_mask); @@ -65,6 +69,10 @@ public: } } + ///Saves a single page to an image file + + /// @param file_name is the name of the image file to be created + /// @param i is the page to be saved void save_image(std::string file_name, unsigned int i){ //create an image @@ -76,6 +84,9 @@ public: I.save(file_name); } + ///Saves the entire stack to a set of images + + /// @param file_mask is the mask describing how the file names will be saved (ex. image????.bmp) void save_images(std::string file_mask){ stim::filename file_path(file_mask); @@ -93,10 +104,6 @@ public: save_image(file_list[i], i); } - - - - }; -- libgit2 0.21.4