From 48081b3b6dd2a1e350ee011966e0bdb2177098c2 Mon Sep 17 00:00:00 2001 From: Sebastian Berisha Date: Thu, 23 Feb 2017 16:15:35 -0600 Subject: [PATCH] fixed the culling and depth test issues in the gl_spharmonics.h as well as syntax errors in both gl and spharmonics.h --- stim/math/spharmonics.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- stim/visualization/gl_spharmonics.h | 17 ++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/stim/math/spharmonics.h b/stim/math/spharmonics.h index a2fc711..43594aa 100644 --- a/stim/math/spharmonics.h +++ b/stim/math/spharmonics.h @@ -181,7 +181,7 @@ namespace stim { /// @param n is the number of points of the surface of the sphere used to create the PDF. DEFAULT 1000 /// @param norm, a boolean that sets where the output vectors will be normalized between 0 and 1. /// @param - /*void pdf(std::vector > sph_pts, unsigned int l, int m, stim::vec3 c = stim::vec3(0, 0, 0), unsigned int n = 1000, bool norm = true, std::vector w = std::vector()) + void pdf(std::vector > sph_pts, unsigned int l, int m, stim::vec3 c = stim::vec3(0, 0, 0), unsigned int n = 1000, bool norm = true, std::vector w = std::vector()) { std::vector weights; ///the weight at each point on the surface of the sphere. // weights.resize(n); @@ -223,7 +223,7 @@ namespace stim { } } mcEnd(); - }*/ + } std::string str() { @@ -313,6 +313,52 @@ namespace stim { T operator()(T theta, T phi) { return p(theta, phi); } + + //overload arithmetic operations + + spharmonics operator*(T rhs) const { + + spharmonics result(C.size()); //create a new spherical harmonics object + + for (size_t c = 0; c < C.size(); c++) //for each coefficient + + result.C[c] = C[c] * rhs; //calculate the factor and store the result in the new spharmonics object + + return result; + + } + + + + spharmonics operator+(spharmonics rhs) { + + size_t low = std::min(C.size(), rhs.C.size()); //store the number of coefficients in the lowest object + size_t high = std::max(C.size(), rhs.C.size()); //store the number of coefficients in the result + bool rhs_lowest = false; //true if rhs has the lowest number of coefficients + if (rhs.C.size() < C.size()) rhs_lowest = true; //if rhs has a lower number of coefficients, set the flag + + + + spharmonics result(high); //create a new object + + size_t c; + for (c = 0; c < low; c++) //perform the first batch of additions + result.C[c] = C[c] + rhs.C[c]; //perform the addition + + for (c = low; c < high; c++) { + if (rhs_lowest) + result.C[c] = C[c]; + else + result.C[c] = rhs.C[c]; + } + return result; + } + + + + spharmonics operator-(spharmonics rhs) { + return (*this) + (rhs * (T)(-1)); + } /// Fill an NxN grid with the spherical function for theta = [0 2pi] and phi = [0 pi] void get_func(T* data, size_t X, size_t Y) { T dt = stim::TAU / (T)X; //calculate the step size in each direction @@ -351,4 +397,4 @@ namespace stim { } -#endif \ No newline at end of file +#endif diff --git a/stim/visualization/gl_spharmonics.h b/stim/visualization/gl_spharmonics.h index 9882325..3d3b767 100644 --- a/stim/visualization/gl_spharmonics.h +++ b/stim/visualization/gl_spharmonics.h @@ -51,6 +51,13 @@ namespace stim { magnitude = true; } + gl_spharmonics(stim::spharmonics disp, stim::spharmonics color, size_t slices) : + gl_spharmonics(slices) + { + Sc = color; + Sd = disp; + } + ~gl_spharmonics() { if (dlist) glDeleteLists(dlist, 1); //delete the display list when the object is destroyed } @@ -60,6 +67,8 @@ namespace stim { //glShadeModel(GL_FLAT); glPushAttrib(GL_ENABLE_BIT); glDisable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); if (!tex) { init_tex(); @@ -140,6 +149,8 @@ namespace stim { glCallList(dlist); //call the display list to render glPopAttrib(); + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); } /// 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 { } /// Project a set of samples onto the basis - void project(std::vector>& vlist, size_t nc) { + void project(std::vector >& vlist, size_t nc) { Sd.project(vlist, nc); Sc = Sd; } /// Calculate a density function from a list of points in spherical coordinates - void pdf(std::vector>& vlist, size_t nc) { + void pdf(std::vector >& vlist, size_t nc) { Sd.pdf(vlist, nc); Sc = Sd; } @@ -196,4 +207,4 @@ namespace stim { -#endif \ No newline at end of file +#endif -- libgit2 0.21.4