From 945ee13c87d2f84bc8e48abb12dce75629e46c3a Mon Sep 17 00:00:00 2001 From: Laila Saadatifard Date: Tue, 10 Nov 2015 12:57:37 -0600 Subject: [PATCH] the get_list function by using the windows.h, these changes are in the image_stack.h and filename.h --- stim/cuda/arraymath/array_cart2polar.cuh | 1 - stim/grids/grid.h | 12 ++++++++++-- stim/grids/image_stack.h | 16 ++++++++++++++++ stim/image/image.h | 17 +++++++++++++++++ stim/parser/filename.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- 5 files changed, 114 insertions(+), 32 deletions(-) diff --git a/stim/cuda/arraymath/array_cart2polar.cuh b/stim/cuda/arraymath/array_cart2polar.cuh index 37e44db..d5fb85c 100644 --- a/stim/cuda/arraymath/array_cart2polar.cuh +++ b/stim/cuda/arraymath/array_cart2polar.cuh @@ -33,7 +33,6 @@ namespace stim{ dim3 threads(max_threads, 1); dim3 blocks(x/threads.x + (x %threads.x == 0 ? 0:1) , y); - //call the kernel to do the multiplication cuda_cart2polar <<< blocks, threads >>>(gpuGrad, x, y); diff --git a/stim/grids/grid.h b/stim/grids/grid.h index 361fd08..1ac2ab1 100644 --- a/stim/grids/grid.h +++ b/stim/grids/grid.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include @@ -51,7 +51,9 @@ protected: public: ///Default constructor doesn't do anything - grid(){} + grid(){ + ptr = NULL; //set the pointer to NULL so that we know nothing is allocated + } ///Constructor used to specify the grid size as a vector @@ -110,6 +112,9 @@ public: R = S; //set the sample resolution + //allocate space for the data + init(); + std::fstream file; //open the file as binary for writing @@ -118,6 +123,7 @@ public: //seek past the header file.seekg(header, std::ios::beg); + //read the data file.read((char *)ptr, samples() * sizeof(T)); } @@ -173,7 +179,9 @@ public: for(unsigned int d = 0; d::R; using stim::grid::ptr; using stim::grid::samples; + using stim::grid::read; public: @@ -62,11 +63,13 @@ public: //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.data_interleaved(&ptr[ i * R[0] * R[1] * R[2] ]); + } } @@ -117,6 +120,19 @@ public: save_image(file_list[i], i); } + /// Returns the pixel at the specified point + T get(unsigned int x, unsigned int y, unsigned int z, unsigned int c = 0){ + return ptr[z * R[0] * R[1] * R[2] + y * R[0] * R[1] + x * R[0] + c]; + } + + void read(std::string file, unsigned int X, unsigned int Y, unsigned int Z, unsigned int C = 1, unsigned int header = 0){ + read(file, stim::vec(C, X, Y, Z), header); + } + + T* data(){ + return ptr; + } + }; diff --git a/stim/image/image.h b/stim/image/image.h index 7845679..594095e 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -135,6 +135,7 @@ public: } T* data(){ + return img.data(); } @@ -260,6 +261,22 @@ public: return result; } + + // leila's code for non_interleaving data in 3D + //create an data set from an interleaved buffer + void set_interleaved3(T* buffer, unsigned int width, unsigned int height, unsigned int depth, unsigned int channels = 3){ + + T* non_interleaved3 = (T*)malloc(width * height * depth * 3 * sizeof(T)); + unsigned int p = width * height * depth; + + for(unsigned int i = 0; i < p; i++){ + for(unsigned int c = 0; c < channels; c++){ + non_interleaved3[i + c * p] = buffer[i * channels + c]; + } + } + + img = cimg_library::CImg(non_interleaved3, width, height, depth, channels); + } }; diff --git a/stim/parser/filename.h b/stim/parser/filename.h index 21a9361..2fa0db2 100644 --- a/stim/parser/filename.h +++ b/stim/parser/filename.h @@ -19,10 +19,6 @@ #include #include "../parser/parser.h" -#ifdef BOOST_PRECOMPILED -#include -#endif - namespace stim{ //filename class designed to work with both Windows and Unix @@ -155,47 +151,93 @@ public: return ss.str(); } -#ifdef BOOST_PRECOMPILED - //get a list of files matching the current template - std::vector get_list(){ + //***************************************************************************************************************** + // output is the directory and the prefix and the extension of the files, which are looking for in that directory. + std::string dir_fname(){ + std::stringstream ss; - boost::filesystem::path p(dir()); //create a path from the current filename + //if the path is absolute + if(absolute){ + //output the drive letter if in Windows + #ifdef _WIN32 + ss< file_list; + + for(unsigned int d = 0; d < path.size(); d++) + ss< vec; // store paths, - vec v; // so we can sort them later + } + + // output is the directory and the name of the file which are found in that given directory + std::string f_name(std::string file_name){ + std::stringstream ss; - std::copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(v)); + //if the path is absolute + if(absolute){ + //output the drive letter if in Windows + #ifdef _WIN32 + ss< + //get a list of files matching the current template + std::vector get_list(){ - } + //stim::filename file_path; + stim::filename filepath(dir_fname()); + HANDLE hFind = INVALID_HANDLE_VALUE; + WIN32_FIND_DATAA FindFileData; + std::vector file_list; + + hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); + + if (hFind == INVALID_HANDLE_VALUE) { + printf ("Invalid file handle. Error is %u.\n", GetLastError()); + } + else { + std::string file_name = FindFileData.cFileName; + stim::filename current_file(f_name(file_name)); + file_list.push_back(current_file); + + // List all the other files in the directory. + while (FindNextFileA(hFind, &FindFileData) != 0){ + file_name = FindFileData.cFileName; + current_file = (f_name(file_name)); + file_list.push_back(current_file); } - } - + FindClose(hFind); + return file_list; } + + } #endif + //************************************************************************************************** + //gets the current working directory static stim::filename cwd(){ -- libgit2 0.21.4