Commit a99e19ed1f0589821c9e53545be2f038bb47399c

Authored by cherub
2 parents ea2056c0 2ed641f0

Merge branch 'master' of git.stim.ee.uh.edu:codebase/stimlib

stim/biomodels/network.h
@@ -18,7 +18,7 @@ namespace stim{ @@ -18,7 +18,7 @@ namespace stim{
18 template<typename T> 18 template<typename T>
19 class network{ 19 class network{
20 20
21 - //helper classes 21 + //-------------------HELPER CLASSES-----------------------
22 /// Stores information about a geometric point on the network centerline (including point position and radius) 22 /// Stores information about a geometric point on the network centerline (including point position and radius)
23 //template<typename T> 23 //template<typename T>
24 class point : public stim::vec<T>{ 24 class point : public stim::vec<T>{
@@ -42,10 +42,15 @@ class network{ @@ -42,10 +42,15 @@ class network{
42 42
43 /// Stores information about a single capillary (a length of vessel between two branch or end points) 43 /// Stores information about a single capillary (a length of vessel between two branch or end points)
44 //template<typename T> 44 //template<typename T>
45 - class fiber{ 45 + class fiber : public std::list< point >{
  46 +
  47 + using std::list< point >::begin;
  48 + using std::list< point >::end;
  49 + using std::list< point >::size;
  50 +
46 51
47 public: 52 public:
48 - std::list< point > P; //geometric point positions 53 + //std::list< point > P; //geometric point positions
49 54
50 typename std::list< t_node >::iterator n[2]; //indices to terminal nodes 55 typename std::list< t_node >::iterator n[2]; //indices to terminal nodes
51 unsigned int id; 56 unsigned int id;
@@ -60,9 +65,9 @@ class network{ @@ -60,9 +65,9 @@ class network{
60 65
61 //for each point 66 //for each point
62 typename std::list< point >::iterator i; //create a point iterator 67 typename std::list< point >::iterator i; //create a point iterator
63 - for(i = P.begin(); i != P.end(); i++){ //for each point in the fiber 68 + for(i = begin(); i != end(); i++){ //for each point in the fiber
64 69
65 - if(i == P.begin()) //if this is the first point, just store it 70 + if(i == begin()) //if this is the first point, just store it
66 p1 = *i; 71 p1 = *i;
67 else{ //if this is any other point 72 else{ //if this is any other point
68 p0 = p1; //shift p1->p0 73 p0 = p1; //shift p1->p0
@@ -84,9 +89,9 @@ class network{ @@ -84,9 +89,9 @@ class network{
84 89
85 //for each point 90 //for each point
86 typename std::list< point >::iterator i; //create a point iterator 91 typename std::list< point >::iterator i; //create a point iterator
87 - for(i = P.begin(); i != P.end(); i++){ //for each point in the fiber 92 + for(i = begin(); i != end(); i++){ //for each point in the fiber
88 93
89 - if(i == P.begin()){ //if this is the first point, just store it 94 + if(i == begin()){ //if this is the first point, just store it
90 p1 = *i; 95 p1 = *i;
91 r1 = i->r; 96 r1 = i->r;
92 } 97 }
@@ -105,7 +110,30 @@ class network{ @@ -105,7 +110,30 @@ class network{
105 } 110 }
106 111
107 length = length_sum; //store the total length 112 length = length_sum; //store the total length
108 - return radius_sum / length; //return the average radius of the fiber 113 +
  114 + //if the total length is zero, store a radius of zero
  115 + if(length == 0)
  116 + return 0;
  117 + else
  118 + return radius_sum / length; //return the average radius of the fiber
  119 + }
  120 +
  121 + std::vector< stim::vec<T> > geometry(){
  122 +
  123 + std::vector< stim::vec<T> > result; //create an array to store the fiber geometry
  124 + result.resize( size() ); //pre-allocate the array
  125 +
  126 + typename std::list< point >::iterator p; //create a list iterator
  127 + unsigned int pi = 0; //create an index into the result array
  128 +
  129 + //for each geometric point on the fiber centerline
  130 + for(p = begin(); p != end(); p++){
  131 + result[pi] = *p;
  132 + pi++;
  133 + }
  134 +
  135 + return result; //return the geometry array
  136 +
109 } 137 }
110 138
111 std::string str(){ 139 std::string str(){
@@ -113,7 +141,7 @@ class network{ @@ -113,7 +141,7 @@ class network{
113 141
114 //create an iterator for the point list 142 //create an iterator for the point list
115 typename std::list<point>::iterator i; 143 typename std::list<point>::iterator i;
116 - for(i = P.begin(); i != P.end(); i++){ 144 + for(i = begin(); i != end(); i++){
117 ss<<i->str()<<" r = "<<i->r<<std::endl; 145 ss<<i->str()<<" r = "<<i->r<<std::endl;
118 } 146 }
119 147
@@ -172,7 +200,7 @@ class network{ @@ -172,7 +200,7 @@ class network{
172 }; 200 };
173 201
174 202
175 - 203 +//---------------NETWORK CLASS-----------------------------
176 204
177 protected: 205 protected:
178 206
@@ -231,6 +259,8 @@ public: @@ -231,6 +259,8 @@ public:
231 } 259 }
232 260
233 /// Load a network from an OBJ object 261 /// Load a network from an OBJ object
  262 +
  263 + /// @param object is the object file to be used as the basis for the network
234 void load( stim::obj<T> object){ 264 void load( stim::obj<T> object){
235 265
236 //get the number of vertices in the object 266 //get the number of vertices in the object
@@ -291,12 +321,98 @@ public: @@ -291,12 +321,98 @@ public:
291 for(unsigned int pi = 0; pi < nP; pi++){ 321 for(unsigned int pi = 0; pi < nP; pi++){
292 point p = (point)L[pi]; //move the geometric coordinates into a point structure 322 point p = (point)L[pi]; //move the geometric coordinates into a point structure
293 p.r = R[pi][0]; //store the radius 323 p.r = R[pi][0]; //store the radius
294 - f->P.push_back(p); //push the point onto the current fiber 324 + f->push_back(p); //push the point onto the current fiber
295 } 325 }
296 } 326 }
297 327
298 } //end load() 328 } //end load()
299 329
  330 + /// Returns an array of node positions
  331 + std::vector< stim::vec<T> > get_node_positions(){
  332 +
  333 + std::vector< stim::vec<T> > result; //create an array to store the result
  334 + result.resize(N.size()); //set the array size
  335 +
  336 + t_node_i ni; //create a terminal node iterator
  337 + unsigned int vi = 0; //vertex index into the result array
  338 +
  339 + //for every terminal node
  340 + for(ni = N.begin(); ni != N.end(); ni++){
  341 +
  342 + //create a vector based on the node position
  343 +
  344 + //if the number of outgoing nodes is nonzero
  345 + if(ni->out.size() != 0)
  346 + result[vi] = ni->out.front()->front();
  347 + else if(ni->in.size() != 0)
  348 + result[vi] = ni->in.front()->back();
  349 +
  350 + vi++; //increment the array index
  351 + }
  352 +
  353 + //return the resulting array
  354 + return result;
  355 + }
  356 +
  357 + std::vector< stim::vec<T> > get_fiber_geometry( fiber_i f ){
  358 + return f->geometry();
  359 + }
  360 +
  361 + /// Generate an OBJ file from the network
  362 +
  363 + stim::obj<T> obj(){
  364 +
  365 + //create an OBJ object
  366 + stim::obj<T> object;
  367 +
  368 + //name the nodes
  369 + set_names();
  370 +
  371 + //retrieve a list of terminal node positions
  372 + std::vector< stim::vec<T> > node_pos = get_node_positions();
  373 +
  374 + //add the nodes to the obj file
  375 + object.addV(node_pos);
  376 +
  377 + //counter for vertex indices in the object class
  378 + unsigned int nP;
  379 +
  380 + //for each fiber
  381 + fiber_i fi; //create a fiber iterator
  382 + for(fi = F.begin(); fi != F.end(); fi++){
  383 +
  384 + //get an array of fiber points
  385 + std::vector< stim::vec<T> > fiber_p = get_fiber_geometry(fi);
  386 +
  387 + //create a subset of this array
  388 + typename std::vector< stim::vec<T> >::iterator start = fiber_p.begin() + 1;
  389 + typename std::vector< stim::vec<T> >::iterator end = fiber_p.end() - 1;
  390 + typename std::vector< stim::vec<T> > fiber_subset(start, end);
  391 +
  392 + //add this subset to the geometry object
  393 + nP = object.addV(fiber_subset);
  394 +
  395 + //create an array to hold vertex indices for a line
  396 + std::vector<unsigned int> line;
  397 + line.resize(fiber_p.size());
  398 +
  399 + //add the terminal nodes to the line list (make sure to add 1 to make them compatible with the OBJ)
  400 + line[0] = fi->n[0]->id + 1;
  401 + line[line.size() - 1] = fi->n[1]->id + 1;
  402 +
  403 + //add the intermediate vertex indices to the line array
  404 + for(unsigned int i = 0; i < fiber_subset.size(); i++){
  405 + line[1 + i] = nP + i;
  406 + }
  407 +
  408 + //add the line list to the object class
  409 + object.addLine(line);
  410 +
  411 + }
  412 +
  413 + return object;
  414 + }
  415 +
300 /// This function returns the information necessary for a simple graph-based physical (ex. fluid) simulation. 416 /// This function returns the information necessary for a simple graph-based physical (ex. fluid) simulation.
301 417
302 /// @param n0 is a array which will contain the list of source nodes 418 /// @param n0 is a array which will contain the list of source nodes
@@ -5,8 +5,9 @@ @@ -5,8 +5,9 @@
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <stim/visualization/colormap.h> 6 #include <stim/visualization/colormap.h>
7 #include <sstream> 7 #include <sstream>
8 -#include <stim/math/mathvec.h>  
9 - 8 +#include <stim/math/vector.h>
  9 +#include <stim/cuda/devices.h>
  10 +#include <stim/cuda/threads.h>
10 11
11 ///Cost function that works with the gl-spider class to find index of the item with min-cost. 12 ///Cost function that works with the gl-spider class to find index of the item with min-cost.
12 typedef unsigned char uchar; 13 typedef unsigned char uchar;
@@ -38,6 +39,7 @@ float get_sum(float *diff) @@ -38,6 +39,7 @@ float get_sum(float *diff)
38 ret = cublasSetVector(20*10, sizeof(*diff), diff, 1, v_dif, 1); 39 ret = cublasSetVector(20*10, sizeof(*diff), diff, 1, v_dif, 1);
39 float out; 40 float out;
40 ret = cublasSasum(handle, 20*10, v_dif, 1, &out); 41 ret = cublasSasum(handle, 20*10, v_dif, 1, &out);
  42 +// cublasDestroy(ret);
41 cublasDestroy(handle); 43 cublasDestroy(handle);
42 return out; 44 return out;
43 } 45 }
@@ -90,7 +92,7 @@ void initArray(cudaGraphicsResource_t src, int DIM_Y) @@ -90,7 +92,7 @@ void initArray(cudaGraphicsResource_t src, int DIM_Y)
90 cudaGraphicsMapResources(1, &src) 92 cudaGraphicsMapResources(1, &src)
91 ); 93 );
92 HANDLE_ERROR( 94 HANDLE_ERROR(
93 - cudaGraphicsSubResourceGetMappedArray(&srcArray, src,0,0) 95 + cudaGraphicsSubResourceGetMappedArray(&srcArray, src, 0, 0)
94 ); 96 );
95 HANDLE_ERROR( 97 HANDLE_ERROR(
96 cudaBindTextureToArray(texIn, srcArray) 98 cudaBindTextureToArray(texIn, srcArray)
@@ -109,9 +111,6 @@ void initArray(cudaGraphicsResource_t src, int DIM_Y) @@ -109,9 +111,6 @@ void initArray(cudaGraphicsResource_t src, int DIM_Y)
109 void cleanUP(cudaGraphicsResource_t src) 111 void cleanUP(cudaGraphicsResource_t src)
110 { 112 {
111 HANDLE_ERROR( 113 HANDLE_ERROR(
112 - cudaUnbindTexture(texIn)  
113 - );  
114 - HANDLE_ERROR(  
115 cudaFree(result) 114 cudaFree(result)
116 ); 115 );
117 HANDLE_ERROR( 116 HANDLE_ERROR(
@@ -120,7 +119,13 @@ void cleanUP(cudaGraphicsResource_t src) @@ -120,7 +119,13 @@ void cleanUP(cudaGraphicsResource_t src)
120 HANDLE_ERROR( 119 HANDLE_ERROR(
121 cudaFree(v_dif) 120 cudaFree(v_dif)
122 ); 121 );
  122 + HANDLE_ERROR(
  123 + cudaUnbindTexture(texIn)
  124 + );
123 } 125 }
  126 +
  127 +
  128 +
124 ///External access-point to the cuda function 129 ///External access-point to the cuda function
125 ///@param src, cudaGraphicsResource that handles the shared OpenGL/Cuda Texture 130 ///@param src, cudaGraphicsResource that handles the shared OpenGL/Cuda Texture
126 ///@param DIM_Y, the number of samples in the template. 131 ///@param DIM_Y, the number of samples in the template.
@@ -128,17 +133,33 @@ void cleanUP(cudaGraphicsResource_t src) @@ -128,17 +133,33 @@ void cleanUP(cudaGraphicsResource_t src)
128 extern "C" 133 extern "C"
129 stim::vec<int> get_cost(cudaGraphicsResource_t src, int DIM_Y) 134 stim::vec<int> get_cost(cudaGraphicsResource_t src, int DIM_Y)
130 { 135 {
  136 +// int minGridSize;
  137 +// int blockSize;
  138 +
  139 +// cudaOccupancyMaxPotentialBlockSize(&minGridSize, &blockSize, get_diff, 0, 20*DIM_Y*10);
  140 +// std::cout << blockSize << std::endl;
  141 +// std::cout << minGridSize << std::endl;
  142 +// stringstream name; //for debugging
  143 +// name << "Test.bmp";
  144 +// dim3 block(4,4);
  145 +// dim3 grid(20/4, DIM_Y*10/4);
  146 +// int gridSize = (DIM_Y*10*20 + 1024 - 1)/1024;
  147 +// dim3 grid(26, 26);
  148 +// dim3 grid = GenGrid1D(DIM_Y*10*20);
  149 +// stim::gpu2image<float>(result, name.str(), 20,DIM_Y*10,0,1);
  150 +// name.clear();
  151 +// name << "sample_" << inter << "_" << idx << ".bmp";
  152 +// stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1);
  153 +
131 float output[DIM_Y]; 154 float output[DIM_Y];
132 stim::vec<int> ret(0, 0); 155 stim::vec<int> ret(0, 0);
133 float mini = 10000000000000000.0; 156 float mini = 10000000000000000.0;
134 int idx; 157 int idx;
135 - stringstream name; //for debugging  
136 - name << "Test.bmp";  
137 initArray(src, DIM_Y*10); 158 initArray(src, DIM_Y*10);
138 - dim3 grid(20, DIM_Y*10);  
139 - dim3 block(1, 1); 159 + dim3 grid(20/2, DIM_Y*10/2);
  160 + dim3 block(2, 2);
  161 +
140 get_diff <<< grid, block >>> (result); 162 get_diff <<< grid, block >>> (result);
141 - stim::gpu2image<float>(result, name.str(), 20,DIM_Y*10,0,1);  
142 for (int i = 0; i < DIM_Y; i++){ 163 for (int i = 0; i < DIM_Y; i++){
143 output[i] = get_sum(result+(20*10*i)); 164 output[i] = get_sum(result+(20*10*i));
144 if(output[i] <= mini){ 165 if(output[i] <= mini){
@@ -147,10 +168,7 @@ stim::vec&lt;int&gt; get_cost(cudaGraphicsResource_t src, int DIM_Y) @@ -147,10 +168,7 @@ stim::vec&lt;int&gt; get_cost(cudaGraphicsResource_t src, int DIM_Y)
147 } 168 }
148 } 169 }
149 170
150 -// name.clear();  
151 -// name << "sample_" << inter << "_" << idx << ".bmp";  
152 output[idx] = get_sum(result+(20*10*idx)); 171 output[idx] = get_sum(result+(20*10*idx));
153 -// stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1);  
154 cleanUP(src); 172 cleanUP(src);
155 ret[0] = idx; ret[1] = (int) output[idx]; 173 ret[0] = idx; ret[1] = (int) output[idx];
156 return ret; 174 return ret;
  1 +#ifndef STIM_CUDA_TIMER
  2 +#define STIM_CUDA_TIMER
  3 +
1 static cudaEvent_t tStartEvent; 4 static cudaEvent_t tStartEvent;
2 static cudaEvent_t tStopEvent; 5 static cudaEvent_t tStopEvent;
3 6
  7 +namespace stim{
  8 +
  9 +/// These functions calculate the time between GPU functions in milliseconds
4 static void gpuStartTimer() 10 static void gpuStartTimer()
5 { 11 {
6 //set up timing events 12 //set up timing events
@@ -18,4 +24,8 @@ static float gpuStopTimer() @@ -18,4 +24,8 @@ static float gpuStopTimer()
18 cudaEventDestroy(tStartEvent); 24 cudaEventDestroy(tStartEvent);
19 cudaEventDestroy(tStopEvent); 25 cudaEventDestroy(tStopEvent);
20 return elapsedTime; 26 return elapsedTime;
21 -}  
22 \ No newline at end of file 27 \ No newline at end of file
  28 +}
  29 +
  30 +} //end namespace stim
  31 +
  32 +#endif
23 \ No newline at end of file 33 \ No newline at end of file
@@ -35,6 +35,8 @@ protected: @@ -35,6 +35,8 @@ protected:
35 return R[1]; 35 return R[1];
36 } 36 }
37 37
  38 + using binary<T>::thread_data;
  39 +
38 public: 40 public:
39 41
40 using binary<T>::open; 42 using binary<T>::open;
@@ -318,12 +320,17 @@ public: @@ -318,12 +320,17 @@ public:
318 320
319 }//loop for YZ line end 321 }//loop for YZ line end
320 target.write(reinterpret_cast<const char*>(c), L); //write the corrected data into destination 322 target.write(reinterpret_cast<const char*>(c), L); //write the corrected data into destination
  323 +
  324 + thread_data = (double)k / Y() * 100;
321 }//loop for Y slice end 325 }//loop for Y slice end
322 326
323 free(a); 327 free(a);
324 free(b); 328 free(b);
325 free(c); 329 free(c);
326 target.close(); 330 target.close();
  331 +
  332 + thread_data = 100;
  333 +
327 return true; 334 return true;
328 335
329 } 336 }
@@ -366,11 +373,14 @@ public: @@ -366,11 +373,14 @@ public:
366 } 373 }
367 } 374 }
368 target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination 375 target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination
  376 +
  377 + thread_data = (double)j / Y() * 100;
369 } 378 }
370 379
371 free(b); 380 free(b);
372 free(c); 381 free(c);
373 target.close(); 382 target.close();
  383 + thread_data = 100;
374 return true; 384 return true;
375 } 385 }
376 386
@@ -390,9 +400,13 @@ public: @@ -390,9 +400,13 @@ public:
390 for ( unsigned i = 0; i < Z(); i++) 400 for ( unsigned i = 0; i < Z(); i++)
391 { 401 {
392 band_index(p, i); 402 band_index(p, i);
393 - target.write(reinterpret_cast<const char*>(p), S); //write a band data into target file 403 + target.write(reinterpret_cast<const char*>(p), S); //write a band data into target file
  404 +
  405 + thread_data = (double)i / Z() * 100; //store the progress for the current operation
394 } 406 }
395 407
  408 + thread_data = 100; //set the current progress to 100%
  409 +
396 free(p); 410 free(p);
397 target.close(); 411 target.close();
398 return true; 412 return true;
@@ -421,11 +435,15 @@ public: @@ -421,11 +435,15 @@ public:
421 unsigned ks = k * X(); 435 unsigned ks = k * X();
422 for ( unsigned j = 0; j < X(); j++) 436 for ( unsigned j = 0; j < X(); j++)
423 q[k + j * Z()] = p[ks + j]; 437 q[k + j * Z()] = p[ks + j];
  438 +
  439 + thread_data = (double)(i * Z() + k) / (Z() * Y()) * 100; //store the progress for the current operation
424 } 440 }
425 441
426 target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file 442 target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file
427 } 443 }
428 444
  445 + thread_data = 100;
  446 +
429 447
430 free(p); 448 free(p);
431 free(q); 449 free(q);
@@ -825,40 +843,50 @@ public: @@ -825,40 +843,50 @@ public:
825 return true; 843 return true;
826 } 844 }
827 845
828 - ///Saves to disk only those spectra corresponding to mask values != 0 846 + /// Saves to disk only those spectra corresponding to mask values != 0
  847 + /// Unlike the BIP and BSQ versions of this function, this version saves a different format: the BIL file is saved as a BIP
829 bool sift(std::string outfile, unsigned char* p){ 848 bool sift(std::string outfile, unsigned char* p){
830 // Assume X() = X, Y() = Y, Z() = Z. 849 // Assume X() = X, Y() = Y, Z() = Z.
831 std::ofstream target(outfile.c_str(), std::ios::binary); 850 std::ofstream target(outfile.c_str(), std::ios::binary);
832 851
833 //for loading pages: 852 //for loading pages:
834 - unsigned XZ = X() * Z(); //calculate the number of values in an XZ page on disk  
835 - unsigned L = XZ * sizeof(T); //calculate the size of the page (in bytes)  
836 - T * temp = (T*)malloc(L); //allocate memory for a temporary page 853 + unsigned long XZ = X() * Z(); //calculate the number of values in an XZ page on disk
  854 + unsigned long B = Z(); //calculate the number of bands
  855 + unsigned long L = XZ * sizeof(T); //calculate the size of the page (in bytes)
837 856
838 - //for saving spectra:  
839 - unsigned LZ = Z() * sizeof(T); //calculate the size of the spectrum (in bytes)  
840 - T * tempZ = (T*)malloc(LZ); //allocate memory for a temporary spectrum  
841 - spectrum(tempZ, X() - 1, Y() - 1); //creates a dummy spectrum by taking the last spectrum in the image 857 + //allocate temporary memory for a XZ slice
  858 + T* slice = (T*) malloc(L);
842 859
843 - for (unsigned i = 0; i < Y(); i++) //Select a page by choosing Y coordinate, Y() 860 + //allocate temporary memory for a spectrum
  861 + T* spec = (T*) malloc(B * sizeof(T));
  862 +
  863 + //for each slice along the y axis
  864 + for (unsigned long y = 0; y < Y(); y++) //Select a page by choosing Y coordinate, Y()
844 { 865 {
845 - read_plane_y(temp, i); //retrieve an ZX page, store in "temp"  
846 - for (unsigned j = 0; j < X(); j++) //Select a pixel by choosing X coordinate in the page, X() 866 + read_plane_y(slice, y); //retrieve an ZX page, store in "slice"
  867 +
  868 + //for each sample along X
  869 + for (unsigned long x = 0; x < X(); x++) //Select a pixel by choosing X coordinate in the page, X()
847 { 870 {
848 - if (p[j * X() + i] != 0) //if the mask != 0 at that XY pixel 871 + //if the mask != 0 at that xy pixel
  872 + if (p[y * X() + x] != 0) //if the mask != 0 at that XY pixel
849 { 873 {
850 - for (unsigned k = 0; k < Z(); k++) //Select a voxel by choosing Z coordinate at the pixel 874 + //for each band at that pixel
  875 + for (unsigned long b = 0; b < B; b++) //Select a voxel by choosing Z coordinate at the pixel
851 { 876 {
852 - tempZ[k] = temp[k*X() + i]; //Pass the correct spectral value from XZ page into the spectrum to be saved. 877 + spec[b] = slice[b*X() + x]; //Pass the correct spectral value from XZ page into the spectrum to be saved.
853 } 878 }
854 - target.write(reinterpret_cast<const char*>(tempZ), LZ); //write that spectrum to disk. Size is L2. 879 + target.write((char*)spec, B * sizeof(T)); //write that spectrum to disk. Size is L2.
855 } 880 }
856 - else  
857 - continue; 881 +
  882 + thread_data = (double) (y * X() + x) / (Y() * X()) * 100;
858 } 883 }
859 } 884 }
860 target.close(); 885 target.close();
861 - free(temp); 886 + free(slice);
  887 + free(spec);
  888 +
  889 + thread_data = 100;
862 return true; 890 return true;
863 } 891 }
864 892
@@ -995,10 +1023,15 @@ public: @@ -995,10 +1023,15 @@ public:
995 { 1023 {
996 file.read((char *)(temp + j * sam), sizeof(T) * sam); 1024 file.read((char *)(temp + j * sam), sizeof(T) * sam);
997 file.seekg(jumpb, std::ios::cur); //go to the next band 1025 file.seekg(jumpb, std::ios::cur); //go to the next band
  1026 +
  1027 + thread_data = (double)(i * Z() + j) / (lin * Z()) * 100;
998 } 1028 }
999 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file 1029 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
1000 } 1030 }
1001 free(temp); 1031 free(temp);
  1032 +
  1033 + thread_data = 100;
  1034 +
1002 return true; 1035 return true;
1003 } 1036 }
1004 1037
stim/envi/binary.h
@@ -28,7 +28,7 @@ protected: @@ -28,7 +28,7 @@ protected:
28 unsigned int header; //header size (in bytes) 28 unsigned int header; //header size (in bytes)
29 unsigned char* mask; //pointer to a character array: 0 = background, 1 = foreground (or valid data) 29 unsigned char* mask; //pointer to a character array: 0 = background, 1 = foreground (or valid data)
30 30
31 - 31 + unsigned int thread_data; //unsigned integer used to pass data to threads during processing
32 32
33 33
34 /// Private initialization function used to set default parameters in the data structure. 34 /// Private initialization function used to set default parameters in the data structure.
@@ -36,6 +36,8 @@ protected: @@ -36,6 +36,8 @@ protected:
36 memset(R, 0, sizeof(unsigned int) * D); //initialize the resolution to zero 36 memset(R, 0, sizeof(unsigned int) * D); //initialize the resolution to zero
37 header = 0; //initialize the header size to zero 37 header = 0; //initialize the header size to zero
38 mask = NULL; 38 mask = NULL;
  39 +
  40 + thread_data = 0;
39 } 41 }
40 42
41 /// Private helper function that returns the size of the file on disk using system functions. 43 /// Private helper function that returns the size of the file on disk using system functions.
@@ -95,6 +97,14 @@ protected: @@ -95,6 +97,14 @@ protected:
95 97
96 public: 98 public:
97 99
  100 + unsigned int get_thread_data(){
  101 + return thread_data;
  102 + }
  103 +
  104 + void reset_thread_data(){
  105 + thread_data = 0;
  106 + }
  107 +
98 /// Open a binary file for streaming. 108 /// Open a binary file for streaming.
99 109
100 /// @param filename is the name of the binary file 110 /// @param filename is the name of the binary file
@@ -37,6 +37,8 @@ protected: @@ -37,6 +37,8 @@ protected:
37 return R[0]; 37 return R[0];
38 } 38 }
39 39
  40 + using binary<T>::thread_data;
  41 +
40 public: 42 public:
41 43
42 using binary<T>::open; 44 using binary<T>::open;
@@ -327,6 +329,8 @@ public: @@ -327,6 +329,8 @@ public:
327 329
328 }//loop for YZ line end 330 }//loop for YZ line end
329 target.write(reinterpret_cast<const char*>(c), L); //write the corrected data into destination 331 target.write(reinterpret_cast<const char*>(c), L); //write the corrected data into destination
  332 +
  333 + thread_data = (double)k / Y() * 100;
330 }//loop for Y slice end 334 }//loop for Y slice end
331 335
332 336
@@ -335,6 +339,8 @@ public: @@ -335,6 +339,8 @@ public:
335 free(b); 339 free(b);
336 free(c); 340 free(c);
337 target.close(); 341 target.close();
  342 +
  343 + thread_data = 100;
338 return true; 344 return true;
339 345
340 } 346 }
@@ -379,12 +385,15 @@ public: @@ -379,12 +385,15 @@ public:
379 } 385 }
380 } 386 }
381 target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination 387 target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination
  388 +
  389 + thread_data = (double) j / Y() * 100;
382 } 390 }
383 391
384 392
385 free(b); 393 free(b);
386 free(c); 394 free(c);
387 target.close(); 395 target.close();
  396 + thread_data = 100;
388 return true; 397 return true;
389 } 398 }
390 399
@@ -434,10 +443,13 @@ public: @@ -434,10 +443,13 @@ public:
434 unsigned ks = k * X(); 443 unsigned ks = k * X();
435 for ( unsigned j = 0; j < X(); j++) 444 for ( unsigned j = 0; j < X(); j++)
436 q[ks + j] = p[k + j * Z()]; 445 q[ks + j] = p[k + j * Z()];
  446 +
  447 + thread_data = (double)(i * Z() + k) / (Y() * Z()) * 100;
437 } 448 }
438 target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file 449 target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file
439 } 450 }
440 451
  452 + thread_data = 100;
441 453
442 free(p); 454 free(p);
443 free(q); 455 free(q);
@@ -837,42 +849,113 @@ public: @@ -837,42 +849,113 @@ public:
837 849
838 850
839 /// Saves to disk only those spectra corresponding to mask values != 0 851 /// Saves to disk only those spectra corresponding to mask values != 0
840 - bool sift(std::string outfile, unsigned char* p){  
841 - // Assume X() = X, Y() = Y, Z() = Z. 852 + bool sift(std::string outfile, unsigned char* mask){
  853 +
  854 + //reset the file pointer to the beginning of the file
  855 + file.seekg(0, std::ios::beg);
  856 +
  857 + // open an output stream
842 std::ofstream target(outfile.c_str(), std::ios::binary); 858 std::ofstream target(outfile.c_str(), std::ios::binary);
843 859
844 - //for loading pages:  
845 - unsigned ZX = X() * Z(); //calculate the number of values in an XZ page on disk  
846 - unsigned L = ZX * sizeof(T); //calculate the size of the page (in bytes)  
847 - T * temp = (T*)malloc(L); //allocate memory for a temporary page 860 + //allocate space for a single spectrum
  861 + unsigned long B = Z();
  862 + T* spectrum = (T*) malloc(B * sizeof(T));
848 863
849 - //for saving spectra:  
850 - unsigned LZ = Z() * sizeof(T); //calculate the size of the spectrum (in bytes)  
851 - T * tempZ = (T*)malloc(LZ); //allocate memory for a temporary spectrum  
852 - spectrum(tempZ, X() - 1, Y() - 1); //creates a dummy spectrum by taking the last spectrum in the image 864 + //calculate the number of pixels in a band
  865 + unsigned long XY = X() * Y();
853 866
854 - for (unsigned i = 0; i < Y(); i++) //Select a page by choosing Y coordinate, Y()  
855 - {  
856 - read_plane_y(temp, i); //retrieve an ZX page, store in "temp"  
857 - for (unsigned j = 0; j < X(); j++) //Select a pixel by choosing X coordinate in the page, X()  
858 - {  
859 - if (p[j * X() + i] != 0) //if the mask != 0 at that XY pixel  
860 - {  
861 - for (unsigned k = 0; k < Z(); k++) //Select a voxel by choosing Z coordinate at the pixel  
862 - {  
863 - tempZ[k] = temp[i*Z() + k]; //Pass the correct spectral value from XZ page into the spectrum to be saved.  
864 - }  
865 - target.write(reinterpret_cast<const char*>(tempZ), LZ); //write that spectrum to disk. Size is L2.  
866 - }  
867 - else  
868 - continue; 867 + //for each pixel
  868 + unsigned long skip = 0; //number of spectra to skip
  869 + for(unsigned long x = 0; x < XY; x++){
  870 +
  871 + //if the current pixel isn't masked
  872 + if( mask[x] == 0){
  873 + //increment the number of skipped pixels
  874 + skip++;
  875 + }
  876 + //if the current pixel is masked
  877 + else{
  878 +
  879 + //skip the intermediate pixels
  880 + file.seekg(skip * B * sizeof(T), std::ios::cur);
  881 +
  882 + //set the skip value to zero
  883 + skip = 0;
  884 +
  885 + //read this pixel into memory
  886 + file.read((char *)spectrum, B * sizeof(T));
  887 +
  888 + //write this pixel out
  889 + target.write((char *)spectrum, B * sizeof(T));
  890 +
  891 + thread_data = (double) x / XY * 100;
869 } 892 }
  893 +
870 } 894 }
  895 +
  896 + //close the output file
871 target.close(); 897 target.close();
872 - free(temp); 898 + free(spectrum);
  899 +
  900 + thread_data = 100;
  901 +
873 return true; 902 return true;
874 } 903 }
875 904
  905 + bool unsift(std::string outfile, unsigned char* mask, unsigned int samples, unsigned int lines){
  906 +
  907 + // open an output stream
  908 + std::ofstream target(outfile.c_str(), std::ios::binary);
  909 +
  910 + //reset the file pointer to the beginning of the file
  911 + file.seekg(0, std::ios::beg);
  912 +
  913 + //allocate space for a single spectrum
  914 + unsigned long B = Z();
  915 + T* spectrum = (T*) malloc(B * sizeof(T));
  916 +
  917 + //allocate space for a spectrum of zeros
  918 + T* zeros = (T*) malloc(B * sizeof(T));
  919 + memset(zeros, 0, B * sizeof(T));
  920 +
  921 + //calculate the number of pixels in a band
  922 + unsigned long XY = samples * lines;
  923 +
  924 + //for each pixel
  925 + unsigned long skip = 0; //number of spectra to skip
  926 + for(unsigned long x = 0; x < XY; x++){
  927 +
  928 + //if the current pixel isn't masked
  929 + if( mask[x] == 0){
  930 +
  931 + //write a bunch of zeros
  932 + target.write((char *)zeros, B * sizeof(T));
  933 + }
  934 + //if the current pixel is masked
  935 + else{
  936 +
  937 + //read a pixel into memory
  938 + file.read((char *)spectrum, B * sizeof(T));
  939 +
  940 + //write this pixel out
  941 + target.write((char *)spectrum, B * sizeof(T));
  942 + }
  943 +
  944 + thread_data = (double)x / XY * 100;
  945 +
  946 + }
  947 +
  948 + //close the output file
  949 + target.close();
  950 + free(spectrum);
  951 +
  952 + thread_data = 100;
  953 +
  954 + return true;
  955 +
  956 +
  957 + }
  958 +
876 959
877 960
878 /// @param p is a pointer to memory of size X * Y * sizeof(T) that will store the band averages. 961 /// @param p is a pointer to memory of size X * Y * sizeof(T) that will store the band averages.
@@ -995,9 +1078,13 @@ public: @@ -995,9 +1078,13 @@ public:
995 { 1078 {
996 pixel(temp, sp + j + i * X()); 1079 pixel(temp, sp + j + i * X());
997 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file 1080 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
  1081 +
  1082 + thread_data = (double)(i * sam + j) / (lin * sam) * 100;
998 } 1083 }
999 } 1084 }
1000 free(temp); 1085 free(temp);
  1086 +
  1087 + thread_data = 100;
1001 return true; 1088 return true;
1002 } 1089 }
1003 1090
@@ -42,6 +42,8 @@ protected: @@ -42,6 +42,8 @@ protected:
42 return R[2]; 42 return R[2];
43 } 43 }
44 44
  45 + using binary<T>::thread_data;
  46 +
45 public: 47 public:
46 48
47 using binary<T>::open; 49 using binary<T>::open;
@@ -259,6 +261,8 @@ public: @@ -259,6 +261,8 @@ public:
259 } 261 }
260 262
261 target.write(reinterpret_cast<const char*>(c), S); //write the corrected data into destination 263 target.write(reinterpret_cast<const char*>(c), S); //write the corrected data into destination
  264 +
  265 + thread_data = (double)cii / B * 100;
262 266
263 } 267 }
264 268
@@ -268,6 +272,8 @@ public: @@ -268,6 +272,8 @@ public:
268 free(b); 272 free(b);
269 free(c); 273 free(c);
270 target.close(); 274 target.close();
  275 +
  276 + thread_data = 100;
271 return true; 277 return true;
272 } 278 }
273 279
@@ -304,13 +310,18 @@ public: @@ -304,13 +310,18 @@ public:
304 c[i] = c[i] / b[i]; 310 c[i] = c[i] / b[i];
305 } 311 }
306 target.write(reinterpret_cast<const char*>(c), S); //write normalized data into destination 312 target.write(reinterpret_cast<const char*>(c), S); //write normalized data into destination
  313 +
  314 + thread_data = (double)j / B * 100;
307 } 315 }
308 316
  317 +
  318 +
309 //header.save(headername); //save the new header file 319 //header.save(headername); //save the new header file
310 320
311 free(b); 321 free(b);
312 free(c); 322 free(c);
313 target.close(); 323 target.close();
  324 + thread_data = 100; //make sure that the progress bar is full
314 return true; 325 return true;
315 } 326 }
316 327
@@ -349,24 +360,31 @@ public: @@ -349,24 +360,31 @@ public:
349 std::ofstream target(outname.c_str(), std::ios::binary); 360 std::ofstream target(outname.c_str(), std::ios::binary);
350 std::string headername = outname + ".hdr"; 361 std::string headername = outname + ".hdr";
351 362
352 - T * p; //pointer to the current spectrum  
353 - p = (T*)malloc(L);  
354 -  
355 - for ( unsigned i = 0; i < Y(); i++) 363 + unsigned int xz_bytes = X() * Z() * sizeof(T);
  364 + T * xz_slice; //pointer to the current spectrum
  365 + xz_slice = (T*)malloc(xz_bytes);
  366 +
  367 + for ( unsigned y = 0; y < Y(); y++) //for each y position
356 { 368 {
357 - file.seekg(X() * i * sizeof(T), std::ios::beg);  
358 - for ( unsigned j = 0; j < Z(); j++ ) 369 + file.seekg(y * X() * sizeof(T), std::ios::beg); //seek to the beginning of the xz slice
  370 + for ( unsigned z = 0; z < Z(); z++ ) //for each band
359 { 371 {
360 - file.read((char *)(p + j * X()), sizeof(T) * X());  
361 - file.seekg(jump, std::ios::cur); //go to the next band 372 + file.read((char *)(xz_slice + z * X()), sizeof(T) * X()); //read a line
  373 + file.seekg(jump, std::ios::cur); //seek to the next band
  374 +
  375 +
  376 + thread_data = (double)(y * Z() + z) / (Z() * Y()) * 100; //update the progress counter
362 } 377 }
363 - target.write(reinterpret_cast<const char*>(p), L); //write XZ slice data into target file 378 + target.write(reinterpret_cast<const char*>(xz_slice), xz_bytes); //write the generated XZ slice to the target file
364 } 379 }
365 - //header.interleave = rts::envi_header::BIL; //change the type of file in header file  
366 - //header.save(headername); 380 +
  381 +
  382 +
  383 + thread_data = 100;
367 384
368 - free(p); 385 + free(xz_slice);
369 target.close(); 386 target.close();
  387 +
370 return true; 388 return true;
371 } 389 }
372 390
@@ -763,16 +781,16 @@ public: @@ -763,16 +781,16 @@ public:
763 bool sift(std::string outfile, unsigned char* p){ 781 bool sift(std::string outfile, unsigned char* p){
764 std::ofstream target(outfile.c_str(), std::ios::binary); 782 std::ofstream target(outfile.c_str(), std::ios::binary);
765 // open a band (XY plane) 783 // open a band (XY plane)
766 - unsigned XY = X() * Y(); //Number of XY pixels  
767 - unsigned L = XY * sizeof(T); //size of XY pixels 784 + unsigned long XY = X() * Y(); //Number of XY pixels
  785 + unsigned long L = XY * sizeof(T); //size of XY pixels
768 786
769 T * temp = (T*)malloc(L); //allocate memory for a band 787 T * temp = (T*)malloc(L); //allocate memory for a band
770 T * temp_vox = (T*)malloc(sizeof(T)); //allocate memory for one voxel 788 T * temp_vox = (T*)malloc(sizeof(T)); //allocate memory for one voxel
771 789
772 - for (unsigned i = 0; i < Z(); i++) //for each spectral bin 790 + for (unsigned long i = 0; i < Z(); i++) //for each spectral bin
773 { 791 {
774 band_index(temp, i); //get the specified band (XY sheet by index) 792 band_index(temp, i); //get the specified band (XY sheet by index)
775 - for (unsigned j = 0; j < XY; j++) // for each pixel 793 + for (unsigned long j = 0; j < XY; j++) // for each pixel
776 { 794 {
777 if (p[j] != 0){ //if the mask is != 0 at that pixel 795 if (p[j] != 0){ //if the mask is != 0 at that pixel
778 temp_vox[0] = temp[j]; 796 temp_vox[0] = temp[j];
@@ -781,10 +799,15 @@ public: @@ -781,10 +799,15 @@ public:
781 else{ 799 else{
782 continue; 800 continue;
783 } 801 }
  802 +
  803 + thread_data = (double)(i * XY + j) / (XY * Z()) * 100;
784 } 804 }
785 } 805 }
786 target.close(); 806 target.close();
787 free(temp); 807 free(temp);
  808 +
  809 + thread_data = 100;
  810 +
788 return true; 811 return true;
789 } 812 }
790 813
@@ -803,9 +826,9 @@ public: @@ -803,9 +826,9 @@ public:
803 std::cout<<"started sifting"<<std::endl; 826 std::cout<<"started sifting"<<std::endl;
804 827
805 //get the number of pixels and bands in the input image 828 //get the number of pixels and bands in the input image
806 - unsigned int P = X(); //Number of pixels  
807 - unsigned int B = Z(); //number of bands  
808 - unsigned int XY = samples * lines; //total number of pixels in an unsifted image 829 + unsigned long P = X(); //Number of pixels
  830 + unsigned long B = Z(); //number of bands
  831 + unsigned long XY = samples * lines; //total number of pixels in an unsifted image
809 832
810 // allocate memory for a sifted band 833 // allocate memory for a sifted band
811 T * sifted = (T*)malloc(P * sizeof(T)); //allocate memory for a band 834 T * sifted = (T*)malloc(P * sizeof(T)); //allocate memory for a band
@@ -814,28 +837,33 @@ public: @@ -814,28 +837,33 @@ public:
814 T* unsifted = (T*) malloc(XY * sizeof(T)); 837 T* unsifted = (T*) malloc(XY * sizeof(T));
815 838
816 //for each band 839 //for each band
817 - for(unsigned int b = 0; b < B; b++){ 840 + for(unsigned long b = 0; b < B; b++){
818 841
819 //set the unsifted index value to zero 842 //set the unsifted index value to zero
820 - unsigned int i = 0; 843 + unsigned long i = 0;
821 844
822 //retrieve the sifted band (masked pixels only) 845 //retrieve the sifted band (masked pixels only)
823 band_index(sifted, b); 846 band_index(sifted, b);
824 847
825 //for each pixel in the final image (treat it as a 1D image) 848 //for each pixel in the final image (treat it as a 1D image)
826 - for(unsigned int xi = 0; xi < XY; xi++){ 849 + for(unsigned long xi = 0; xi < XY; xi++){
827 if( p[xi] == 0 ) 850 if( p[xi] == 0 )
828 unsifted[xi] = 0; 851 unsifted[xi] = 0;
829 else{ 852 else{
830 unsifted[xi] = sifted[i]; 853 unsifted[xi] = sifted[i];
831 i++; 854 i++;
832 } 855 }
  856 + //std::cout<<xi<<"/"<<XY<<", "<<b<<"/"<<B<<std::endl;
  857 + thread_data = (double)(b * XY + xi) / (B * XY) * 100;
833 } 858 }
834 - 859 + //std::cout<<b*XY<<"/"<<B*XY<<" "<<B<<"-"<<XY<<std::endl;
835 //write the band image to disk 860 //write the band image to disk
836 target.write(reinterpret_cast<const char*>(unsifted), sizeof(T) * XY); 861 target.write(reinterpret_cast<const char*>(unsifted), sizeof(T) * XY);
837 } 862 }
838 863
  864 + //std::cout<<"unsifted"<<std::endl;
  865 + thread_data = 100;
  866 +
839 return true; 867 return true;
840 } 868 }
841 869
@@ -953,17 +981,22 @@ public: @@ -953,17 +981,22 @@ public:
953 unsigned long long jumpl = (X() - sam) * sizeof(T); //jump pointer to the next line 981 unsigned long long jumpl = (X() - sam) * sizeof(T); //jump pointer to the next line
954 //get start 982 //get start
955 file.seekg((y0 * X() + x0) * sizeof(T), std::ios::beg); 983 file.seekg((y0 * X() + x0) * sizeof(T), std::ios::beg);
956 - for (unsigned i = 0; i < Z(); i++) 984 + for (unsigned z = 0; z < Z(); z++)
957 { 985 {
958 for (unsigned j = 0; j < lin; j++) 986 for (unsigned j = 0; j < lin; j++)
959 { 987 {
960 file.read((char *)(temp + j * sam), sizeof(T) * sam); 988 file.read((char *)(temp + j * sam), sizeof(T) * sam);
961 file.seekg(jumpl, std::ios::cur); //go to the next band 989 file.seekg(jumpl, std::ios::cur); //go to the next band
  990 +
  991 + thread_data = (double)(z * lin + j) / (Z() * lin) * 100;
962 } 992 }
963 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file 993 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
964 file.seekg(jumpb, std::ios::cur); 994 file.seekg(jumpb, std::ios::cur);
965 } 995 }
966 free(temp); 996 free(temp);
  997 +
  998 + thread_data = 100;
  999 +
967 return true; 1000 return true;
968 } 1001 }
969 1002
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 #include "../envi/bip.h" 6 #include "../envi/bip.h"
7 #include "../envi/bil.h" 7 #include "../envi/bil.h"
8 #include <iostream> 8 #include <iostream>
9 -#include "../image/image.h" 9 +//#include "../image/image.h"
10 10
11 namespace stim{ 11 namespace stim{
12 12
@@ -23,6 +23,78 @@ public: @@ -23,6 +23,78 @@ public:
23 23
24 envi_header header; 24 envi_header header;
25 25
  26 + /// Returns the progress of the current processing operation as a percentage
  27 + void reset_progress(){
  28 +
  29 + if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
  30 + if(header.data_type ==envi_header::float32)
  31 + ((bsq<float>*)file)->reset_thread_data();
  32 + else if(header.data_type == envi_header::float64)
  33 + ((bsq<double>*)file)->reset_thread_data();
  34 + else
  35 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  36 + }
  37 +
  38 + else if(header.interleave == envi_header::BIL){ //if the infile is bil file
  39 + if(header.data_type ==envi_header::float32)
  40 + ((bil<float>*)file)->reset_thread_data();
  41 + else if(header.data_type == envi_header::float64)
  42 + ((bil<double>*)file)->reset_thread_data();
  43 + else
  44 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  45 + }
  46 +
  47 + else if(header.interleave == envi_header::BIP){ //if the infile is bip file
  48 + if(header.data_type ==envi_header::float32)
  49 + ((bip<float>*)file)->reset_thread_data();
  50 + else if(header.data_type == envi_header::float64)
  51 + ((bip<double>*)file)->reset_thread_data();
  52 + else
  53 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  54 + }
  55 +
  56 + else{
  57 + std::cout<<"ERROR: unidentified file type"<<std::endl;
  58 + exit(1);
  59 + }
  60 + }
  61 +
  62 + /// Returns the progress of the current processing operation as a percentage
  63 + unsigned int progress(){
  64 +
  65 + if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
  66 + if(header.data_type ==envi_header::float32)
  67 + return ((bsq<float>*)file)->get_thread_data();
  68 + else if(header.data_type == envi_header::float64)
  69 + return ((bsq<double>*)file)->get_thread_data();
  70 + else
  71 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  72 + }
  73 +
  74 + else if(header.interleave == envi_header::BIL){ //if the infile is bil file
  75 + if(header.data_type ==envi_header::float32)
  76 + return ((bil<float>*)file)->get_thread_data();
  77 + else if(header.data_type == envi_header::float64)
  78 + return ((bil<double>*)file)->get_thread_data();
  79 + else
  80 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  81 + }
  82 +
  83 + else if(header.interleave == envi_header::BIP){ //if the infile is bip file
  84 + if(header.data_type ==envi_header::float32)
  85 + return ((bip<float>*)file)->get_thread_data();
  86 + else if(header.data_type == envi_header::float64)
  87 + return ((bip<double>*)file)->get_thread_data();
  88 + else
  89 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  90 + }
  91 +
  92 + else{
  93 + std::cout<<"ERROR: unidentified file type"<<std::endl;
  94 + }
  95 + return 0;
  96 + }
  97 +
26 /// Allocate memory for a new ENVI file based on the current interleave format (BIP, BIL, BSQ) and data type. 98 /// Allocate memory for a new ENVI file based on the current interleave format (BIP, BIL, BSQ) and data type.
27 bool allocate(){ 99 bool allocate(){
28 100
@@ -385,6 +457,10 @@ public: @@ -385,6 +457,10 @@ public:
385 //create a new header 457 //create a new header
386 envi_header new_header = header; 458 envi_header new_header = header;
387 459
  460 + //if a BIL file is sifted, it's saved as a BIP
  461 + if(header.interleave == envi_header::BIL)
  462 + new_header.interleave = envi_header::BIP;
  463 +
388 //set the number of lines to 1 (this is a matrix with 1 line and N samples) 464 //set the number of lines to 1 (this is a matrix with 1 line and N samples)
389 new_header.lines = 1; 465 new_header.lines = 1;
390 new_header.samples = nnz; 466 new_header.samples = nnz;
@@ -455,14 +531,18 @@ public: @@ -455,14 +531,18 @@ public:
455 531
456 else if (header.interleave == envi_header::BIP){ //if the infile is bip file 532 else if (header.interleave == envi_header::BIP){ //if the infile is bip file
457 533
458 - std::cout << "ERROR in stim::envi::unsift - BIP files aren't supported yet" << std::endl; 534 + if (header.data_type == envi_header::float32)
  535 + return ((bip<float>*)file)->unsift(outfile, mask, samples, lines);
  536 + else if (header.data_type == envi_header::float64)
  537 + return ((bip<double>*)file)->unsift(outfile, mask, samples, lines);
  538 + else
  539 + std::cout << "ERROR: unidentified data type" << std::endl;
459 } 540 }
460 541
461 else{ 542 else{
462 std::cout << "ERROR: unidentified file type" << std::endl; 543 std::cout << "ERROR: unidentified file type" << std::endl;
463 - exit(1);  
464 } 544 }
465 - 545 + return 0;
466 } 546 }
467 547
468 /// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array. 548 /// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array.
@@ -847,7 +927,7 @@ public: @@ -847,7 +927,7 @@ public:
847 927
848 /// @param mask is a pointer to pre-allocated memory of size X*Y 928 /// @param mask is a pointer to pre-allocated memory of size X*Y
849 /// @param maskname is the file name for the image that will serve as the mask 929 /// @param maskname is the file name for the image that will serve as the mask
850 - bool load_mask(unsigned char * mask, std::string maskname){ 930 + /*bool load_mask(unsigned char * mask, std::string maskname){
851 //open the mask file 931 //open the mask file
852 stim::image<unsigned char> mask_image(maskname); 932 stim::image<unsigned char> mask_image(maskname);
853 mask_image.data_noninterleaved(mask); 933 mask_image.data_noninterleaved(mask);
@@ -855,7 +935,7 @@ public: @@ -855,7 +935,7 @@ public:
855 //memcpy(mask, mask_image.data_noninterleaved(), mask_image.size()); 935 //memcpy(mask, mask_image.data_noninterleaved(), mask_image.size());
856 //mask_image.clear(); 936 //mask_image.clear();
857 return true; 937 return true;
858 - } 938 + }*/
859 939
860 /// Calculate the mean value for all masked (or valid) pixels in a band and returns the average spectrum 940 /// Calculate the mean value for all masked (or valid) pixels in a band and returns the average spectrum
861 941
stim/gl/gl_spider.h
@@ -10,11 +10,12 @@ @@ -10,11 +10,12 @@
10 #include "stim/gl/gl_texture.h" 10 #include "stim/gl/gl_texture.h"
11 #include "stim/visualization/camera.h" 11 #include "stim/visualization/camera.h"
12 #include "stim/gl/error.h" 12 #include "stim/gl/error.h"
13 -#include "stim/math/mathvec.h" 13 +#include "stim/math/vector.h"
14 #include "stim/math/rect.h" 14 #include "stim/math/rect.h"
15 #include "stim/math/matrix.h" 15 #include "stim/math/matrix.h"
16 #include "stim/cuda/cost.h" 16 #include "stim/cuda/cost.h"
17 #include "stim/cuda/glbind.h" 17 #include "stim/cuda/glbind.h"
  18 +#include <stim/visualization/obj.h>
18 #include <vector> 19 #include <vector>
19 20
20 #include <iostream> 21 #include <iostream>
@@ -55,6 +56,7 @@ class gl_spider @@ -55,6 +56,7 @@ class gl_spider
55 GLuint texbufferID; 56 GLuint texbufferID;
56 int numSamples; 57 int numSamples;
57 float stepsize = 3.0; 58 float stepsize = 3.0;
  59 + int current_cost;
58 60
59 /// Method for finding the best scale for the spider. 61 /// Method for finding the best scale for the spider.
60 /// changes the x, y, z size of the spider to minimize the cost 62 /// changes the x, y, z size of the spider to minimize the cost
@@ -119,7 +121,7 @@ class gl_spider @@ -119,7 +121,7 @@ class gl_spider
119 setMatrix(); 121 setMatrix();
120 glCallList(dList+3); 122 glCallList(dList+3);
121 123
122 - int best = getCost(); 124 +// int best = getCost();
123 125
124 } 126 }
125 127
@@ -142,7 +144,7 @@ class gl_spider @@ -142,7 +144,7 @@ class gl_spider
142 ///Method for populating the vector arrays with sampled vectors. 144 ///Method for populating the vector arrays with sampled vectors.
143 ///uses the default d vector <0,0,1> 145 ///uses the default d vector <0,0,1>
144 void 146 void
145 - genDirectionVectors(float solidAngle = M_PI) 147 + genDirectionVectors(float solidAngle = 5*M_PI/4)
146 { 148 {
147 //ofstream file; 149 //ofstream file;
148 //file.open("dvectors.txt"); 150 //file.open("dvectors.txt");
@@ -492,8 +494,9 @@ class gl_spider @@ -492,8 +494,9 @@ class gl_spider
492 createResource(); 494 createResource();
493 stim::vec<int> cost = get_cost(resource, numSamples); 495 stim::vec<int> cost = get_cost(resource, numSamples);
494 destroyResource(); 496 destroyResource();
495 - if (cost[1] >= 80)  
496 - exit(0); 497 +// if (cost[1] >= 80)
  498 +// exit(0);
  499 + current_cost = cost[1];
497 return cost[0]; 500 return cost[0];
498 } 501 }
499 502
@@ -562,7 +565,7 @@ class gl_spider @@ -562,7 +565,7 @@ class gl_spider
562 dList = glGenLists(3); 565 dList = glGenLists(3);
563 glListBase(dList); 566 glListBase(dList);
564 Bind(); 567 Bind();
565 - genDirectionVectors(M_PI); 568 + genDirectionVectors(5*M_PI/4);
566 genPositionVectors(); 569 genPositionVectors();
567 genMagnitudeVectors(); 570 genMagnitudeVectors();
568 DrawCylinder(); 571 DrawCylinder();
@@ -649,7 +652,7 @@ class gl_spider @@ -649,7 +652,7 @@ class gl_spider
649 { 652 {
650 m[0] = mag; 653 m[0] = mag;
651 m[1] = mag; 654 m[1] = mag;
652 - m[2] = mag; 655 + // m[2] = mag;
653 } 656 }
654 657
655 658
@@ -719,15 +722,16 @@ class gl_spider @@ -719,15 +722,16 @@ class gl_spider
719 } 722 }
720 723
721 724
722 - void 725 + int
723 Step() 726 Step()
724 { 727 {
725 Bind(); 728 Bind();
726 findOptimalDirection(); 729 findOptimalDirection();
727 findOptimalPosition(); 730 findOptimalPosition();
728 findOptimalScale(); 731 findOptimalScale();
729 -// branchDetection(); 732 + // branchDetection();
730 Unbind(); 733 Unbind();
  734 + return current_cost;
731 } 735 }
732 736
733 737
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 #include <fstream> 7 #include <fstream>
8 #include <cstdarg> 8 #include <cstdarg>
9 9
10 -#include "../math/mathvec.h" 10 +#include <stim/math/vector.h>
11 11
12 namespace stim{ 12 namespace stim{
13 13
stim/math/matrix.h
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 //#include "rts/vector.h" 4 //#include "rts/vector.h"
5 #include <string.h> 5 #include <string.h>
6 #include <iostream> 6 #include <iostream>
7 -#include "mathvec.h" 7 +#include <stim/math/vector.h>
8 #include "../cuda/callable.h" 8 #include "../cuda/callable.h"
9 9
10 namespace stim{ 10 namespace stim{
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 #define RTS_PLANE_H 2 #define RTS_PLANE_H
3 3
4 #include <iostream> 4 #include <iostream>
5 -#include "../math/vector.h" 5 +#include <stim/math/vector.h>
6 #include "rts/cuda/callable.h" 6 #include "rts/cuda/callable.h"
7 7
8 8
@@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@
2 #define RTS_QUAD_H 2 #define RTS_QUAD_H
3 3
4 //enable CUDA_CALLABLE macro 4 //enable CUDA_CALLABLE macro
5 -#include "../cuda/callable.h"  
6 -#include "../math/vector.h"  
7 -#include "../math/triangle.h"  
8 -#include "../math/quaternion.h" 5 +#include <stim/cuda/callable.h>
  6 +#include <stim/math/vector.h>
  7 +#include <stim/math/triangle.h>
  8 +#include <stim/math/quaternion.h>
9 #include <iostream> 9 #include <iostream>
10 #include <iomanip> 10 #include <iomanip>
11 #include <algorithm> 11 #include <algorithm>
@@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@
2 #define RTS_RECT_H 2 #define RTS_RECT_H
3 3
4 //enable CUDA_CALLABLE macro 4 //enable CUDA_CALLABLE macro
5 -#include "../cuda/callable.h"  
6 -#include "../math/mathvec.h"  
7 -#include "../math/triangle.h"  
8 -#include "../math/quaternion.h" 5 +#include <stim/cuda/callable.h>
  6 +#include <stim/math/vector.h>
  7 +#include <stim/math/triangle.h>
  8 +#include <stim/math/quaternion.h>
9 #include <iostream> 9 #include <iostream>
10 #include <iomanip> 10 #include <iomanip>
11 #include <algorithm> 11 #include <algorithm>
stim/math/spharmonics.h
1 #ifndef STIM_SPH_HARMONICS 1 #ifndef STIM_SPH_HARMONICS
2 #define STIM_SPH_HARMONICS 2 #define STIM_SPH_HARMONICS
3 3
4 -#include <stim/math/mathvec.h> 4 +#include <stim/math/vector.h>
5 #include <boost/math/special_functions/spherical_harmonic.hpp> 5 #include <boost/math/special_functions/spherical_harmonic.hpp>
6 #include <vector> 6 #include <vector>
7 7
stim/math/triangle.h
@@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
2 #define RTS_TRIANGLE_H 2 #define RTS_TRIANGLE_H
3 3
4 //enable CUDA_CALLABLE macro 4 //enable CUDA_CALLABLE macro
5 -#include "../cuda/callable.h"  
6 -#include "../math/mathvec.h" 5 +#include <stim/cuda/callable.h>
  6 +#include <stim/math/vector.h>
7 #include <iostream> 7 #include <iostream>
8 8
9 namespace stim{ 9 namespace stim{
stim/math/vector.h
@@ -59,7 +59,7 @@ struct vec : public std::vector&lt;T&gt; @@ -59,7 +59,7 @@ struct vec : public std::vector&lt;T&gt;
59 //copy constructor 59 //copy constructor
60 vec( const vec<T>& other){ 60 vec( const vec<T>& other){
61 unsigned int N = other.size(); 61 unsigned int N = other.size();
62 - for(int i=0; i<N; i++) 62 + for(unsigned int i=0; i<N; i++)
63 push_back(other[i]); 63 push_back(other[i]);
64 } 64 }
65 65
@@ -112,7 +112,7 @@ struct vec : public std::vector&lt;T&gt; @@ -112,7 +112,7 @@ struct vec : public std::vector&lt;T&gt;
112 112
113 //compute and return the vector length 113 //compute and return the vector length
114 T sum_sq = (T)0; 114 T sum_sq = (T)0;
115 - for(int i=0; i<N; i++) 115 + for(unsigned int i=0; i<N; i++)
116 { 116 {
117 sum_sq += pow( at(i), 2 ); 117 sum_sq += pow( at(i), 2 );
118 } 118 }
@@ -231,7 +231,7 @@ struct vec : public std::vector&lt;T&gt; @@ -231,7 +231,7 @@ struct vec : public std::vector&lt;T&gt;
231 231
232 vec<T> result(N); 232 vec<T> result(N);
233 233
234 - for(int i=0; i<N; i++) 234 + for(unsigned int i=0; i<N; i++)
235 result[i] = at(i) - rhs[i]; 235 result[i] = at(i) - rhs[i];
236 236
237 return result; 237 return result;
@@ -340,7 +340,7 @@ struct vec : public std::vector&lt;T&gt; @@ -340,7 +340,7 @@ struct vec : public std::vector&lt;T&gt;
340 unsigned int N = size(); 340 unsigned int N = size();
341 341
342 ss<<"["; 342 ss<<"[";
343 - for(int i=0; i<N; i++) 343 + for(unsigned int i=0; i<N; i++)
344 { 344 {
345 ss<<at(i); 345 ss<<at(i);
346 if(i != N-1) 346 if(i != N-1)
stim/ui/progressbar.h
1 -#ifndef RTS_PROGRESSBAR_H  
2 -#define RTS_PROGRESSBAR_H  
3 - 1 +#ifndef RTS_PROGRESSBAR_H
  2 +#define RTS_PROGRESSBAR_H
  3 +
4 #include <iostream> 4 #include <iostream>
5 #include <sstream> 5 #include <sstream>
6 using namespace std; 6 using namespace std;
7 7
8 -static void rtsProgressBar(int percent) 8 +static void rtsProgressBar(unsigned int percent)
9 { 9 {
  10 + //std::cout<<percent<<std::endl;
10 stringstream bar; 11 stringstream bar;
11 static int x = 0; 12 static int x = 0;
12 string slash[4]; 13 string slash[4];
@@ -25,9 +26,10 @@ static void rtsProgressBar(int percent) @@ -25,9 +26,10 @@ static void rtsProgressBar(int percent)
25 bar<<"]"; 26 bar<<"]";
26 cout << "\r"; // carriage return back to beginning of line 27 cout << "\r"; // carriage return back to beginning of line
27 cout << bar.str() << " " << slash[x] << " " << percent << " %"; // print the bars and percentage 28 cout << bar.str() << " " << slash[x] << " " << percent << " %"; // print the bars and percentage
  29 + cout.flush();
28 x++; // increment to make the slash appear to rotate 30 x++; // increment to make the slash appear to rotate
29 if(x == 4) 31 if(x == 4)
30 x = 0; // reset slash animation 32 x = 0; // reset slash animation
31 -}  
32 -  
33 -#endif 33 +}
  34 +
  35 +#endif
stim/visualization/camera.h
1 -#include "../math/mathvec.h"  
2 -#include "../math/quaternion.h"  
3 -#include "../math/matrix.h" 1 +#include <stim/math/vector.h>
  2 +#include <stim/math/quaternion.h>
  3 +#include <stim/math/matrix.h>
4 4
5 #include <ostream> 5 #include <ostream>
6 6
stim/visualization/glObj.h 0 โ†’ 100644
  1 +#ifndef STIM_GLOBJ_H
  2 +#define STIM_GLOBJ_H
  3 +
  4 +#include <stim/visualization/obj.h>
  5 +#include <GL/glew.h>
  6 +#include <GL/glut.h>
  7 +#include <stim/math/vector.h>
  8 +
  9 +
  10 +namespace stim
  11 +{
  12 +/** This class uses the loading functionality of the obj class in order to
  13 + * Assist with the visualization the segmented vessels.
  14 + * Uses
  15 +*/
  16 +
  17 +class objGl : public virtual stim::obj<T>
  18 +{
  19 +private:
  20 + using stim::obj<T>::L;
  21 + using stim::obj<T>::P;
  22 + using stim::obj<T>::F;
  23 + using vec<T>::size;
  24 + using vec<T>::at;
  25 + GLuint dList;
  26 +
  27 +
  28 + void
  29 + init
  30 + {
  31 + dList = glGenList(1);
  32 + glListBase(dList);
  33 + glMatrixMode(GL_PROJECTION);
  34 + glLoadIdentity;
  35 + glMatrixMode(GL_MODELVIEW);
  36 + glLoadIdentity;
  37 +
  38 + }
  39 +
  40 + void
  41 + Create()
  42 + {
  43 + int len = (int) numL();
  44 + std::vector< stim::vec<float> > line;
  45 + glNewList(dList, GL_COMPILE);
  46 + glColor3f(0.5, 1.0, 0.5);
  47 + for(int i = 0; i < len; i++){
  48 + line = getL_V(i);
  49 + glBegin(GL_LINES);
  50 + for(int j = 0; j < line.size(); j++){
  51 + glVectex3f(
  52 + line[j][0],
  53 + line[j][1],
  54 + line[j][2]
  55 + );
  56 + }
  57 + glEnd();
  58 + }
  59 + glEndList();
  60 + }
  61 +
  62 +public:
  63 + objGl(std::string filename)
  64 + {
  65 + stim::obj::load(filename);
  66 + glPopMatrix(); //Safety Operation to avoid changing the current matrix.
  67 + init();
  68 + Create();
  69 + glPushMatrix();
  70 + }
  71 +
  72 +
  73 + void
  74 + Render()
  75 + {
  76 + glCallList(dList);
  77 + }
  78 +
  79 +}
  80 +}
stim/visualization/obj.h
@@ -52,6 +52,8 @@ protected: @@ -52,6 +52,8 @@ protected:
52 vertex(T x, T y, T z) : stim::vec<T>(x, y, z){} 52 vertex(T x, T y, T z) : stim::vec<T>(x, y, z){}
53 vertex(T x, T y, T z, T w) : stim::vec<T>(x, y, z, w){} 53 vertex(T x, T y, T z, T w) : stim::vec<T>(x, y, z, w){}
54 54
  55 + vertex(stim::vec<T> rhs) : stim::vec<T>(rhs){}
  56 +
55 //constructor creates a vertex from a line string 57 //constructor creates a vertex from a line string
56 vertex(std::string line){ 58 vertex(std::string line){
57 59
@@ -167,6 +169,25 @@ protected: @@ -167,6 +169,25 @@ protected:
167 169
168 } 170 }
169 171
  172 + //returns a vector containing the vertex indices for the geometry
  173 + void get_v(std::vector<unsigned>& v){
  174 + v.resize(size()); //resize the vector to match the number of vertices
  175 + for(unsigned int i = 0; i<size(); i++) //for each vertex
  176 + v[i] = at(i)[0]; //copy the vertex index
  177 + }
  178 +
  179 + void get_vt(std::vector<unsigned>& vt){
  180 + vt.resize(size()); //resize the vector to match the number of vertices
  181 + for(unsigned int i = 0; i<size(); i++) //for each vertex
  182 + vt[i] = at(i)[1]; //copy the vertex index
  183 + }
  184 +
  185 + void get_vn(std::vector<unsigned>& vn){
  186 + vn.resize(size()); //resize the vector to match the number of vertices
  187 + for(unsigned int i = 0; i<size(); i++) //for each vertex
  188 + vn[i] = at(i)[2]; //copy the vertex index
  189 + }
  190 +
170 std::string str(){ 191 std::string str(){
171 192
172 std::stringstream ss; 193 std::stringstream ss;
@@ -291,6 +312,13 @@ protected: @@ -291,6 +312,13 @@ protected:
291 return OBJ_INVALID; 312 return OBJ_INVALID;
292 } 313 }
293 314
  315 + //private method returns the vertex indices for a line
  316 + std::vector<unsigned> get_l_v(unsigned l){
  317 +
  318 +
  319 +
  320 + }
  321 +
294 public: 322 public:
295 /// Constructor loads a Wavefront OBJ file 323 /// Constructor loads a Wavefront OBJ file
296 obj(std::string filename){ 324 obj(std::string filename){
@@ -509,12 +537,70 @@ public: @@ -509,12 +537,70 @@ public:
509 } 537 }
510 538
511 /// Retrieve the vertex stored in index i 539 /// Retrieve the vertex stored in index i
  540 + /// @param vi is the desired vertex index
  541 + stim::vec<T> getV(unsigned int vi){
  542 + stim::vec<T> v = V[vi];
  543 + return v;
  544 + }
512 545
513 - /// @param i is the desired vertex index  
514 - stim::vec<T> getV(unsigned int i){ 546 + /// Retrieve the vertex texture coordinate at index i
  547 + /// @param vti is the desired index
  548 + stim::vec<T> getVT(unsigned int vti){
  549 + stim::vec<T> vt = VT[vti];
  550 + return vt;
  551 + }
515 552
516 - stim::vec<T> v = V[i];  
517 - return v; 553 + /// Retrieve the vertex normal at index i
  554 + /// @param vni is the desired index
  555 + stim::vec<T> getVN(unsigned int vni){
  556 + stim::vec<T> vn = VN[vni];
  557 + return vn;
  558 + }
  559 +
  560 +
  561 + /// Retrieve a vertex stored at a list of given indices
  562 + /// @param vi is an array containing a series of indices
  563 + std::vector< stim::vec<T> > getV( std::vector<unsigned> vi ){
  564 +
  565 + std::vector< stim::vec<T> > v;
  566 + v.resize(vi.size()); //pre-allocate an array of vertices
  567 +
  568 + std::cout<<"stim::obj::getV: "<<v.size()<<std::endl;
  569 +
  570 + for(unsigned i = 0; i < vi.size(); i++)
  571 + v[i] = V[vi[i] - 1];
  572 +
  573 + return v; //return the array of vertices
  574 + }
  575 +
  576 + /// Retrieve a vertex stored at a list of given indices
  577 + /// @param vi is an array containing a series of indices
  578 + std::vector< stim::vec<T> > getVT( std::vector<unsigned> vti ){
  579 +
  580 + std::vector< stim::vec<T> > vt;
  581 + vt.resize(vti.size()); //pre-allocate an array of vertices
  582 +
  583 + std::cout<<"stim::obj::getV: "<<vt.size()<<std::endl;
  584 +
  585 + for(unsigned i = 0; i < vti.size(); i++)
  586 + vt[i] = VT[vti[i] - 1];
  587 +
  588 + return vt; //return the array of vertices
  589 + }
  590 +
  591 + /// Retrieve a vertex stored at a list of given indices
  592 + /// @param vi is an array containing a series of indices
  593 + std::vector< stim::vec<T> > getVN( std::vector<unsigned> vni ){
  594 +
  595 + std::vector< stim::vec<T> > vn;
  596 + vn.resize(vni.size()); //pre-allocate an array of vertices
  597 +
  598 + std::cout<<"stim::obj::getV: "<<vn.size()<<std::endl;
  599 +
  600 + for(unsigned i = 0; i < vni.size(); i++)
  601 + vn[i] = VN[vni[i] - 1];
  602 +
  603 + return vn; //return the array of vertices
518 } 604 }
519 605
520 stim::vec<T> centroid(){ 606 stim::vec<T> centroid(){
@@ -583,7 +669,7 @@ public: @@ -583,7 +669,7 @@ public:
583 669
584 /// Returns the vertex indices for the specified line 670 /// Returns the vertex indices for the specified line
585 /// @param i is the index of the line 671 /// @param i is the index of the line
586 - std::vector< unsigned int > getL_Vi(unsigned int i){ 672 + /*std::vector< unsigned int > getL_Vi(unsigned int i){
587 673
588 unsigned int nP = L[i].size(); 674 unsigned int nP = L[i].size();
589 675
@@ -600,12 +686,12 @@ public: @@ -600,12 +686,12 @@ public:
600 } 686 }
601 687
602 return l; 688 return l;
603 - } 689 + }*/
604 690
605 /// Returns a vector containing the list of texture coordinates associated with each point of a line. 691 /// Returns a vector containing the list of texture coordinates associated with each point of a line.
606 692
607 /// @param i is the index of the desired line 693 /// @param i is the index of the desired line
608 - std::vector< stim::vec<T> > getL_VT(unsigned int i){ 694 + /*std::vector< stim::vec<T> > getL_VT(unsigned int i){
609 695
610 //get the number of points in the specified line 696 //get the number of points in the specified line
611 unsigned int nP = L[i].size(); 697 unsigned int nP = L[i].size();
@@ -631,9 +717,104 @@ public: @@ -631,9 +717,104 @@ public:
631 } 717 }
632 718
633 return l; 719 return l;
  720 + }*/
  721 +
  722 + /// Add an array of vertices to the vertex list
  723 + unsigned int addV(std::vector< stim::vec<T> > vertices){
  724 +
  725 + unsigned int NV = vertices.size(); //get the total number of new vertices
  726 +
  727 + unsigned int currentV = V.size() + 1; //store the index to the first submitted point
  728 +
  729 + //for each vertex
  730 + for(unsigned int vi = 0; vi < NV; vi++){
  731 + vertex v(vertices[vi]);
  732 + V.push_back(v);
  733 + }
  734 +
  735 + //return the index to the first point
  736 + return currentV;
634 737
635 } 738 }
636 739
  740 + /// Add a line to the object
  741 + void addLine(std::vector<unsigned> v, std::vector<unsigned> vt = std::vector<unsigned>(), std::vector<unsigned> vn = std::vector<unsigned>()){
  742 +
  743 + //create a new line geometry
  744 + geometry new_line;
  745 +
  746 + unsigned int v_i, vt_i, vn_i;
  747 + for(unsigned int i = 0; i < v.size(); i++){
  748 + v_i = vt_i = vn_i = 0;
  749 +
  750 + v_i = v[i];
  751 + if(vt.size() != 0)
  752 + vt_i = vt[i];
  753 + if(vn.size() != 0)
  754 + vn_i = vn[i];
  755 +
  756 + new_line.push_back(triplet(v_i, vt_i, vn_i));
  757 + }
  758 +
  759 + //push the new geometry to the line list
  760 + L.push_back(new_line);
  761 + }
  762 +
  763 + /// Fills three std::vector structures with the indices representing a line
  764 + /// @param l is the line index
  765 + /// @param vi is a vertex index array that will be filled
  766 + void getLinei(unsigned l, std::vector<unsigned>& vi){
  767 + L[l-1].get_v(vi);
  768 + }
  769 +
  770 + /// Fills three std::vector structures with the indices representing a line
  771 + /// @param l is the line index
  772 + /// @param vi is a vertex index array that will be filled
  773 + /// @param vti is a vertex texture coordinate index array that will be filled
  774 + void getLinei(unsigned l, std::vector<unsigned>& vi, std::vector<unsigned>& vti){
  775 + getLinei(l, vi);
  776 + L[l-1].get_vt(vti);
  777 + }
  778 +
  779 + /// Fills three std::vector structures with the indices representing a line
  780 + /// @param l is the line index
  781 + /// @param vi is a vertex index array that will be filled
  782 + /// @param vti is a vertex texture coordinate index array that will be filled
  783 + /// @param vni is a vertex normal index array that will be filled
  784 + void getLinei(unsigned l, std::vector<unsigned>& vi, std::vector<unsigned>& vti, std::vector<unsigned>& vni){
  785 + getLinei(l, vi, vti);
  786 + L[l-1].get_vn(vni);
  787 + }
  788 +
  789 + /// Returns a list of points corresponding to the vertices of a line
  790 + void getLine(unsigned l, std::vector< stim::vec<T> > v){
  791 +
  792 + std::vector<unsigned> vi; //create a vector to store indices to vertices
  793 + getLinei(l, vi); //get the indices for the line vertices
  794 + v = getV(vi); //get the vertices corresponding to the indices
  795 + }
  796 +
  797 + void getLine(unsigned l, std::vector< stim::vec<T> > v, std::vector< stim::vec<T> > vt){
  798 +
  799 + std::vector<unsigned> vi, vti;
  800 + getLinei(l, vi, vti); //get the indices for the line vertices
  801 + v = getV(vi); //get the vertices corresponding to the indices
  802 + vt = getVT(vti);
  803 + }
  804 +
  805 + void getLine(unsigned l, std::vector< stim::vec<T> > v,
  806 + std::vector< stim::vec<T> > vt,
  807 + std::vector< stim::vec<T> > vn){
  808 +
  809 + std::vector<unsigned> vi, vti, vni;
  810 + getLinei(l, vi, vti, vni); //get the indices for the line vertices
  811 + v = getV(vi); //get the vertices corresponding to the indices
  812 + vt = getVT(vti);
  813 + vn = getVN(vni);
  814 +
  815 + }
  816 +
  817 +
637 818
638 819
639 }; 820 };