Commit faef771897b9f16f46b31422f0a727e4196602f4

Authored by David Mayerich
1 parent 2ed641f0

updates to stim::image allow acquiring sparse image data

stim/image/image.h
@@ -66,7 +66,7 @@ public: @@ -66,7 +66,7 @@ public:
66 void data_interleaved(T* data){ 66 void data_interleaved(T* data){
67 67
68 unsigned int C = channels(); 68 unsigned int C = channels();
69 - unsigned int X = size(); 69 + unsigned int X = width() * height();
70 70
71 T* ptr = img.data(); 71 T* ptr = img.data();
72 72
@@ -105,6 +105,55 @@ public: @@ -105,6 +105,55 @@ public:
105 return img.size(); 105 return img.size();
106 } 106 }
107 107
  108 + /// Returns the number of nonzero values
  109 + unsigned int nnz(){
  110 +
  111 + unsigned long P = width() * height();
  112 + unsigned long C = channels();
  113 +
  114 + T* ptr = img.data();
  115 +
  116 + unsigned long n = 0;
  117 +
  118 + for(unsigned long p = 0; p < P; p++){
  119 + for(unsigned long c = 0; c < C; c++){
  120 +
  121 + if(ptr[c * P + p] > 0){
  122 + n++;
  123 + break;
  124 + }
  125 + }
  126 + }
  127 +
  128 + return n; //return the number of nonzero pixels
  129 +
  130 + }
  131 +
  132 + //this function returns indices of pixels that have nonzero values
  133 + std::vector<unsigned long> sparse_idx(){
  134 +
  135 + std::vector<unsigned long> s; //allocate an array
  136 + s.resize(nnz()); //allocate space in the array
  137 +
  138 + unsigned long P = width() * height();
  139 + unsigned long C = channels();
  140 +
  141 + T* ptr = img.data(); //get a pointer to the image data
  142 +
  143 + unsigned long i = 0;
  144 + for(unsigned long p = 0; p < P; p++){
  145 + for(unsigned long c = 0; c < C; c++){
  146 +
  147 + if(ptr[c * P + p] > 0){
  148 + s[i] = p;
  149 + i++;
  150 + break;
  151 + }
  152 + }
  153 + }
  154 +
  155 + return s; //return the index list
  156 + }
108 157
109 158
110 159
stim/math/vector.h
@@ -54,6 +54,16 @@ struct vec : public std::vector&lt;T&gt; @@ -54,6 +54,16 @@ struct vec : public std::vector&lt;T&gt;
54 at(3) = w; 54 at(3) = w;
55 } 55 }
56 56
  57 + vec(std::string str){
  58 + std::stringstream ss(str);
  59 +
  60 + T c;
  61 + while(ss >> c){
  62 + push_back(c);
  63 + }
  64 +
  65 + }
  66 +
57 67
58 68
59 //copy constructor 69 //copy constructor
stim/parser/filename.h
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 20
21 #include "../parser/parser.h" 21 #include "../parser/parser.h"
22 22
23 -#include <boost/filesystem.hpp> 23 +//#include <boost/filesystem.hpp>
24 24
25 namespace stim{ 25 namespace stim{
26 26
@@ -154,8 +154,8 @@ public: @@ -154,8 +154,8 @@ public:
154 154
155 return ss.str(); 155 return ss.str();
156 } 156 }
157 -  
158 - //get a list of files matching the current tamplate 157 +/*
  158 + //get a list of files matching the current template
159 std::vector<stim::filename> get_list(){ 159 std::vector<stim::filename> get_list(){
160 160
161 boost::filesystem::path p(dir()); //create a path from the current filename 161 boost::filesystem::path p(dir()); //create a path from the current filename
@@ -193,7 +193,7 @@ public: @@ -193,7 +193,7 @@ public:
193 193
194 return file_list; 194 return file_list;
195 } 195 }
196 - 196 +*/
197 //gets the current working directory 197 //gets the current working directory
198 static stim::filename cwd(){ 198 static stim::filename cwd(){
199 199