Commit 6236289c5faa27cc3ef88e154c70403061eba2a0

Authored by David Mayerich
2 parents 721fd9d1 9b766f1f

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

stim/cuda/branch_detection.cuh
... ... @@ -7,7 +7,7 @@
7 7 #include <stim/cuda/cuda_texture.cuh>
8 8 #include <stim/cuda/filter.cuh>
9 9 typedef unsigned int uint;
10   -typedef unsigned int uchar;
  10 +//typedef unsigned int uchar;
11 11  
12 12  
13 13 std::vector< stim::vec<float> >
... ...
stim/cuda/spider_cost.cuh
... ... @@ -3,7 +3,7 @@
3 3  
4 4 #include <assert.h>
5 5 #include <cuda.h>
6   -#include <cuda_runtime.h>
  6 +//#include <cuda_runtime.h>
7 7 #include <stdio.h>
8 8 #include <stim/visualization/colormap.h>
9 9 #include <sstream>
... ...
stim/envi/bil.h
... ... @@ -3,8 +3,10 @@
3 3  
4 4 #include "../envi/envi_header.h"
5 5 #include "../envi/hsi.h"
  6 +#include "../math/fd_coefficients.h"
6 7 #include <cstring>
7 8 #include <utility>
  9 +#include <deque>
8 10  
9 11 namespace stim{
10 12  
... ... @@ -22,26 +24,14 @@ template &lt;typename T&gt;
22 24 class bil: public hsi<T> {
23 25  
24 26 protected:
25   -
26   - //std::vector<double> w; //band wavelengths
27 27  
28   - /*unsigned long long X(){
29   - return R[0];
30   - }
31   - unsigned long long Y(){
32   - return R[2];
33   - }
34   - unsigned long long Z(){
35   - return R[1];
36   - }*/
  28 +
37 29 using hsi<T>::w; //use the wavelength array in stim::hsi
38 30 using hsi<T>::nnz;
39 31 using binary<T>::progress;
40   -
41   - /// Call the binary nnz() function for the BIL orientation
42   - //unsigned long long nnz(unsigned char* mask){
43   - // return binary<T>::nnz(mask, X()*Y());
44   - //}
  32 + using hsi<T>::X;
  33 + using hsi<T>::Y;
  34 + using hsi<T>::Z;
45 35  
46 36 public:
47 37  
... ... @@ -59,11 +49,11 @@ public:
59 49 /// @param B is the number of samples (bands) along dimension 3
60 50 /// @param header_offset is the number of bytes (if any) in the binary header
61 51 /// @param wavelengths is an optional STL vector of size B specifying a numerical label for each band
62   - bool open(std::string filename,
63   - unsigned long long X,
64   - unsigned long long Y,
65   - unsigned long long B,
66   - unsigned long long header_offset,
  52 + bool open(std::string filename,
  53 + unsigned long long X,
  54 + unsigned long long Y,
  55 + unsigned long long B,
  56 + unsigned long long header_offset,
67 57 std::vector<double> wavelengths){
68 58  
69 59 w = wavelengths;
... ... @@ -113,7 +103,7 @@ public:
113 103 unsigned long long S = XY * sizeof(T); //calculate the number of bytes of a band
114 104  
115 105 unsigned long long page=0; //bands around the wavelength
116   -
  106 +
117 107  
118 108 //get the bands numbers around the wavelength
119 109  
... ... @@ -173,7 +163,7 @@ public:
173 163  
174 164 //if wavelength is smaller than the first one in header file
175 165 if ( w[page] > wavelength ){
176   - memcpy(p, c, L);
  166 + memcpy(p, c, L);
177 167 return true;
178 168 }
179 169  
... ... @@ -193,16 +183,16 @@ public:
193 183  
194 184 memcpy(p1, c + (page - 1) * X(), L);
195 185 memcpy(p2, c + page * X(), L);
196   -
  186 +
197 187 for(unsigned long long i=0; i < X(); i++){
198 188 double r = (double) (wavelength - w[page-1]) / (double) (w[page] - w[page-1]);
199 189 p[i] = (T)(((double)p2[i] - (double)p1[i]) * r + (double)p1[i]);
200 190 }
201 191 }
202   - else //if the wavelength is equal to a wavelength in header file
  192 + else //if the wavelength is equal to a wavelength in header file
203 193 memcpy(p, c + page * X(), L);
204   -
205   - return true;
  194 +
  195 + return true;
206 196 }
207 197  
208 198 /// Retrieve a single spectrum (B-axis line) at a given (x, y) location and stores it in pre-allocated memory.
... ... @@ -227,24 +217,24 @@ public:
227 217 //get the pixel
228 218 return spectrum(p, x, y);
229 219 }
230   -
  220 +
231 221 //given a Y ,return a XZ slice
232 222 bool read_plane_y(T * p, unsigned long long y){
233 223 return binary<T>::read_plane_2(p, y);
234 224 }
235 225  
236   -
  226 +
237 227 /// Perform baseline correction given a list of baseline points and stores the result in a new BSQ file.
238 228  
239 229 /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
240 230 /// @param wls is the list of baseline points based on band labels.
241 231 bool baseline(std::string outname, std::vector<double> wls, unsigned char* mask = NULL, bool PROGRESS = false){
242   -
  232 +
243 233 unsigned long long N = wls.size(); //get the number of baseline points
244   -
  234 +
245 235 std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
246   - std::string headername = outname + ".hdr"; //the header file name
247   -
  236 + std::string headername = outname + ".hdr"; //the header file name
  237 +
248 238 //simplify image resolution
249 239 unsigned long long ZX = Z() * X(); //calculate the number of points in a Y slice
250 240 unsigned long long L = ZX * sizeof(T); //calculate the number of bytes of a Y slice
... ... @@ -252,10 +242,10 @@ public:
252 242  
253 243 T* c; //pointer to the current Y slice
254 244 c = (T*)malloc(L); //memory allocation
255   -
  245 +
256 246 T* a; //pointer to the two YZ lines surrounding the current YZ line
257 247 T* b;
258   -
  248 +
259 249 a = (T*)malloc(X() * sizeof(T));
260 250 b = (T*)malloc(X() * sizeof(T));
261 251  
... ... @@ -269,19 +259,19 @@ public:
269 259 exit(1);
270 260 }
271 261 // loop start correct every y slice
272   -
  262 +
273 263 for (unsigned long long k =0; k < Y(); k++)
274 264 {
275 265 //get the current y slice
276 266 read_plane_y(c, k);
277   -
278   - //initialize lownum, highnum, low, high
  267 +
  268 + //initialize lownum, highnum, low, high
279 269 ai = w[0];
280 270 control=0;
281 271 //if no baseline point is specified at band 0,
282 272 //set the baseline point at band 0 to 0
283 273 if(wls[0] != w[0]){
284   - bi = wls[control];
  274 + bi = wls[control];
285 275 memset(a, (char)0, X() * sizeof(T) );
286 276 }
287 277 //else get the low band
... ... @@ -292,39 +282,39 @@ public:
292 282 }
293 283 //get the high band
294 284 read_x_from_xz(b, c, bi);
295   -
  285 +
296 286 //correct every YZ line
297   -
  287 +
298 288 for(unsigned long long cii = 0; cii < B; cii++){
299 289  
300 290 //update baseline points, if necessary
301 291 if( w[cii] >= bi && cii != B - 1) {
302 292 //if the high band is now on the last BL point
303 293 if (control != N-1) {
304   -
  294 +
305 295 control++; //increment the index
306   -
  296 +
307 297 std::swap(a, b); //swap the baseline band pointers
308   -
  298 +
309 299 ai = bi;
310 300 bi = wls[control];
311 301 read_x_from_xz(b, c, bi);
312   -
  302 +
313 303 }
314 304 //if the last BL point on the last band of the file?
315 305 else if ( wls[control] < w[B - 1]) {
316   -
  306 +
317 307 std::swap(a, b); //swap the baseline band pointers
318   -
  308 +
319 309 memset(b, (char)0, X() * sizeof(T) ); //clear the high band
320   -
  310 +
321 311 ai = bi;
322 312 bi = w[B - 1];
323 313 }
324 314 }
325   -
  315 +
326 316 ci = w[cii];
327   -
  317 +
328 318 unsigned long long jump = cii * X();
329 319 //perform the baseline correction
330 320 for(unsigned i=0; i < X(); i++)
... ... @@ -332,22 +322,22 @@ public:
332 322 double r = (double) (ci - ai) / (double) (bi - ai);
333 323 c[i + jump] =(T) ( c[i + jump] - (b[i] - a[i]) * r - a[i] );
334 324 }
335   -
336   - }//loop for YZ line end
337   - target.write(reinterpret_cast<const char*>(c), L); //write the corrected data into destination
  325 +
  326 + }//loop for YZ line end
  327 + target.write(reinterpret_cast<const char*>(c), L); //write the corrected data into destination
338 328  
339 329 if(PROGRESS) progress = (double)(k+1) / Y() * 100;
340   - }//loop for Y slice end
341   -
  330 + }//loop for Y slice end
  331 +
342 332 free(a);
343 333 free(b);
344 334 free(c);
345 335 target.close();
346 336  
347   - return true;
348   -
  337 + return true;
  338 +
349 339 }
350   -
  340 +
351 341 /// Normalize all spectra based on the value of a single band, storing the result in a new BSQ file.
352 342  
353 343 /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
... ... @@ -358,7 +348,7 @@ public:
358 348 unsigned long long B = Z(); //calculate the number of bands
359 349 unsigned long long ZX = Z() * X();
360 350 unsigned long long XY = X() * Y(); //calculate the number of pixels in a band
361   - unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band
  351 + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band
362 352 unsigned long long L = ZX * sizeof(T);
363 353  
364 354 std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
... ... @@ -368,7 +358,7 @@ public:
368 358 T * b; //pointer to the standard band
369 359  
370 360 b = (T*)malloc( S ); //memory allocation
371   - c = (T*)malloc( L );
  361 + c = (T*)malloc( L );
372 362  
373 363 band(b, w); //get the certain band into memory
374 364  
... ... @@ -383,13 +373,13 @@ public:
383 373 c[m + i * X()] = (T)0.0;
384 374 else
385 375 c[m + i * X()] = c[m + i * X()] / b[m + j * X()];
386   - }
  376 + }
387 377 }
388 378 target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination
389 379  
390 380 if(PROGRESS) progress = (double)(j+1) / Y() * 100;
391 381 }
392   -
  382 +
393 383 free(b);
394 384 free(c);
395 385 target.close();
... ... @@ -397,26 +387,26 @@ public:
397 387 }
398 388  
399 389 void normalize(std::string outfile, unsigned char* mask = NULL, bool PROGRESS = false){}
400   -
  390 +
401 391 /// Convert the current BIL file to a BSQ file with the specified file name.
402 392  
403 393 /// @param outname is the name of the output BSQ file to be saved to disk.
404 394 bool bsq(std::string outname, bool PROGRESS = false)
405 395 {
406 396 unsigned long long S = X() * Y() * sizeof(T); //calculate the number of bytes in a band
407   -
  397 +
408 398 std::ofstream target(outname.c_str(), std::ios::binary);
409 399 std::string headername = outname + ".hdr";
410   -
  400 +
411 401 T * p; //pointer to the current band
412 402 p = (T*)malloc(S);
413   -
  403 +
414 404 for ( unsigned long long i = 0; i < Z(); i++)
415   - {
  405 + {
416 406 band_index(p, i);
417 407 target.write(reinterpret_cast<const char*>(p), S); //write a band data into target file
418 408  
419   - if(PROGRESS) progress = (double)(i+1) / Z() * 100; //store the progress for the current operation
  409 + if(PROGRESS) progress = (double)(i+1) / Z() * 100; //store the progress for the current operation
420 410 }
421 411  
422 412 free(p);
... ... @@ -430,17 +420,17 @@ public:
430 420 bool bip(std::string outname, bool PROGRESS = false)
431 421 {
432 422 unsigned long long S = X() * Z() * sizeof(T); //calculate the number of bytes in a ZX slice
433   -
  423 +
434 424 std::ofstream target(outname.c_str(), std::ios::binary);
435 425 std::string headername = outname + ".hdr";
436   -
  426 +
437 427 T * p; //pointer to the current XZ slice for bil file
438 428 p = (T*)malloc(S);
439 429 T * q; //pointer to the current ZX slice for bip file
440 430 q = (T*)malloc(S);
441   -
  431 +
442 432 for ( unsigned long long i = 0; i < Y(); i++)
443   - {
  433 + {
444 434 read_plane_y(p, i);
445 435 for ( unsigned long long k = 0; k < Z(); k++)
446 436 {
... ... @@ -448,10 +438,10 @@ public:
448 438 for ( unsigned long long j = 0; j < X(); j++)
449 439 q[k + j * Z()] = p[ks + j];
450 440  
451   - if(PROGRESS) progress = (double)((i+1) * Z() + k+1) / (Z() * Y()) * 100; //store the progress for the current operation
  441 + if(PROGRESS) progress = (double)((i+1) * Z() + k+1) / (Z() * Y()) * 100; //store the progress for the current operation
452 442 }
453   -
454   - target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file
  443 +
  444 + target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file
455 445 }
456 446  
457 447 free(p);
... ... @@ -498,7 +488,7 @@ public:
498 488 rp = (T*) malloc(S);
499 489  
500 490 band(lp, lb);
501   - band(rp, rb);
  491 + band(rp, rb);
502 492  
503 493 baseline_band(lb, rb, lp, rp, bandwavelength, result);
504 494  
... ... @@ -570,7 +560,7 @@ public:
570 560 }
571 561 baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part
572 562 baseline_band(lb, rb, lp, rp, w[ai], cur);
573   - for(unsigned long long j = 0; j < XY; j++){
  563 + for(unsigned long long j = 0; j < XY; j++){
574 564 result[j] += (T)((w[ai] - lab) * ((double)cur[j] + (double)cur2[j]) / 2.0);
575 565 }
576 566  
... ... @@ -581,7 +571,7 @@ public:
581 571 baseline_band(lb, rb, lp, rp, w[ai], cur2);
582 572 for(unsigned long long j = 0; j < XY; j++)
583 573 {
584   - result[j] += (T)((w[ai] - w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 2.0);
  574 + result[j] += (T)((w[ai] - w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 2.0);
585 575 }
586 576 std::swap(cur,cur2); //swap the band pointers
587 577 }
... ... @@ -606,7 +596,7 @@ public:
606 596  
607 597 T* p1 = (T*)malloc(X() * Y() * sizeof(T));
608 598 T* p2 = (T*)malloc(X() * Y() * sizeof(T));
609   -
  599 +
610 600 //get the two peak band
611 601 height(lb1, rb1, pos1, p1);
612 602 height(lb2, rb2, pos2, p2);
... ... @@ -620,9 +610,9 @@ public:
620 610  
621 611 free(p1);
622 612 free(p2);
623   - return true;
  613 + return true;
624 614 }
625   -
  615 +
626 616 /// Compute the ratio between a peak area and peak height.
627 617  
628 618 /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
... ... @@ -634,10 +624,10 @@ public:
634 624 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
635 625 bool pa_to_ph(T* result, double lb1, double rb1, double lab1, double rab1,
636 626 double lb2, double rb2, double pos, unsigned char* mask = NULL){
637   -
  627 +
638 628 T* p1 = (T*)malloc(X() * Y() * sizeof(T));
639 629 T* p2 = (T*)malloc(X() * Y() * sizeof(T));
640   -
  630 +
641 631 //get the area and the peak band
642 632 area(lb1, rb1, lab1, rab1, p1);
643 633 height(lb2, rb2, pos, p2);
... ... @@ -651,9 +641,9 @@ public:
651 641  
652 642 free(p1);
653 643 free(p2);
654   - return true;
655   - }
656   -
  644 + return true;
  645 + }
  646 +
657 647 /// Compute the ratio between two peak areas.
658 648  
659 649 /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
... ... @@ -663,14 +653,14 @@ public:
663 653 /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
664 654 /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
665 655 /// @param lab2 is the label value for the left bound (start of the integration) of the second peak (denominator)
666   - /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator)
  656 + /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator)
667 657 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
668 658 bool pa_to_pa(T* result, double lb1, double rb1, double lab1, double rab1,
669 659 double lb2, double rb2, double lab2, double rab2, unsigned char* mask = NULL){
670   -
  660 +
671 661 T* p1 = (T*)malloc(X() * Y() * sizeof(T));
672 662 T* p2 = (T*)malloc(X() * Y() * sizeof(T));
673   -
  663 +
674 664 //get the area and the peak band
675 665 area(lb1, rb1, lab1, rab1, p1);
676 666 area(lb2, rb2, lab2, rab2, p2);
... ... @@ -684,8 +674,8 @@ public:
684 674  
685 675 free(p1);
686 676 free(p2);
687   - return true;
688   - }
  677 + return true;
  678 + }
689 679  
690 680 /// Compute the definite integral of a baseline corrected peak.
691 681  
... ... @@ -745,7 +735,7 @@ public:
745 735 }
746 736 baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part
747 737 baseline_band(lb, rb, lp, rp, w[ai], cur);
748   - for(unsigned long long j = 0; j < XY; j++){
  738 + for(unsigned long long j = 0; j < XY; j++){
749 739 result[j] += (T)((w[ai] - lab) * (w[ai] + lab) * ((double)cur[j] + (double)cur2[j]) / 4.0);
750 740 }
751 741  
... ... @@ -756,7 +746,7 @@ public:
756 746 baseline_band(lb, rb, lp, rp, w[ai], cur2);
757 747 for(unsigned long long j = 0; j < XY; j++)
758 748 {
759   - result[j] += (T)((w[ai] - w[ai-1]) * (w[ai] + w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 4.0);
  749 + result[j] += (T)((w[ai] - w[ai-1]) * (w[ai] + w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 4.0);
760 750 }
761 751 std::swap(cur,cur2); //swap the band pointers
762 752 }
... ... @@ -778,7 +768,7 @@ public:
778 768 bool centroid(T* result, double lb, double rb, double lab, double rab, unsigned char* mask = NULL){
779 769 T* p1 = (T*)malloc(X() * Y() * sizeof(T));
780 770 T* p2 = (T*)malloc(X() * Y() * sizeof(T));
781   -
  771 +
782 772 //get the area and the peak band
783 773 x_area(lb, rb, lab, rab, p1);
784 774 area(lb, rb, lab, rab, p2);
... ... @@ -790,7 +780,7 @@ public:
790 780  
791 781 free(p1);
792 782 free(p2);
793   - return true;
  783 + return true;
794 784 }
795 785  
796 786 /// Create a mask based on a given band and threshold value.
... ... @@ -843,7 +833,7 @@ public:
843 833 continue;
844 834 }
845 835 }
846   - target.write(reinterpret_cast<const char*>(temp), L); //write a band data into target file
  836 + target.write(reinterpret_cast<const char*>(temp), L); //write a band data into target file
847 837 if(PROGRESS) progress = (double)(i+1) / (double)Y() * 100;
848 838 }
849 839 target.close();
... ... @@ -861,7 +851,7 @@ public:
861 851 T* line = (T*) malloc( Lbytes ); //allocate space for a line
862 852  
863 853 file.seekg(0, std::ios::beg); //seek to the beginning of the file
864   -
  854 +
865 855 size_t pl;
866 856 size_t p = 0; //create counter variables
867 857 for(size_t y = 0; y < Y(); y++){ //for each line in the data set
... ... @@ -903,7 +893,7 @@ public:
903 893 {
904 894 read_plane_y(slice, y); //retrieve an ZX page, store in "slice"
905 895  
906   - //for each sample along X
  896 + //for each sample along X
907 897 for (unsigned long long x = 0; x < X(); x++) //Select a pixel by choosing X coordinate in the page, X()
908 898 {
909 899 //if the mask != 0 at that xy pixel
... ... @@ -1082,7 +1072,7 @@ public:
1082 1072 for (unsigned long long z = b0; z < b1; z++)
1083 1073 {
1084 1074 file.read((char *)(temp + z * samples), sizeof(T) * samples);
1085   - file.seekg(jumpb, std::ios::cur); //go to the next band
  1075 + file.seekg(jumpb, std::ios::cur); //go to the next band
1086 1076  
1087 1077 if(PROGRESS) progress = (double)(x * Z() + z+1) / (lines * Z()) * 100;
1088 1078 }
... ... @@ -1193,7 +1183,7 @@ public:
1193 1183 size_t N = C.size(); //get the number of bands that the kernel spans
1194 1184 std::deque<T*> frame(N, NULL); //create an array to store pointers to each frame
1195 1185 for(size_t f = 0; f < N; f++)
1196   - frame[f] = (T*)malloc(Xb); //allocate space for the frame
  1186 + frame[f] = (T*)malloc(Xb); //allocate space for the frame
1197 1187  
1198 1188 T* outline = (T*)malloc(Xb); //allocate space for the output band
1199 1189  
... ... @@ -1219,23 +1209,23 @@ public:
1219 1209 frame.pop_front(); //pop the first element
1220 1210 }
1221 1211 if(PROGRESS) progress = (double)(y+1) / (double)Y() * 100;
1222   - }
  1212 + }
1223 1213 }
1224 1214  
1225 1215 /// Approximate the spectral derivative of the image
1226 1216 void deriv(std::string outfile, size_t d, size_t order, const std::vector<double> w = std::vector<double>(), unsigned char* mask = NULL, bool PROGRESS = false){
1227 1217 std::ofstream out(outfile.c_str(), std::ios::binary); //open the output file for writing
1228   -
  1218 +
1229 1219 size_t Xb = X() * sizeof(T); //calculate the size of a line (frame) in bytes
1230 1220 size_t XBb = Xb * Z();
1231 1221 size_t B = Z();
1232 1222  
1233   - file.seekg(0, std::ios::beg); //seek to the beginning of the file
  1223 + file.seekg(0, std::ios::beg); //seek to the beginning of the file
1234 1224  
1235 1225 size_t N = order + d; //approximating a derivative requires order + d samples
1236 1226 std::deque<T*> frame(N, NULL); //create an array to store pointers to each frame
1237 1227 for(size_t f = 0; f < N; f++) //for each frame
1238   - frame[f] = (T*)malloc(Xb); //allocate space for the frame
  1228 + frame[f] = (T*)malloc(Xb); //allocate space for the frame
1239 1229  
1240 1230 T* outline = (T*)malloc(Xb); //allocate space for the output band
1241 1231  
... ... @@ -1273,7 +1263,7 @@ public:
1273 1263 }
1274 1264 }
1275 1265 out.write((char*)outline, Xb); //output the band
1276   -
  1266 +
1277 1267 }
1278 1268 if(PROGRESS) progress = (double)(y+1) / (double)Y() * 100;
1279 1269 }
... ...
stim/envi/bip.h
... ... @@ -28,15 +28,18 @@ template &lt;typename T&gt;
28 28 class bip: public hsi<T> {
29 29  
30 30 protected:
31   -
32   -
  31 +
  32 +
33 33 //std::vector<double> w; //band wavelength
34 34 unsigned long long offset; //header offset
35 35  
36 36 using hsi<T>::w; //use the wavelength array in stim::hsi
37 37 using hsi<T>::nnz;
38 38 using binary<T>::progress;
39   -
  39 + using hsi<T>::X;
  40 + using hsi<T>::Y;
  41 + using hsi<T>::Z;
  42 +
40 43 public:
41 44  
42 45 using binary<T>::open;
... ... @@ -54,11 +57,11 @@ public:
54 57 /// @param B is the number of samples (bands) along dimension 3
55 58 /// @param header_offset is the number of bytes (if any) in the binary header
56 59 /// @param wavelengths is an optional STL vector of size B specifying a numerical label for each band
57   - bool open(std::string filename,
58   - unsigned long long X,
59   - unsigned long long Y,
60   - unsigned long long B,
61   - unsigned long long header_offset,
  60 + bool open(std::string filename,
  61 + unsigned long long X,
  62 + unsigned long long Y,
  63 + unsigned long long B,
  64 + unsigned long long header_offset,
62 65 std::vector<double> wavelengths){
63 66  
64 67 //copy the wavelengths to the BSQ file structure
... ... @@ -67,7 +70,7 @@ public:
67 70 offset = header_offset;
68 71  
69 72 return open(filename, vec<unsigned long long>(B, X, Y), header_offset);
70   -
  73 +
71 74 }
72 75  
73 76 /// Retrieve a single band (based on index) and stores it in pre-allocated memory.
... ... @@ -160,7 +163,7 @@ public:
160 163 for(unsigned long long j = 0; j < X(); j++)
161 164 {
162 165 p[j] = c[j * B];
163   - }
  166 + }
164 167 return true;
165 168 }
166 169  
... ... @@ -192,7 +195,7 @@ public:
192 195 {
193 196 p2[j] = c[j * B + page];
194 197 }
195   -
  198 +
196 199 for(unsigned long long i=0; i < X(); i++){
197 200 double r = (double) (wavelength - w[page-1]) / (double) (w[page] - w[page-1]);
198 201 p[i] = (p2[i] - p1[i]) * r + p1[i];
... ... @@ -209,7 +212,7 @@ public:
209 212 }
210 213 }
211 214  
212   - return true;
  215 + return true;
213 216 }
214 217  
215 218 /// Retrieve a single pixel and store it in a pre-allocated double array.
... ... @@ -246,20 +249,20 @@ public:
246 249 file.read((char *)p, sizeof(T) * Z());
247 250 return true;
248 251 }
249   -
  252 +
250 253 //given a Y ,return a ZX slice
251 254 bool read_plane_y(T * p, unsigned long long y){
252 255 return binary<T>::read_plane_2(p, y);
253 256 }
254   -
  257 +
255 258 /// Perform baseline correction given a list of baseline points and stores the result in a new BSQ file.
256 259  
257 260 /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
258   - /// @param wls is the list of baseline points based on band labels.
  261 + /// @param wls is the list of baseline points based on band labels.
259 262 bool baseline(std::string outname, std::vector<double> base_pts, unsigned char* mask = NULL, bool PROGRESS = false){
260   -
  263 +
261 264 std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
262   -
  265 +
263 266 unsigned long long N = X() * Y(); //calculate the total number of pixels to be processed
264 267 unsigned long long B = Z(); //get the number of bands
265 268 T* s = (T*)malloc(sizeof(T) * B); //allocate memory to store a pixel
... ... @@ -274,9 +277,9 @@ public:
274 277 memset(sbc, 0, sizeof(T) * B); //set the baseline corrected spectrum to zero
275 278 }
276 279 else{
277   -
  280 +
278 281 pixel(s, n); //retrieve the spectrum s
279   - base_vals = interp_spectrum(s, base_pts); //get the values at each baseline point
  282 + base_vals = hsi<T>::interp_spectrum(s, base_pts); //get the values at each baseline point
280 283  
281 284 ai = bi = 0;
282 285 aw = w[0]; //initialize the current baseline points (assume the spectrum starts at 0)
... ... @@ -298,23 +301,23 @@ public:
298 301 aw = base_pts[ai]; //set the wavelength for the lower bound baseline point
299 302 av = base_vals[ai]; //set the value for the lower bound baseline point
300 303 }
301   - sbc[b] = s[b] - lerp(w[b], av, aw, bv, bw); //perform the baseline correction and save the new value
  304 + sbc[b] = s[b] - hsi<T>::lerp(w[b], av, aw, bv, bw); //perform the baseline correction and save the new value
302 305 }
303 306 }
304   -
  307 +
305 308 if(PROGRESS) progress = (double)(n+1) / N * 100; //set the current progress
306 309  
307 310 target.write((char*)sbc, sizeof(T) * B); //write the corrected data into destination
308 311 } //end for each pixel
309   -
  312 +
310 313 free(s);
311 314 free(sbc);
312 315 target.close();
313   -
314   - return true;
315   -
  316 +
  317 + return true;
  318 +
316 319 }
317   -
  320 +
318 321 /// Normalize all spectra based on the value of a single band, storing the result in a new BSQ file.
319 322  
320 323 /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
... ... @@ -323,8 +326,8 @@ public:
323 326 bool ratio(std::string outname, double w, unsigned char* mask = NULL, bool PROGRESS = false)
324 327 {
325 328 std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
326   - std::string headername = outname + ".hdr"; //the header file name
327   -
  329 + std::string headername = outname + ".hdr"; //the header file name
  330 +
328 331 unsigned long long N = X() * Y(); //calculate the total number of pixels to be processed
329 332 unsigned long long B = Z(); //get the number of bands
330 333 T* s = (T*)malloc(sizeof(T) * B); //allocate memory to store a pixel
... ... @@ -334,24 +337,24 @@ public:
334 337 memset(s, 0, sizeof(T) * B); //set the output to zero
335 338 else{
336 339 pixel(s, n); //retrieve the spectrum s
337   - nv = interp_spectrum(s, w); //find the value of the normalization band
338   -
  340 + nv = hsi<T>::interp_spectrum(s, w); //find the value of the normalization band
  341 +
339 342 for(unsigned long long b = 0; b < B; b++) //for each band in the spectrum
340 343 s[b] /= nv; //divide by the normalization value
341 344 }
342   -
  345 +
343 346 if(PROGRESS) progress = (double)(n+1) / N * 100; //set the current progress
344 347  
345 348 target.write((char*)s, sizeof(T) * B); //write the corrected data into destination
346 349 } //end for each pixel
347   -
  350 +
348 351 free(s);
349 352 target.close();
350 353 return true;
351 354 }
352 355  
353 356 void normalize(std::string outfile, unsigned char* mask = NULL, bool PROGRESS = false){}
354   -
  357 +
355 358  
356 359 /// Convert the current BIP file to a BIL file with the specified file name.
357 360  
... ... @@ -359,17 +362,17 @@ public:
359 362 bool bil(std::string outname, bool PROGRESS = false)
360 363 {
361 364 unsigned long long S = X() * Z() * sizeof(T); //calculate the number of bytes in a ZX slice
362   -
  365 +
363 366 std::ofstream target(outname.c_str(), std::ios::binary);
364 367 //std::string headername = outname + ".hdr";
365   -
  368 +
366 369 T * p; //pointer to the current ZX slice for bip file
367 370 p = (T*)malloc(S);
368 371 T * q; //pointer to the current XZ slice for bil file
369 372 q = (T*)malloc(S);
370   -
  373 +
371 374 for ( unsigned long long i = 0; i < Y(); i++)
372   - {
  375 + {
373 376 read_plane_y(p, i);
374 377 for ( unsigned long long k = 0; k < Z(); k++)
375 378 {
... ... @@ -379,7 +382,7 @@ public:
379 382  
380 383 if(PROGRESS) progress = (double)(i * Z() + k+1) / (Y() * Z()) * 100;
381 384 }
382   - target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file
  385 + target.write(reinterpret_cast<const char*>(q), S); //write a band data into target file
383 386 }
384 387  
385 388 free(p);
... ... @@ -408,7 +411,7 @@ public:
408 411 }
409 412 return true;
410 413 }
411   -
  414 +
412 415 /// Return a baseline corrected band given two adjacent baseline points. The result is stored in a pre-allocated array.
413 416  
414 417 /// @param lb is the label value for the left baseline point
... ... @@ -425,7 +428,7 @@ public:
425 428 rp = (T*) malloc(S);
426 429  
427 430 band(lp, lb);
428   - band(rp, rb);
  431 + band(rp, rb);
429 432  
430 433 baseline_band(lb, rb, lp, rp, bandwavelength, result);
431 434  
... ... @@ -496,7 +499,7 @@ public:
496 499 }
497 500 baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part
498 501 baseline_band(lb, rb, lp, rp, w[ai], cur);
499   - for(unsigned long long j = 0; j < XY; j++){
  502 + for(unsigned long long j = 0; j < XY; j++){
500 503 result[j] += (T)((w[ai] - lab) * ((double)cur[j] + (double)cur2[j]) / 2.0);
501 504 }
502 505  
... ... @@ -507,7 +510,7 @@ public:
507 510 baseline_band(lb, rb, lp, rp, w[ai], cur2);
508 511 for(unsigned long long j = 0; j < XY; j++)
509 512 {
510   - result[j] += (T)((w[ai] - w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 2.0);
  513 + result[j] += (T)((w[ai] - w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 2.0);
511 514 }
512 515 std::swap(cur,cur2); //swap the band pointers
513 516 }
... ... @@ -530,9 +533,9 @@ public:
530 533 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
531 534 bool ph_to_ph(T* result, double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, unsigned char* mask = NULL){
532 535  
533   - T* p1 = (T*)malloc(X() * Y() * sizeof(T));
534   - T* p2 = (T*)malloc(X() * Y() * sizeof(T));
535   -
  536 + T* p1 = (T*)malloc(X() * Y() * sizeof(T));
  537 + T* p2 = (T*)malloc(X() * Y() * sizeof(T));
  538 +
536 539 //get the two peak band
537 540 height(lb1, rb1, pos1, p1);
538 541 height(lb2, rb2, pos2, p2);
... ... @@ -546,9 +549,9 @@ public:
546 549  
547 550 free(p1);
548 551 free(p2);
549   - return true;
  552 + return true;
550 553 }
551   -
  554 +
552 555 /// Compute the ratio between a peak area and peak height.
553 556  
554 557 /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
... ... @@ -560,10 +563,10 @@ public:
560 563 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
561 564 bool pa_to_ph(T* result, double lb1, double rb1, double lab1, double rab1,
562 565 double lb2, double rb2, double pos, unsigned char* mask = NULL){
563   -
564   - T* p1 = (T*)malloc(X() * Y() * sizeof(T));
565   - T* p2 = (T*)malloc(X() * Y() * sizeof(T));
566   -
  566 +
  567 + T* p1 = (T*)malloc(X() * Y() * sizeof(T));
  568 + T* p2 = (T*)malloc(X() * Y() * sizeof(T));
  569 +
567 570 //get the area and the peak band
568 571 area(lb1, rb1, lab1, rab1, p1);
569 572 height(lb2, rb2, pos, p2);
... ... @@ -577,9 +580,9 @@ public:
577 580  
578 581 free(p1);
579 582 free(p2);
580   - return true;
581   - }
582   -
  583 + return true;
  584 + }
  585 +
583 586 /// Compute the ratio between two peak areas.
584 587  
585 588 /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
... ... @@ -589,14 +592,14 @@ public:
589 592 /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
590 593 /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
591 594 /// @param lab2 is the label value for the left bound (start of the integration) of the second peak (denominator)
592   - /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator)
  595 + /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator)
593 596 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
594 597 bool pa_to_pa(T* result, double lb1, double rb1, double lab1, double rab1,
595 598 double lb2, double rb2, double lab2, double rab2, unsigned char* mask = NULL){
596   -
597   - T* p1 = (T*)malloc(X() * Y() * sizeof(T));
598   - T* p2 = (T*)malloc(X() * Y() * sizeof(T));
599   -
  599 +
  600 + T* p1 = (T*)malloc(X() * Y() * sizeof(T));
  601 + T* p2 = (T*)malloc(X() * Y() * sizeof(T));
  602 +
600 603 //get the area and the peak band
601 604 area(lb1, rb1, lab1, rab1, p1);
602 605 area(lb2, rb2, lab2, rab2, p2);
... ... @@ -610,8 +613,8 @@ public:
610 613  
611 614 free(p1);
612 615 free(p2);
613   - return true;
614   - }
  616 + return true;
  617 + }
615 618  
616 619 /// Compute the definite integral of a baseline corrected peak.
617 620  
... ... @@ -671,7 +674,7 @@ public:
671 674 }
672 675 baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part
673 676 baseline_band(lb, rb, lp, rp, w[ai], cur);
674   - for(unsigned long long j = 0; j < XY; j++){
  677 + for(unsigned long long j = 0; j < XY; j++){
675 678 result[j] += (T)((w[ai] - lab) * (w[ai] + lab) * ((double)cur[j] + (double)cur2[j]) / 4.0);
676 679 }
677 680  
... ... @@ -682,7 +685,7 @@ public:
682 685 baseline_band(lb, rb, lp, rp, w[ai], cur2);
683 686 for(unsigned long long j = 0; j < XY; j++)
684 687 {
685   - result[j] += (T)((w[ai] - w[ai-1]) * (w[ai] + w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 4.0);
  688 + result[j] += (T)((w[ai] - w[ai-1]) * (w[ai] + w[ai-1]) * ((double)cur[j] + (double)cur2[j]) / 4.0);
686 689 }
687 690 std::swap(cur,cur2); //swap the band pointers
688 691 }
... ... @@ -702,9 +705,9 @@ public:
702 705 /// @param rab is the label for the end of the peak
703 706 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
704 707 bool centroid(T* result, double lb, double rb, double lab, double rab, unsigned char* mask = NULL){
705   - T* p1 = (T*)malloc(X() * Y() * sizeof(T));
706   - T* p2 = (T*)malloc(X() * Y() * sizeof(T));
707   -
  708 + T* p1 = (T*)malloc(X() * Y() * sizeof(T));
  709 + T* p2 = (T*)malloc(X() * Y() * sizeof(T));
  710 +
708 711 //get the area and the peak band
709 712 x_area(lb, rb, lab, rab, p1);
710 713 area(lb, rb, lab, rab, p2);
... ... @@ -716,7 +719,7 @@ public:
716 719  
717 720 free(p1);
718 721 free(p2);
719   - return true;
  722 + return true;
720 723 }
721 724  
722 725 /// Create a mask based on a given band and threshold value.
... ... @@ -788,7 +791,7 @@ public:
788 791 T* band = (T*) malloc( Bbytes ); //allocate space for a line
789 792  
790 793 file.seekg(0, std::ios::beg); //seek to the beginning of the file
791   -
  794 +
792 795 size_t p = 0; //create counter variables
793 796 for(size_t xy = 0; xy < XY; xy++){ //for each pixel
794 797 if(mask[xy]){ //if the current pixel is masked
... ... @@ -800,7 +803,7 @@ public:
800 803 p++; //increment the pixel pointer
801 804 }
802 805 else
803   - file.seekg(Bbytes, std::ios::cur); //otherwise skip this band
  806 + file.seekg(Bbytes, std::ios::cur); //otherwise skip this band
804 807 }
805 808 return true;
806 809 }
... ... @@ -809,7 +812,7 @@ public:
809 812 bool sift(std::string outfile, unsigned char* mask, bool PROGRESS = false){
810 813  
811 814 //reset the file pointer to the beginning of the file
812   - file.seekg(0, std::ios::beg);
  815 + file.seekg(0, std::ios::beg);
813 816  
814 817 // open an output stream
815 818 std::ofstream target(outfile.c_str(), std::ios::binary);
... ... @@ -862,7 +865,7 @@ public:
862 865 std::ofstream target(outfile.c_str(), std::ios::binary);
863 866  
864 867 //reset the file pointer to the beginning of the file
865   - file.seekg(0, std::ios::beg);
  868 + file.seekg(0, std::ios::beg);
866 869  
867 870 //allocate space for a single spectrum
868 871 unsigned long long B = Z();
... ... @@ -942,10 +945,10 @@ public:
942 945 /// Note that cuBLAS only supports integer-sized arrays, so there may be issues with large spectra
943 946 bool co_matrix_cublas(double* co, double* avg, unsigned char *mask, bool PROGRESS = false){
944 947  
945   - cudaError_t cudaStat;
  948 + cudaError_t cudaStat;
946 949 cublasStatus_t stat;
947 950 cublasHandle_t handle;
948   -
  951 +
949 952 progress = 0; //initialize the progress to zero (0)
950 953 unsigned long long XY = X() * Y(); //calculate the number of elements in a band image
951 954 unsigned long long B = Z(); //calculate the number of spectral elements
... ... @@ -959,7 +962,7 @@ public:
959 962 cudaStat = cudaMemset(A_dev, 0, B * B * sizeof(double)); //initialize the covariance matrix to zero (0)
960 963 cudaStat = cudaMalloc(&avg_dev, B * sizeof(double)); //allocate space on the CUDA device for the average spectrum
961 964 stat = cublasSetVector((int)B, sizeof(double), avg, 1, avg_dev, 1); //copy the average spectrum to the CUDA device
962   -
  965 +
963 966 double ger_alpha = 1.0/(double)XY; //scale the outer product by the inverse of the number of samples (mean outer product)
964 967 double axpy_alpha = -1; //multiplication factor for the average spectrum (in order to perform a subtraction)
965 968  
... ... @@ -994,7 +997,7 @@ public:
994 997 return true;
995 998 }
996 999 #endif
997   -
  1000 +
998 1001 /// Calculate the covariance matrix for all masked pixels in the image with 64-bit floating point precision.
999 1002  
1000 1003 /// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix
... ... @@ -1074,7 +1077,7 @@ public:
1074 1077 }
1075 1078 }
1076 1079 }
1077   -
  1080 +
1078 1081 target.write(reinterpret_cast<const char*>(rs), sizeof(T) * M); //write the projected vector
1079 1082 if(PROGRESS) progress = (double)(xy+1) / XY * 100;
1080 1083 }
... ... @@ -1104,7 +1107,7 @@ public:
1104 1107 memset(s, 0, sizeof(T) * B); //initialize the spectrum to zero (0)
1105 1108 for(unsigned long long c = 0; c < C; c++){ //for each basis vector coefficient
1106 1109 bv = &basis[c * B]; //assign 'bv' to the beginning of the basis vector
1107   - for(unsigned long long b = 0; b < B; b++){ //for each component of the basis vector
  1110 + for(unsigned long long b = 0; b < B; b++){ //for each component of the basis vector
1108 1111 s[b] += (T)((double)coeff[c] * bv[b] + center[b]); //calculate the contribution of each element of the basis vector in the final spectrum
1109 1112 }
1110 1113 }
... ... @@ -1172,7 +1175,7 @@ public:
1172 1175 //read the cropped spectral region
1173 1176 file.read( (char*) temp, L );
1174 1177 //pixel(temp, sp + x + y * X());
1175   - out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
  1178 + out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
1176 1179  
1177 1180 file.seekg(jump_sample, std::ios::cur);
1178 1181  
... ... @@ -1253,7 +1256,7 @@ public:
1253 1256 memset(spec, 0, spec_bytes);
1254 1257 out.write((char*)spec, spec_bytes); //write to the output file
1255 1258 }
1256   - if(PROGRESS) progress = (double)( (y+1) * S[0] + 1) / (double) (S[0] * S[1]) * 100;
  1259 + if(PROGRESS) progress = (double)( (y+1) * S[0] + 1) / (double) (S[0] * S[1]) * 100;
1257 1260 }
1258 1261 }
1259 1262  
... ... @@ -1267,7 +1270,7 @@ public:
1267 1270  
1268 1271 void convolve(std::string outfile, std::vector<double> C, size_t start, size_t end, unsigned char* mask = NULL, bool PROGRESS = false){
1269 1272 std::ofstream out(outfile.c_str(), std::ios::binary); //open the output file for writing
1270   -
  1273 +
1271 1274 size_t N = end - start + 1; //number of bands in the output spectrum
1272 1275 size_t Nb = N * sizeof(T); //size of the output spectrum in bytes
1273 1276 size_t B = Z(); //calculate the number of values in a spectrum
... ... @@ -1297,8 +1300,8 @@ public:
1297 1300  
1298 1301 void deriv(std::string outfile, size_t d, size_t order, const std::vector<double> w, unsigned char* mask = NULL, bool PROGRESS = false){
1299 1302 std::ofstream out(outfile.c_str(), std::ios::binary); //open the output file for writing
1300   -
1301   -
  1303 +
  1304 +
1302 1305 size_t B = Z(); //calculate the number of values in a spectrum
1303 1306 size_t Bb = B * sizeof(T); //calculate the size of a spectrum in bytes
1304 1307  
... ...
stim/envi/bsq.h
... ... @@ -37,6 +37,9 @@ protected:
37 37 using hsi<T>::w; //use the wavelength array in stim::hsi
38 38 using hsi<T>::nnz;
39 39 using binary<T>::progress;
  40 + using hsi<T>::X;
  41 + using hsi<T>::Y;
  42 + using hsi<T>::Z;
40 43  
41 44 public:
42 45  
... ... @@ -55,11 +58,11 @@ public:
55 58 /// @param B is the number of samples (bands) along dimension 3
56 59 /// @param header_offset is the number of bytes (if any) in the binary header
57 60 /// @param wavelengths is an STL vector of size B specifying a numerical label for each band
58   - bool open(std::string filename,
59   - unsigned long long X,
60   - unsigned long long Y,
61   - unsigned long long B,
62   - unsigned long long header_offset,
  61 + bool open(std::string filename,
  62 + unsigned long long X,
  63 + unsigned long long Y,
  64 + unsigned long long B,
  65 + unsigned long long header_offset,
63 66 std::vector<double> wavelengths){
64 67  
65 68 //copy the wavelengths to the BSQ file structure
... ... @@ -366,7 +369,7 @@ public:
366 369 out.write((char*)band, XYb);
367 370 if(PROGRESS) progress = (double) (b+1) / (double)B * 50 + 50;
368 371 }
369   -
  372 +
370 373 }
371 374  
372 375 /// Convert the current BSQ file to a BIL file with the specified file name.
... ... @@ -489,7 +492,7 @@ public:
489 492 }
490 493  
491 494 //find the indices of the left and right baseline points
492   - while (lab >= w[ai]){
  495 + while (lab >= w[ai]){
493 496 ai++;
494 497 }
495 498 while (rab <= w[bi]){
... ... @@ -822,13 +825,13 @@ public:
822 825 i++;
823 826 //std::cout<<i<<std::endl;
824 827 }
825   -
  828 +
826 829 }
827 830 }
828 831  
829 832 return true;
830 833 }
831   -
  834 +
832 835 /// Saves to disk only those spectra corresponding to mask values != 0
833 836 /// @param outfile is the name of the sifted ENVI file to be written to disk
834 837 /// @param unsigned char* p is the mask file used for sifting
... ... @@ -853,7 +856,7 @@ public:
853 856 }
854 857 else{
855 858 continue;
856   - }
  859 + }
857 860 }
858 861 if(PROGRESS) progress = (double)(i+1)/ B * 100;
859 862 }
... ... @@ -973,7 +976,7 @@ public:
973 976 free(temp);
974 977 return true;
975 978 }
976   -
  979 +
977 980 /// Crop a region of the image and save it to a new file.
978 981  
979 982 /// @param outfile is the file name for the new cropped image
... ... @@ -1035,7 +1038,7 @@ public:
1035 1038 /// @param outfile is the file name for the output hyperspectral image (with trimmed bands)
1036 1039 /// @param b is an array of bands to be eliminated
1037 1040 void trim(std::string outfile, std::vector<size_t> band_array, bool PROGRESS = false){
1038   -
  1041 +
1039 1042 std::ofstream out(outfile.c_str(), std::ios::binary); //open the output file for writing
1040 1043 file.seekg(0, std::ios::beg); //move to the beginning of the input file
1041 1044  
... ... @@ -1185,7 +1188,7 @@ public:
1185 1188  
1186 1189 void deriv(std::string outfile, size_t d, size_t order, const std::vector<double> w = std::vector<double>(), unsigned char* mask = NULL, bool PROGRESS = false){
1187 1190 std::ofstream out(outfile.c_str(), std::ios::binary); //open the output file for writing
1188   -
  1191 +
1189 1192 size_t XY = X() * Y(); //calculate the number of values in a band
1190 1193 size_t XYb = XY * sizeof(T); //calculate the size of a band (frame) in bytes
1191 1194 size_t B = Z();
... ... @@ -1227,7 +1230,7 @@ public:
1227 1230 }
1228 1231 }
1229 1232 }
1230   - out.write((char*)outband, XYb); //output the band
  1233 + out.write((char*)outband, XYb); //output the band
1231 1234 if(PROGRESS) progress = (double)(b+1) / (double)B * 100;
1232 1235 }
1233 1236  
... ...
stim/envi/hsi.h
... ... @@ -32,6 +32,9 @@ protected:
32 32  
33 33 std::vector<double> w; //band wavelengths
34 34  
  35 + using binary<T>::R;
  36 + using binary<T>::progress;
  37 +
35 38 unsigned long long X(){ return R[O[0]]; }
36 39 unsigned long long Y(){ return R[O[1]]; }
37 40 unsigned long long Z(){ return R[O[2]]; }
... ... @@ -70,8 +73,8 @@ protected:
70 73 }
71 74  
72 75 /// Get the list of band numbers that bound a list of wavelengths
73   - void band_bounds(std::vector<double> wavelengths,
74   - std::vector<unsigned long long>& low_bands,
  76 + void band_bounds(std::vector<double> wavelengths,
  77 + std::vector<unsigned long long>& low_bands,
75 78 std::vector<unsigned long long>& high_bands){
76 79  
77 80 unsigned long long W = w.size(); //get the number of wavelengths in the list
... ... @@ -92,7 +95,7 @@ protected:
92 95 band_bounds(wavelength, low, high); //get the surrounding band indices
93 96  
94 97 if(high == w.size()) return s[w.size()-1]; //if the high band is above the wavelength range, return the highest wavelength value
95   -
  98 +
96 99 return lerp(wavelength, s[low], w[low], s[high], w[high]);
97 100 }
98 101  
... ... @@ -140,11 +143,11 @@ public:
140 143 size_t XY = X() * Y();
141 144 memset(mask, 255, XY * sizeof(unsigned char)); //initialize the mask to zero (0)
142 145 T* page = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate space for a page of data
143   -
  146 +
144 147 for(size_t p = 0; p < R[2]; p++){ //for each page
145 148 binary<T>::read_page(page, p); //read a page
146 149 for(size_t i = 0; i < R[0] * R[1]; i++){ //for each pixel in that page
147   -
  150 +
148 151 #ifdef _WIN32
149 152 if(!_finite(page[i])){ //if the value at index i is finite
150 153 #else
... ... @@ -171,7 +174,7 @@ public:
171 174 }
172 175  
173 176 /// Calculates the necessary image size required to combine two images given the specified offset (position) of the second image
174   - void calc_combined_size(long long xp, long long yp, long long Sx, long long Sy,
  177 + void calc_combined_size(long long xp, long long yp, long long Sx, long long Sy,
175 178 size_t& Sfx, size_t& Sfy,
176 179 size_t& p0_x, size_t& p0_y,
177 180 size_t& p1_x, size_t& p1_y){
... ... @@ -179,7 +182,7 @@ public:
179 182 calc_combined_size(xp, yp, Sx, Sy, Sfx, Sfy);
180 183  
181 184 p0_x = p0_y = p1_x = p1_y = 0; //initialize all boundary positions to zero
182   -
  185 +
183 186 if(xp < 0) p0_x = -xp; //set the left positions of the current and source image
184 187 else p1_x = xp;
185 188 if(yp < 0) p0_y = -yp;
... ... @@ -191,8 +194,8 @@ public:
191 194  
192 195 size_t w = X(); //calculate the number of pixels in a line
193 196 size_t wb = w * sizeof(T); //calculate the number of bytes in a line
194   - pw = (X() + x0 + x1); //calculate the width of the padded image
195   - pwb = pw * sizeof(T); //calculate the number of bytes in a line of the padded image
  197 + size_t pw = (X() + x0 + x1); //calculate the width of the padded image
  198 + size_t pwb = pw * sizeof(T); //calculate the number of bytes in a line of the padded image
196 199  
197 200 for(size_t y = 0; y < Y(); y++){ //for each line in the real image
198 201 memcpy( &padded[ (y + y0) * pw + x0 ], &src[y * w], wb ); //use memcpy to copy the line to the appropriate place in the padded image
... ...
stim/grids/image_stack.h
... ... @@ -68,7 +68,7 @@ public:
68 68 stim::image<T> I(file_list[i].str());
69 69  
70 70 //retrieve the interlaced data from the image - store it in the grid
71   - I.data_interleaved(&ptr[ i * R[0] * R[1] * R[2] ]);
  71 + I.get_interleaved_rgb(&ptr[ i * R[0] * R[1] * R[2] ]);
72 72  
73 73 }
74 74 }
... ...
stim/image/image.h
... ... @@ -32,7 +32,7 @@ class image{
32 32 void unalloc(){ //frees any resources associated with the image
33 33 if(img) free(img); //if memory has been allocated, free it
34 34 }
35   -
  35 +
36 36  
37 37 void clear(){ //clears all image data
38 38 unalloc(); //unallocate previous memory
... ... @@ -53,7 +53,7 @@ class image{
53 53 size_t idx(size_t x, size_t y, size_t c = 0){
54 54 return y * C() * X() + x * C() + c;
55 55 }
56   -
  56 +
57 57  
58 58 int cv_type(){
59 59 if(std::is_same<T, unsigned char>::value) return CV_MAKETYPE(CV_8U, (int)C());
... ... @@ -63,7 +63,7 @@ class image{
63 63 if(std::is_same<T, int>::value) return CV_MAKETYPE(CV_32S, (int)C());
64 64 if(std::is_same<T, float>::value) return CV_MAKETYPE(CV_32F, (int)C());
65 65 if(std::is_same<T, double>::value) return CV_MAKETYPE(CV_64F, (int)C());
66   -
  66 +
67 67 std::cout<<"ERROR in stim::image::cv_type - no valid data type found"<<std::endl;
68 68 exit(1);
69 69 }
... ... @@ -94,7 +94,7 @@ public:
94 94 }
95 95  
96 96 /// Create a new image from scratch given a number of samples and channels
97   - image(size_t x, size_t y = 1, size_t c = 1){
  97 + image(size_t x, size_t y = 1, size_t c = 1){
98 98 allocate(x, y, c);
99 99 }
100 100  
... ... @@ -148,7 +148,7 @@ public:
148 148 if(C() == 1)
149 149 memcpy(buffer, img, bytes());
150 150 else if(C() == 3)
151   - data_interleaved_bgr(buffer);
  151 + get_interleaved_bgr(buffer);
152 152 cv::Mat cvImage((int)Y(), (int)X(), cv_type(), buffer);
153 153 cv::imwrite(filename, cvImage);
154 154 }
... ... @@ -170,7 +170,7 @@ public:
170 170 }
171 171 }
172 172  
173   - void data_interleaved_bgr(T* data){
  173 + void get_interleaved_bgr(T* data){
174 174  
175 175 //for each channel
176 176 for(size_t y = 0; y < Y(); y++){
... ... @@ -182,6 +182,11 @@ public:
182 182 }
183 183 }
184 184  
  185 + void get_interleaved_rgb(T* data){
  186 + memcpy(data, img, bytes());
  187 + }
  188 +
  189 +
185 190 image<T> channel(size_t c){
186 191  
187 192 //create a new image
... ... @@ -284,7 +289,7 @@ public:
284 289 return s; //return the index list
285 290 }
286 291  
287   -
  292 +
288 293 /// Returns the maximum pixel value in the image
289 294 T maxv(){
290 295 T max_val = img[0]; //initialize the maximum value to the first one
... ... @@ -294,10 +299,10 @@ public:
294 299  
295 300 if (img[n] > max_val){ //if the value is higher than the current max
296 301 max_val = img[n];
297   - }
  302 + }
298 303 }
299 304  
300   - return max;
  305 + return max_val;
301 306 }
302 307  
303 308 /// Returns the maximum pixel value in the image
... ... @@ -308,10 +313,10 @@ public:
308 313 for (size_t n=0; n<N; n++){ //for every value
309 314 if (img[n] < min_val){ //if the value is higher than the current max
310 315 min_val = img[n];
311   - }
  316 + }
312 317 }
313 318  
314   - return max;
  319 + return min_val;
315 320 }
316 321  
317 322 /// Invert an image by calculating I1 = alpha - I0, where alpha is the maximum image value
... ... @@ -320,7 +325,7 @@ public:
320 325 image<T> r(X(), Y(), C()); //allocate space for the resulting image
321 326 for(size_t n = 0; n < N; n++)
322 327 r.img[n] = white_val - img[n]; //perform the inversion
323   -
  328 +
324 329 return r; //return the inverted image
325 330 }
326 331  
... ... @@ -330,7 +335,7 @@ public:
330 335 }
331 336  
332 337 image<T> convolve2(image<T> mask){
333   -
  338 +
334 339 std::cout<<"ERROR stim::image::convolve2 - function has been broken, and shouldn't really be in here."<<std::endl;
335 340 exit(1);
336 341 }
... ... @@ -347,7 +352,7 @@ public:
347 352 std::cout<<"ERROR stim::image::set_interleaved3 - stim::image no longer supports 3D images."<<std::endl;
348 353 exit(1);
349 354 }
350   -
  355 +
351 356 };
352 357  
353 358 }; //end namespace stim
... ...
stim/math/circle.h
... ... @@ -175,5 +175,4 @@ public:
175 175  
176 176 };
177 177 }
178   ->>>>>>> origin/Master_Clone_W_Branch
179 178 #endif
... ...
stim/parser/filename.h
... ... @@ -22,6 +22,9 @@
22 22 #include <iostream>
23 23  
24 24 #include "../parser/parser.h"
  25 +#ifdef BOOST_PRECOMPILED
  26 +#include <boost/filesystem.hpp>
  27 +#endif
25 28 namespace stim{
26 29  
27 30 //filename class designed to work with both Windows and Unix
... ... @@ -234,8 +237,40 @@ public:
234 237 }
235 238 return file_list;
236 239 #else
237   - std::cout<<"File lists aren't currently supported on Unix/Linux systems."<<std::endl;
238   - exit(1);
  240 +
  241 + boost::filesystem::path p(dir()); //create a path from the current filename
  242 + std::vector<stim::filename> file_list;
  243 + if(boost::filesystem::exists(p)){
  244 + if(boost::filesystem::is_directory(p)){
  245 + typedef std::vector<boost::filesystem::path> vec; // store paths,
  246 + vec v; // so we can sort them later
  247 + std::copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(v));
  248 + std::sort(v.begin(), v.end()); // sort, since directory iteration
  249 + // is not ordered on some file systems
  250 + //compare file names to the current template (look for wild cards)
  251 + for (vec::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it)
  252 + {
  253 + //if the filename is a wild card *or* it matches the read file name
  254 + if( prefix == "*" || prefix == (*it).filename().stem().string()){
  255 + //if the extension is a wild card *or* it matches the read file extension
  256 + if( ext == "*" || "." + ext == (*it).filename().extension().string()){
  257 + file_list.push_back((*it).string()); //include it in the final list
  258 + }
  259 +
  260 + }
  261 +
  262 +
  263 +
  264 + }
  265 +
  266 + }
  267 +
  268 + }
  269 + return file_list;
  270 +
  271 +
  272 +// std::cout<<"File lists aren't currently supported on Unix/Linux systems."<<std::endl;
  273 +// exit(1);
239 274 #endif
240 275 }
241 276 //**************************************************************************************************
... ...
stim/visualization/cylinder.h
... ... @@ -164,7 +164,7 @@ class cylinder
164 164 ///Returns the number of points on the cylinder centerline
165 165  
166 166 unsigned int size(){
167   - return pos.size();
  167 + return e.size();
168 168 }
169 169  
170 170  
... ... @@ -231,7 +231,7 @@ class cylinder
231 231 /// Adds a new magnitude value to all points
232 232 /// @param m is the starting value for the new magnitude
233 233 void add_mag(T m = 0){
234   - for(unsigned int p = 0; p < pos.size(); p++)
  234 + for(unsigned int p = 0; p < e.size(); p++)
235 235 mags[p].push_back(m);
236 236 }
237 237  
... ... @@ -317,7 +317,7 @@ class cylinder
317 317 T len = L[0]; //allocate space for the segment length
318 318  
319 319 //for every consecutive point in the cylinder
320   - for(unsigned p = 1; p < pos.size(); p++){
  320 + for(unsigned p = 1; p < e.size(); p++){
321 321  
322 322 //p1 = pos[p]; //get the position and magnitude for the next point
323 323 m1 = mags[p][m];
... ... @@ -347,7 +347,7 @@ class cylinder
347 347  
348 348 std::vector< vec<T> > result;
349 349  
350   - vec<T> p0 = e[i].P; //initialize p0 to the first point on the centerline
  350 + vec<T> p0 = e[0].P; //initialize p0 to the first point on the centerline
351 351 vec<T> p1;
352 352 unsigned N = size(); //number of points in the current centerline
353 353  
... ...
stim/visualization/obj.h
... ... @@ -158,6 +158,7 @@ protected:
158 158 using std::vector<triplet>::size;
159 159 using std::vector<triplet>::at;
160 160 using std::vector<triplet>::push_back;
  161 + using std::vector<triplet>::resize;
161 162  
162 163 geometry(){}
163 164  
... ...