Commit 629c754ef9d0a0200e4cc5bd4ea51e3236665358

Authored by David Mayerich
2 parents a11c7efe 48081b3b

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

stim/math/spharmonics.h
... ... @@ -181,7 +181,7 @@ namespace stim {
181 181 /// @param n is the number of points of the surface of the sphere used to create the PDF. DEFAULT 1000
182 182 /// @param norm, a boolean that sets where the output vectors will be normalized between 0 and 1.
183 183 /// @param
184   - /*void pdf(std::vector<stim::vec3<T> > sph_pts, unsigned int l, int m, stim::vec3<T> c = stim::vec3<T>(0, 0, 0), unsigned int n = 1000, bool norm = true, std::vector<T> w = std::vector<T>())
  184 + void pdf(std::vector<stim::vec3<T> > sph_pts, unsigned int l, int m, stim::vec3<T> c = stim::vec3<T>(0, 0, 0), unsigned int n = 1000, bool norm = true, std::vector<T> w = std::vector<T>())
185 185 {
186 186 std::vector<double> weights; ///the weight at each point on the surface of the sphere.
187 187 // weights.resize(n);
... ... @@ -223,7 +223,7 @@ namespace stim {
223 223 }
224 224 }
225 225 mcEnd();
226   - }*/
  226 + }
227 227  
228 228 std::string str() {
229 229  
... ... @@ -313,6 +313,52 @@ namespace stim {
313 313 T operator()(T theta, T phi) {
314 314 return p(theta, phi);
315 315 }
  316 +
  317 + //overload arithmetic operations
  318 +
  319 + spharmonics<T> operator*(T rhs) const {
  320 +
  321 + spharmonics<T> result(C.size()); //create a new spherical harmonics object
  322 +
  323 + for (size_t c = 0; c < C.size(); c++) //for each coefficient
  324 +
  325 + result.C[c] = C[c] * rhs; //calculate the factor and store the result in the new spharmonics object
  326 +
  327 + return result;
  328 +
  329 + }
  330 +
  331 +
  332 +
  333 + spharmonics<T> operator+(spharmonics<T> rhs) {
  334 +
  335 + size_t low = std::min(C.size(), rhs.C.size()); //store the number of coefficients in the lowest object
  336 + size_t high = std::max(C.size(), rhs.C.size()); //store the number of coefficients in the result
  337 + bool rhs_lowest = false; //true if rhs has the lowest number of coefficients
  338 + if (rhs.C.size() < C.size()) rhs_lowest = true; //if rhs has a lower number of coefficients, set the flag
  339 +
  340 +
  341 +
  342 + spharmonics<T> result(high); //create a new object
  343 +
  344 + size_t c;
  345 + for (c = 0; c < low; c++) //perform the first batch of additions
  346 + result.C[c] = C[c] + rhs.C[c]; //perform the addition
  347 +
  348 + for (c = low; c < high; c++) {
  349 + if (rhs_lowest)
  350 + result.C[c] = C[c];
  351 + else
  352 + result.C[c] = rhs.C[c];
  353 + }
  354 + return result;
  355 + }
  356 +
  357 +
  358 +
  359 + spharmonics<T> operator-(spharmonics<T> rhs) {
  360 + return (*this) + (rhs * (T)(-1));
  361 + }
316 362 /// Fill an NxN grid with the spherical function for theta = [0 2pi] and phi = [0 pi]
317 363 void get_func(T* data, size_t X, size_t Y) {
318 364 T dt = stim::TAU / (T)X; //calculate the step size in each direction
... ... @@ -351,4 +397,4 @@ namespace stim {
351 397 }
352 398  
353 399  
354   -#endif
355 400 \ No newline at end of file
  401 +#endif
... ...
stim/visualization/gl_spharmonics.h
... ... @@ -51,6 +51,13 @@ namespace stim {
51 51 magnitude = true;
52 52 }
53 53  
  54 + gl_spharmonics(stim::spharmonics<T> disp, stim::spharmonics<T> color, size_t slices) :
  55 + gl_spharmonics<T>(slices)
  56 + {
  57 + Sc = color;
  58 + Sd = disp;
  59 + }
  60 +
54 61 ~gl_spharmonics() {
55 62 if (dlist) glDeleteLists(dlist, 1); //delete the display list when the object is destroyed
56 63 }
... ... @@ -60,6 +67,8 @@ namespace stim {
60 67 //glShadeModel(GL_FLAT);
61 68 glPushAttrib(GL_ENABLE_BIT);
62 69 glDisable(GL_CULL_FACE);
  70 + glEnable(GL_DEPTH_TEST);
  71 + glDepthMask(GL_TRUE);
63 72  
64 73 if (!tex) {
65 74 init_tex();
... ... @@ -140,6 +149,8 @@ namespace stim {
140 149 glCallList(dlist); //call the display list to render
141 150  
142 151 glPopAttrib();
  152 + glDisable(GL_DEPTH_TEST);
  153 + glDepthMask(GL_FALSE);
143 154 }
144 155  
145 156 /// Push a coefficient to the spherical harmonic - by default, push applies the component to both the displacement and color SH
... ... @@ -166,13 +177,13 @@ namespace stim {
166 177 }
167 178  
168 179 /// Project a set of samples onto the basis
169   - void project(std::vector<vec3<float>>& vlist, size_t nc) {
  180 + void project(std::vector<vec3<float> >& vlist, size_t nc) {
170 181 Sd.project(vlist, nc);
171 182 Sc = Sd;
172 183 }
173 184  
174 185 /// Calculate a density function from a list of points in spherical coordinates
175   - void pdf(std::vector<stim::vec3<T>>& vlist, size_t nc) {
  186 + void pdf(std::vector<stim::vec3<T> >& vlist, size_t nc) {
176 187 Sd.pdf(vlist, nc);
177 188 Sc = Sd;
178 189 }
... ... @@ -196,4 +207,4 @@ namespace stim {
196 207  
197 208  
198 209  
199   -#endif
200 210 \ No newline at end of file
  211 +#endif
... ...