Commit 5d42469a7e606e120e67d7e91aa2a85fce8564ea

Authored by Jiaming Guo
2 parents eceb6571 e702aa4e

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

stim/cuda/templates/conv2sep.cuh
... ... @@ -8,8 +8,6 @@
8 8 #include <stim/cuda/sharedmem.cuh>
9 9 #include <stim/cuda/cudatools/error.h>
10 10  
11   -#define pi 3.14159
12   -
13 11 namespace stim{
14 12 namespace cuda{
15 13  
... ...
stim/envi/agilent_binary.h
... ... @@ -125,7 +125,7 @@ public:
125 125 infile.read((char*)ptr, bytes()); //read the data
126 126 infile.close();
127 127 Z[0] = 1;
128   - Z[1] = R[2];
  128 + Z[1] = (double)R[2];
129 129 }
130 130  
131 131 void save(std::string filename){
... ...
stim/image/image.h
... ... @@ -480,7 +480,6 @@ public:
480 480 max_val = img[n];
481 481 }
482 482 }
483   -
484 483 return max_val;
485 484 }
486 485  
... ... @@ -508,6 +507,33 @@ public:
508 507 return r; //return the inverted image
509 508 }
510 509  
  510 + image<T> crop(size_t x0, size_t y0, size_t w, size_t h){
  511 + image<T> result(w, h, C()); //create the output cropped image
  512 +
  513 + size_t srci;
  514 + size_t dsti;
  515 + size_t line_bytes = w * C(); //calculate the number of bytes in a line
  516 + for (size_t yi = 0; yi < h; yi++) { //for each row in the cropped image
  517 + srci = (y0 + yi) * X() * C() + x0 * C(); //calculate the source index
  518 + dsti = yi * w * C(); //calculate the destination index
  519 + memcpy(&result.img[dsti], &img[srci], line_bytes); //copy the data
  520 + }
  521 + return result;
  522 + }
  523 +
  524 + //crop regions given by an array of 1D index values
  525 + std::vector<image<T>> crop_idx(size_t w, size_t h, std::vector<size_t> idx) {
  526 + std::vector<image<T>> result(idx.size()); //create an array of image files to return
  527 + for (size_t i = 0; i < idx.size(); i++) { //for each specified index point
  528 + size_t y = idx[i] / X(); //calculate the y coordinate from the 1D index (center of ROI)
  529 + size_t x = idx[i] - y * X(); //calculate the x coordinate (center of ROI)
  530 + y -= w / 2; //update x and y values to reflect the lower corner of the ROI
  531 + x -= h / 2;
  532 + result[i] = crop(x, y, w, h); //get the cropped image and store it in the result array
  533 + }
  534 + return result;
  535 + }
  536 +
511 537 image<T> srgb2lab(){
512 538 std::cout<<"ERROR stim::image::srgb2lab - function has been broken, re-implement."<<std::endl;
513 539 exit(1);
... ...
stim/math/spharmonics.h
... ... @@ -25,8 +25,20 @@ protected:
25 25 //calculate the value of the SH basis function (l, m) at (theta, phi)
26 26 //here, theta = [0, PI], phi = [0, 2*PI]
27 27 double SH(int l, int m, double theta, double phi){
28   - std::complex<T> result = boost::math::spherical_harmonic(l, m, phi, theta);
29   - return result.imag() + result.real();
  28 + //std::complex<T> result = boost::math::spherical_harmonic(l, m, phi, theta);
  29 + //return result.imag() + result.real();
  30 +
  31 + //this calculation is based on calculating the real spherical harmonics:
  32 + // https://en.wikipedia.org/wiki/Spherical_harmonics#Addition_theorem
  33 + if (m < 0) {
  34 + return sqrt(2.0) * pow(-1, m) * boost::math::spherical_harmonic(l, abs(m), phi, theta).imag();
  35 + }
  36 + else if (m == 0) {
  37 + return boost::math::spherical_harmonic(l, m, phi, theta).real();
  38 + }
  39 + else {
  40 + return sqrt(2.0) * pow(-1, m) * boost::math::spherical_harmonic(l, m, phi, theta).real();
  41 + }
30 42 }
31 43  
32 44 unsigned int coeff_1d(unsigned int l, int m){
... ...