diff --git a/stim/gl/gl_texture.h b/stim/gl/gl_texture.h index 041f52c..1e1e17c 100644 --- a/stim/gl/gl_texture.h +++ b/stim/gl/gl_texture.h @@ -1,25 +1,13 @@ #ifndef STIM_GL_TEXTURE_H #define STIM_GL_TEXTURE_H - - - -/* -includes not necessary (yet) - -#include -#include - - -*/ - #include #include #include #include "../grids/image_stack.h" #include -//#include -#include "./error.h" +#include +#include namespace stim{ /* @@ -30,22 +18,8 @@ class gl_texture template class gl_texture : public virtual image_stack { - private: - /// Sets the internal texture_type, based on the data - /// size. Either 3D, 2D, 1D textures. - - void - setTextureType() - { - if (R[3] > 1) - texture_type = GL_TEXTURE_3D; - else if (R[3] == 1 && R[2] == 0) - texture_type = GL_TEXTURE_1D; - else if (R[3] == 1) - texture_type = GL_TEXTURE_2D; - } protected: - std::string path; + //std::string path; GLuint texID; //OpenGL object GLenum texture_type; //1D, 2D, 3D GLint interpType; @@ -57,43 +31,56 @@ class gl_texture : public virtual image_stack using image_stack::ptr; using image_stack::samples; + /// Sets the internal texture_type, based on the data dimensions + void setTextureType(){ + if (R[3] > 1) //if the third dimension is greater than 1 + texture_type = GL_TEXTURE_3D; //this is a 3D texture + else if (R[2] > 1) //if the second dimension is greater than 1 + texture_type = GL_TEXTURE_2D; //this is a 2D texture + else if (R[1] > 1) //if the dimension value is greater than 1 + texture_type = GL_TEXTURE_1D; //this is a 1D texture + } + + //initializes important variables + void init() { + texID = 0; //initialize texture ID to zero, default if OpenGL returns an error + memset(R, 0, sizeof) + } + public: ///default constructor - gl_texture() - { + gl_texture() : image_stack() { } ///@param string path to the directory with the image files. ///Creates an instance of the gl_texture object with a path to the data. - gl_texture(std::string file_path) - { - path = file_path; - image_stack::load_images(path.append("/*.jpg")); + gl_texture(std::string file_mask){ + image_stack::load_images(file_mask); setTextureType(); } ///returns the dimentions of the data in the x, y, z directions. - vec - getSize() - { + vec getSize(){ stim::vec size(R[1], R[2], R[3]); return size; } + void getSize(size_t& x, size_t& y, size_t& z) { + x = R[0]; y = R[1]; z = R[2]; + } + ///@param GLint interp --GL_LINEAR, GL_NEAREST... ///@param GLint twrap --GL_REPEAR, GL_CLAMP_TO_EDGE... ///@param GLenum dataType --GL_UNSIGNED_BYTE, GL_FLOAT16... ///@param GLenum dataFormat--GL_LUMINANCE, GL_RGB... /// Texture paramenters. - void - setTexParam(GLint interp = GL_LINEAR, - GLint twrap = GL_CLAMP_TO_EDGE, - GLenum dataType = GL_UNSIGNED_BYTE, - GLenum dataFormat = GL_LUMINANCE) - { + void setTexParam(GLint interp = GL_LINEAR, + GLint twrap = GL_CLAMP_TO_EDGE, + GLenum dataType = GL_UNSIGNED_BYTE, + GLenum dataFormat = GL_LUMINANCE){ interpType = interp; texWrap = twrap; type = dataType; @@ -104,45 +91,34 @@ class gl_texture : public virtual image_stack ///@param y size of the voxel in y direction ///@param z size of the voxel in z direction /// Sets the dimenstions of the voxels. - void - setDims(float x, float y, float z) - { - S[1] = x; - S[2] = y; - S[3] = z; + void setSpacing(float sx, float sy, float sz){ + S[1] = sx; + S[2] = sy; + S[3] = sz; } ///Returns a stim::vec that contains the x, y, z sizes of the voxel. - vec - getDims() - { + vec getDims(){ vec dims(S[1], S[2], S[3]); return dims; } - ///@param file_Path location of the directory with the files + ///@param file_mask specifies the file(s) to be loaded /// Sets the path and calls the loader on that path. - void - setPath(std::string file_path) - { - path = file_path; - image_stack::load_images(path.append("/*.jpg")); + void load(std::string file_mask){ + image_stack::load_images(file_mask); setTextureType(); } /// Returns an std::string path associated with an instance of the gl_texture class. - std::string - getPath() - { - return path; - } + //std::string getPath() + //{ + // return path; + //} /// Returns the GLuint id of the texture created by/associated with the - /// instance of the gl_texture class. - - GLuint - getTexture() - { + /// instance of the gl_texture class. + GLuint getTexture(){ return texID; } @@ -152,61 +128,24 @@ class gl_texture : public virtual image_stack //TO DO:::add methods for handling the cases of T // and convert them to GL equivalent. // i.e. an overloaded function that handles paramenter conversion. - void - createTexture() - { - glPixelStorei(GL_UNPACK_ALIGNMENT,1); + void createTexture(){ + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &texID); glBindTexture(texture_type, texID); - glTexParameteri(texture_type, - GL_TEXTURE_MIN_FILTER, - interpType); - glTexParameteri(texture_type, - GL_TEXTURE_MAG_FILTER, - interpType); - switch(texture_type) - { + glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, interpType); + glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, interpType); + switch(texture_type){ case GL_TEXTURE_3D: - glTexParameteri(texture_type, - GL_TEXTURE_WRAP_S,texWrap); - // GL_REPEAT); - // GL_CLAMP_TO_EDGE); - glTexParameteri(texture_type, - GL_TEXTURE_WRAP_T,texWrap); - // GL_REPEAT); - // GL_CLAMP_TO_EDGE); - glTexParameteri(texture_type, - GL_TEXTURE_WRAP_R,texWrap); - // GL_REPEAT); - // GL_CLAMP_TO_EDGE); - glTexImage3D(texture_type, - 0, - // GL_RGB16, - 1, - R[1], - R[2], - R[3], - 0, - format, - type, - ptr); - //GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents + glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, texWrap); + glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, texWrap); + glTexParameteri(texture_type, GL_TEXTURE_WRAP_R, texWrap); + glTexImage3D(texture_type, 0, 1, R[1], R[2], R[3], 0, format, type, ptr); glPixelStorei(GL_PACK_ALIGNMENT,1); break; case GL_TEXTURE_2D: - glTexParameteri(texture_type, - GL_TEXTURE_WRAP_S, texWrap); - glTexParameteri(texture_type, - GL_TEXTURE_WRAP_T, texWrap); - glTexImage2D(texture_type, - 0, - 1, - R[1], - R[2], - 0, - format, - type, - ptr); + glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, texWrap); + glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, texWrap); + glTexImage2D(texture_type, 0, 1, R[1], R[2], 0, format, type, ptr); break; } } diff --git a/stim/grids/grid.h b/stim/grids/grid.h index 1ac2ab1..43a0893 100644 --- a/stim/grids/grid.h +++ b/stim/grids/grid.h @@ -15,78 +15,80 @@ namespace stim{ Functions are provided for saving and loading binary data. **/ -template +template class grid{ protected: - stim::vec R; //elements in each dimension - stim::vec S; + size_t R[D]; //elements in each dimension + F S[D]; //spacing between element samples 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++) + size_t samples(){ + size_t s = 1; + for(size_t d = 0; d < D; d++) 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); - + void init(){ + size_t N = samples(); //calculate the total number of values + ptr = (T*)calloc(sizeof(T) * N); //allocate memory to store the grid } public: ///Default constructor doesn't do anything grid(){ - ptr = NULL; //set the pointer to NULL so that we know nothing is allocated + memset(R, 0, sizeof(size_t) * D); //initialize the grid dimensions to zero + memset(S, 0, sizeof(F) * D); //initialize the grid size to zero + ptr = NULL; //set the data pointer to NULL } ///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; - + grid( stim::vec _R){ + for (size_t d = 0; d < D; d++) + R[d] = _R[d]; init(); } void - setDim(stim::vec s) - { - S = s; + setDim(stim::vec s){ + for(size_t d = 0; d < D; d++) + S[d] = s[d]; } ///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 - - //allocate space for the data - init(); - - 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)); + void read(std::string filename, stim::vec X, unsigned long header = 0){ + for(size_t d = 0; d < D; d++) + R[d] = X[d]; //set the sample resolution + init(); //allocate space for the data + std::fstream file; + file.open(filename.c_str(), std::ios::in | std::ios::binary); //open the file as binary for writing + file.seekg(header, std::ios::beg); //seek past the header + file.read((char *)ptr, samples() * sizeof(T)); //read the data } ///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; + va_list ap; //create a variable list - unsigned long F = 1; - unsigned long p = x0; + unsigned long F = 1; //initialize the dimension size to 1 + unsigned long idx = x0; - va_start(ap, x0); - for(unsigned int d = 1; d class image_stack : public virtual stim::grid{ @@ -24,20 +23,17 @@ protected: using stim::grid::read; public: + //default constructor + image_stack() : grid() { - ///Load an image stack based on a file mask. Images are loaded in alphanumeric order. + } + ///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); - //if the file path is relative, update it with the current working directory -// if(file_path.is_relative()){ -// stim::filename wd = stim::filename::cwd(); -// file_path = wd.get_relative(file_mask); -// } - //get the list of files std::vector file_list = file_path.get_list(); @@ -50,7 +46,6 @@ public: std::cout << file_list[i].str() << std::endl; //load the first image and set all of the image_stack properties -// std::cout<<"File to Load: "< I(file_list[0].str()); //set the image resolution and number of channels @@ -63,37 +58,25 @@ public: ptr = (T*)malloc(sizeof(T) * samples()); //load and copy each image into the grid - for(unsigned int i = 0; i I(file_list[i].str()); - - //retrieve the interlaced data from the image - store it in the grid - I.get_interleaved_rgb(&ptr[ i * R[0] * R[1] * R[2] ]); - + for(unsigned int i = 0; i I(file_list[i].str()); //load the image + I.get_interleaved_rgb(&ptr[ i * R[0] * R[1] * R[2] ]); //retrieve the interlaced data from the image - store it in the grid } } ///Inserts image I into slot i. /// @param stim::image I; image to insert. /// @int I, where to place the image. - void insert_image(stim::image I, int i) - { + void insert_image(stim::image I, int i){ I.get_interleaved_rgb(&ptr[i *R[0] *R[1] *R[2] ]); } ///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 - stim::image I; - - //retrieve the interlaced data from the image - store it in the grid - I.set_interleaved_rgb(&ptr[ i * R[0] * R[1] * R[2] ], R[1], R[2], R[0]); - + void save_image(std::string file_name, unsigned int i){ + stim::image I; //create an image + I.set_interleaved_rgb(&ptr[ i * R[0] * R[1] * R[2] ], R[1], R[2], R[0]); //retrieve the interlaced data from the image - store it in the grid I.save(file_name); } @@ -133,12 +116,6 @@ public: stim::filename file_path(file_mask); - //if the file path is relative, update it with the current working directory -// if(file_path.is_relative()){ -// stim::filename wd = stim::filename::cwd(); -// file_path = wd.get_relative(file_mask); -// } - //create a list of file names std::vector file_list = stim::wildcards::increment(file_path.str(), 0, R[3]-1, 1); diff --git a/stim/visualization/camera.h b/stim/visualization/camera.h index 4abd4b0..cc6248b 100644 --- a/stim/visualization/camera.h +++ b/stim/visualization/camera.h @@ -186,6 +186,7 @@ public: d = vec3(0, 0, 1); up = vec3(0, 1, 0); focus = 1; + fov = 60; } -- libgit2 0.21.4