Commit 761ebaa936cf81f314fb51047ff84e6a60fffeaf

Authored by David Mayerich
1 parent 18f207ce

spherical harmonics arithmetic

stim/math/constants.h
... ... @@ -4,7 +4,6 @@
4 4 #define STIM_PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862
5 5 #define STIM_TAU 2 * STIM_PI
6 6  
7   -#include "stim/cuda/cudatools/callable.h"
8 7 namespace stim{
9 8 const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862;
10 9 const double TAU = 2 * stim::PI;
... ...
stim/math/spharmonics.h
... ... @@ -5,7 +5,6 @@
5 5 #include <boost/math/special_functions/spherical_harmonic.hpp>
6 6 #include <vector>
7 7  
8   -#define PI 3.14159
9 8 #define WIRE_SCALE 1.001
10 9 namespace stim{
11 10  
... ... @@ -32,6 +31,12 @@ protected:
32 31  
33 32  
34 33 public:
  34 + spharmonics() {
  35 + mcN = 0;
  36 + }
  37 + spharmonics(size_t c) : spharmonics() {
  38 + resize(c);
  39 + }
35 40  
36 41 void push(double c){
37 42 C.push_back(c);
... ... @@ -163,6 +168,38 @@ public:
163 168 return fx;
164 169 }
165 170  
  171 + //overload arithmetic operations
  172 + spharmonics<T> operator*(T rhs) const {
  173 + spharmonics<T> result(C.size()); //create a new spherical harmonics object
  174 + for (size_t c = 0; c < C.size(); c++) //for each coefficient
  175 + result.C[c] = C[c] * rhs; //calculate the factor and store the result in the new spharmonics object
  176 + return result;
  177 + }
  178 +
  179 + spharmonics<T> operator+(spharmonics<T> rhs) {
  180 + size_t low = std::min(C.size(), rhs.C.size()); //store the number of coefficients in the lowest object
  181 + size_t high = std::max(C.size(), rhs.C.size()); //store the number of coefficients in the result
  182 + bool rhs_lowest = false; //true if rhs has the lowest number of coefficients
  183 + if (rhs.C.size() < C.size()) rhs_lowest = true; //if rhs has a lower number of coefficients, set the flag
  184 +
  185 + spharmonics<T> result(high); //create a new object
  186 + size_t c;
  187 + for (c = 0; c < low; c++) //perform the first batch of additions
  188 + result.C[c] = C[c] + rhs.C[c]; //perform the addition
  189 +
  190 + for (c = low; c < high; c++) {
  191 + if (rhs_lowest)
  192 + result.C[c] = C[c];
  193 + else
  194 + result.C[c] = rhs.C[c];
  195 + }
  196 + return result;
  197 + }
  198 +
  199 + spharmonics<T> operator-(spharmonics<T> rhs) {
  200 + return (*this) + (rhs * (T)(-1));
  201 + }
  202 +
166 203 }; //end class sph_harmonics
167 204  
168 205  
... ...
stim/visualization/gl_spharmonics.h
... ... @@ -163,6 +163,19 @@ protected:
163 163 }
164 164  
165 165 public:
  166 + gl_spharmonics<T>() {
  167 +
  168 + }
  169 +
  170 + gl_spharmonics<T>(const spharmonics<T> copy) : gl_spharmonics<T>() {
  171 + C = copy.C;
  172 + }
  173 +
  174 + gl_spharmonics<T>& operator=(const spharmonics<T> rhs) {
  175 + gl_spharmonics<T> result(rhs.C.size());
  176 + result.C = spharmonics<T>::rhs.C;
  177 + return result;
  178 + }
166 179  
167 180 void glRender(){
168 181 //set all OpenGL parameters required for drawing
... ... @@ -177,7 +190,6 @@ public:
177 190 gen_function();
178 191 }
179 192  
180   -
181 193 }; //end gl_spharmonics
182 194  
183 195  
... ...