diff --git a/stim/image/image.h b/stim/image/image.h index c093405..71150ae 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -66,7 +66,7 @@ public: void data_interleaved(T* data){ unsigned int C = channels(); - unsigned int X = size(); + unsigned int X = width() * height(); T* ptr = img.data(); @@ -105,6 +105,55 @@ public: return img.size(); } + /// Returns the number of nonzero values + unsigned int nnz(){ + + unsigned long P = width() * height(); + unsigned long C = channels(); + + T* ptr = img.data(); + + unsigned long n = 0; + + for(unsigned long p = 0; p < P; p++){ + for(unsigned long c = 0; c < C; c++){ + + if(ptr[c * P + p] > 0){ + n++; + break; + } + } + } + + return n; //return the number of nonzero pixels + + } + + //this function returns indices of pixels that have nonzero values + std::vector sparse_idx(){ + + std::vector s; //allocate an array + s.resize(nnz()); //allocate space in the array + + unsigned long P = width() * height(); + unsigned long C = channels(); + + T* ptr = img.data(); //get a pointer to the image data + + unsigned long i = 0; + for(unsigned long p = 0; p < P; p++){ + for(unsigned long c = 0; c < C; c++){ + + if(ptr[c * P + p] > 0){ + s[i] = p; + i++; + break; + } + } + } + + return s; //return the index list + } diff --git a/stim/math/vector.h b/stim/math/vector.h index fe8afed..43b5e14 100644 --- a/stim/math/vector.h +++ b/stim/math/vector.h @@ -54,6 +54,16 @@ struct vec : public std::vector at(3) = w; } + vec(std::string str){ + std::stringstream ss(str); + + T c; + while(ss >> c){ + push_back(c); + } + + } + //copy constructor diff --git a/stim/parser/filename.h b/stim/parser/filename.h index dc6b4da..f4aa800 100644 --- a/stim/parser/filename.h +++ b/stim/parser/filename.h @@ -20,7 +20,7 @@ #include "../parser/parser.h" -#include +//#include namespace stim{ @@ -154,8 +154,8 @@ public: return ss.str(); } - - //get a list of files matching the current tamplate +/* + //get a list of files matching the current template std::vector get_list(){ boost::filesystem::path p(dir()); //create a path from the current filename @@ -193,7 +193,7 @@ public: return file_list; } - +*/ //gets the current working directory static stim::filename cwd(){ -- libgit2 0.21.4