From 3520bd121edca79fc0c27afa60975c70424fa064 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 11 May 2014 18:34:57 +0200 Subject: [PATCH] Renamed pss to PowerScaledScalar --- .../externalcontrol/externalcontrol.h | 2 +- .../interaction/interactionhandler.h | 2 +- include/openspace/rendering/renderable.h | 6 +- include/openspace/scenegraph/scenegraphnode.h | 6 +- include/openspace/util/planet.h | 2 +- .../openspace/util/powerscaledcoordinate.h | 10 +- include/openspace/util/powerscaledscalar.h | 87 +++---- include/openspace/util/powerscaledsphere.h | 2 +- .../externalcontrol/externalcontrol.cpp | 2 +- src/interaction/interactionhandler.cpp | 12 +- src/rendering/planets/renderableplanet.cpp | 4 +- .../planets/simplespheregeometry.cpp | 2 +- src/rendering/renderable.cpp | 4 +- src/rendering/renderablevolumeexpert.cpp | 2 +- src/rendering/renderengine.cpp | 2 +- src/scenegraph/scenegraph.cpp | 4 +- src/scenegraph/scenegraphnode.cpp | 10 +- src/util/planet.cpp | 2 +- src/util/powerscaledcoordinate.cpp | 18 +- src/util/powerscaledscalar.cpp | 224 +++++++----------- src/util/powerscaledsphere.cpp | 2 +- 21 files changed, 165 insertions(+), 240 deletions(-) diff --git a/include/openspace/interaction/externalcontrol/externalcontrol.h b/include/openspace/interaction/externalcontrol/externalcontrol.h index cb02c2b401..b267880d9d 100644 --- a/include/openspace/interaction/externalcontrol/externalcontrol.h +++ b/include/openspace/interaction/externalcontrol/externalcontrol.h @@ -18,7 +18,7 @@ public: void rotate(const glm::quat &rotation); void orbit(const glm::quat &rotation); - void distance(const pss &distance); + void distance(const PowerScaledScalar &distance); protected: diff --git a/include/openspace/interaction/interactionhandler.h b/include/openspace/interaction/interactionhandler.h index 0428055595..b8505beda2 100644 --- a/include/openspace/interaction/interactionhandler.h +++ b/include/openspace/interaction/interactionhandler.h @@ -43,7 +43,7 @@ public: void orbit(const glm::quat &rotation); void rotate(const glm::quat &rotation); - void distance(const pss &distance); + void distance(const PowerScaledScalar &distance); void lookAt(const glm::quat &rotation); void setRotation(const glm::quat &rotation); diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index ee15c4c1a4..2ff4bda48a 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -45,8 +45,8 @@ public: virtual bool initialize() = 0; virtual bool deinitialize() = 0; - void setBoundingSphere(const pss& boundingSphere); - const pss& getBoundingSphere(); + void setBoundingSphere(const PowerScaledScalar& boundingSphere); + const PowerScaledScalar& getBoundingSphere(); virtual void render(const Camera* camera, const psc& thisPosition) = 0; virtual void update(); @@ -54,7 +54,7 @@ public: protected: // Renderable(); private: - pss boundingSphere_; + PowerScaledScalar boundingSphere_; }; } // namespace openspace diff --git a/include/openspace/scenegraph/scenegraphnode.h b/include/openspace/scenegraph/scenegraphnode.h index aefd6fbb65..2269d7d7cf 100644 --- a/include/openspace/scenegraph/scenegraphnode.h +++ b/include/openspace/scenegraph/scenegraphnode.h @@ -69,7 +69,7 @@ public: const std::vector& children() const; // bounding sphere - pss calculateBoundingSphere(); + PowerScaledScalar calculateBoundingSphere(); SceneGraphNode* get(const std::string& name); @@ -92,10 +92,10 @@ private: // bounding sphere bool _boundingSphereVisible; - pss _boundingSphere; + PowerScaledScalar _boundingSphere; // private helper methods - bool sphereInsideFrustum(const psc s_pos, const pss& s_rad, const Camera* camera); + bool sphereInsideFrustum(const psc s_pos, const PowerScaledScalar& s_rad, const Camera* camera); }; } // namespace openspace diff --git a/include/openspace/util/planet.h b/include/openspace/util/planet.h index 4d5cdad100..0fac365ef6 100644 --- a/include/openspace/util/planet.h +++ b/include/openspace/util/planet.h @@ -32,7 +32,7 @@ class Planet { public: //initializers - Planet(pss radius, int levels = 4); + Planet(PowerScaledScalar radius, int levels = 4); ~Planet(); void setHeightMap(const std::string &path); diff --git a/include/openspace/util/powerscaledcoordinate.h b/include/openspace/util/powerscaledcoordinate.h index 19c2dd1b8d..e6396941a5 100644 --- a/include/openspace/util/powerscaledcoordinate.h +++ b/include/openspace/util/powerscaledcoordinate.h @@ -36,7 +36,7 @@ namespace openspace { // forward declare the power scaled scalars -class pss; +class PowerScaledScalar; class PowerScaledCoordinate { public: @@ -60,7 +60,7 @@ public: // returns the rescaled, "normal" coordinates glm::vec3 vec3() const; // length of the vector as a pss - pss length() const; + PowerScaledScalar length() const; glm::vec3 direction() const; // operator overloading @@ -78,8 +78,8 @@ public: // scalar operators PowerScaledCoordinate operator*(const double& rhs) const; PowerScaledCoordinate operator*(const float& rhs) const; - PowerScaledCoordinate& operator*=(const pss& rhs); - PowerScaledCoordinate operator*(const pss& rhs) const; + PowerScaledCoordinate& operator*=(const PowerScaledScalar& rhs); + PowerScaledCoordinate operator*(const PowerScaledScalar& rhs) const; PowerScaledCoordinate operator*(const glm::mat4& matrix) const; @@ -100,7 +100,7 @@ public: friend std::ostream& operator<<(std::ostream& os, const PowerScaledCoordinate& rhs); // allow the power scaled scalars to access private members - friend class pss; + friend class PowerScaledScalar; private: // internal glm vector diff --git a/include/openspace/util/powerscaledscalar.h b/include/openspace/util/powerscaledscalar.h index 60810d922a..b5ae52e575 100644 --- a/include/openspace/util/powerscaledscalar.h +++ b/include/openspace/util/powerscaledscalar.h @@ -34,76 +34,59 @@ namespace openspace { -class pss { +class PowerScaledScalar { public: // constructors - pss(); - pss(const glm::vec2 &v); - pss(const glm::dvec2 &v); - pss(const float &f1,const float &f2); - pss(const double &d1,const double &d2); - static pss CreatePSS(double d1); + PowerScaledScalar(); + PowerScaledScalar(const glm::vec2 &v); + PowerScaledScalar(float f1, float f2); + static PowerScaledScalar CreatePSS(double d1); - // print n' debug - void print() const; - void print(const char *name) const; - - // get functions - const double * value_ptr(); - const float * value_ptrf(); - glm::dvec2 getVec2() const; - glm::vec2 getVec2f() const; - double length() const; + const glm::vec2& vec2() const; float lengthf() const; // operator overloading - pss & operator=(const pss &rhs); - pss & operator+=(const pss &rhs); - const pss operator+(const pss &rhs) const; - pss & operator-=(const pss &rhs); - const pss operator-(const pss &rhs) const; - pss & operator*=(const pss &rhs); - const pss operator*(const pss &rhs) const; - pss & operator*=(const double &rhs); - const pss operator*(const double &rhs) const; - pss & operator*=(const float &rhs); - const pss operator*(const float &rhs) const; - double& operator[](unsigned int idx); - const double& operator[](unsigned int idx) const; + PowerScaledScalar& operator=(const PowerScaledScalar& rhs); + PowerScaledScalar& operator+=(const PowerScaledScalar& rhs); + const PowerScaledScalar operator+(const PowerScaledScalar& rhs) const; + PowerScaledScalar& operator-=(const PowerScaledScalar& rhs); + const PowerScaledScalar operator-(const PowerScaledScalar& rhs) const; + PowerScaledScalar& operator*=(const PowerScaledScalar& rhs); + const PowerScaledScalar operator*(const PowerScaledScalar& rhs) const; + PowerScaledScalar& operator*=(const float& rhs); + const PowerScaledScalar operator*(const float& rhs) const; + float& operator[](unsigned int idx); + float operator[](unsigned int idx) const; - // comparasion - bool operator==(const pss &other) const; - bool operator<(const pss &other) const; - bool operator>(const pss &other) const; - bool operator<=(const pss &other) const; - bool operator>=(const pss &other) const; + // comparison + bool operator==(const PowerScaledScalar& other) const; + bool operator<(const PowerScaledScalar& other) const; + bool operator>(const PowerScaledScalar& other) const; + bool operator<=(const PowerScaledScalar& other) const; + bool operator>=(const PowerScaledScalar& other) const; - bool operator==(const double &other) const; - bool operator<(const double &other) const; - bool operator>(const double &other) const; - bool operator<=(const double &other) const; - bool operator>=(const double &other) const; + bool operator==(double other) const; + bool operator<(double other) const; + bool operator>(double other) const; + bool operator<=(double other) const; + bool operator>=(double other) const; // glm integration - pss & operator=(const glm::vec2 &rhs); - pss & operator=(const float &rhs); - pss & operator=(const glm::dvec2 &rhs); - pss & operator=(const double &rhs); + PowerScaledScalar& operator=(const glm::vec2& rhs); + PowerScaledScalar& operator=(float rhs); - friend std::ostream& operator<<(::std::ostream& os, const pss& rhs); + friend std::ostream& operator<<(std::ostream& os, const PowerScaledScalar& rhs); - // allow the power scaled coordinates to acces private members + // allow the power scaled coordinates to access private members friend class PowerScaledCoordinate; private: - - // internal glm vector - glm::dvec2 vec_; - // float vector used when returning float values - mutable glm::vec2 vecf_; + glm::vec2 _data; }; +typedef PowerScaledScalar pss; + } // namespace openspace diff --git a/include/openspace/util/powerscaledsphere.h b/include/openspace/util/powerscaledsphere.h index 307ee3f159..11fb8aa315 100644 --- a/include/openspace/util/powerscaledsphere.h +++ b/include/openspace/util/powerscaledsphere.h @@ -36,7 +36,7 @@ namespace openspace { class PowerScaledSphere { public: // initializers - PowerScaledSphere(const pss& radius, int segments = 8); + PowerScaledSphere(const PowerScaledScalar& radius, int segments = 8); ~PowerScaledSphere(); bool initialize(); diff --git a/src/interaction/externalcontrol/externalcontrol.cpp b/src/interaction/externalcontrol/externalcontrol.cpp index 81d0ec89b7..ff37ffd055 100644 --- a/src/interaction/externalcontrol/externalcontrol.cpp +++ b/src/interaction/externalcontrol/externalcontrol.cpp @@ -24,7 +24,7 @@ void ExternalControl::orbit(const glm::quat &rotation) { OsEng.interactionHandler().orbit(rotation); } -void ExternalControl::distance(const pss &distance) { +void ExternalControl::distance(const PowerScaledScalar &distance) { OsEng.interactionHandler().distance(distance); } diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 8e31d3dc92..b9a18a634e 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -168,7 +168,7 @@ void InteractionHandler::orbit(const glm::quat &rotation) { unlockControls(); } -void InteractionHandler::distance(const pss &distance) { +void InteractionHandler::distance(const PowerScaledScalar &distance) { //assert(this_); lockControls(); @@ -179,7 +179,7 @@ void InteractionHandler::distance(const pss &distance) { } psc relative_origin_coordinate = relative - origin; - glm::dvec3 dir(relative_origin_coordinate.direction()); + glm::vec3 dir(relative_origin_coordinate.direction()); dir = dir * distance[0]; relative_origin_coordinate = dir; relative_origin_coordinate[3] = distance[1]; @@ -344,19 +344,19 @@ void InteractionHandler::keyboardCallback(int key, int action) { rotate(rot); } if (key == 'R') { - pss dist(-speed * dt, 0.0); + PowerScaledScalar dist(-speed * dt, 0.0); distance(dist); } if (key == 'F') { - pss dist(speed * dt, 0.0); + PowerScaledScalar dist(speed * dt, 0.0); distance(dist); } if (key == 'T') { - pss dist(-speed * 100.0 * dt, 0.0); + PowerScaledScalar dist(-speed * 100.0 * dt, 0.0); distance(dist); } if (key == 'G') { - pss dist(speed * 100.0 * dt, 0.0); + PowerScaledScalar dist(speed * 100.0 * dt, 0.0); distance(dist); } /* diff --git a/src/rendering/planets/renderableplanet.cpp b/src/rendering/planets/renderableplanet.cpp index ac9954c83c..79c08236bd 100644 --- a/src/rendering/planets/renderableplanet.cpp +++ b/src/rendering/planets/renderableplanet.cpp @@ -119,7 +119,7 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition) psc currentPosition = thisPosition; psc campos = camera->position(); glm::mat4 camrot = camera->viewRotationMatrix(); - pss scaling = camera->scaling(); + PowerScaledScalar scaling = camera->scaling(); // scale the planet to appropriate size since the planet is a unit sphere glm::mat4 transform = glm::mat4(1); @@ -133,7 +133,7 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition) _programObject->setUniform("campos", campos.vec4()); _programObject->setUniform("objpos", currentPosition.vec4()); _programObject->setUniform("camrot", camrot); - _programObject->setUniform("scaling", scaling.getVec2f()); + _programObject->setUniform("scaling", scaling.vec2()); // Bind texture ghoul::opengl::TextureUnit unit; diff --git a/src/rendering/planets/simplespheregeometry.cpp b/src/rendering/planets/simplespheregeometry.cpp index 3bfcf91815..5c544d49fd 100644 --- a/src/rendering/planets/simplespheregeometry.cpp +++ b/src/rendering/planets/simplespheregeometry.cpp @@ -107,7 +107,7 @@ void SimpleSphereGeometry::createSphere() { //create the power scaled scalar - pss planetSize(_radius); + PowerScaledScalar planetSize(_radius); _parent->setBoundingSphere(planetSize); delete _planet; diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index f0c8cf2a99..9a432b02d7 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -69,12 +69,12 @@ Renderable::~Renderable() { } -void Renderable::setBoundingSphere(const pss& boundingSphere) +void Renderable::setBoundingSphere(const PowerScaledScalar& boundingSphere) { boundingSphere_ = boundingSphere; } -const pss& Renderable::getBoundingSphere() +const PowerScaledScalar& Renderable::getBoundingSphere() { return boundingSphere_; } diff --git a/src/rendering/renderablevolumeexpert.cpp b/src/rendering/renderablevolumeexpert.cpp index 3beefb4f39..c3f268ae4a 100644 --- a/src/rendering/renderablevolumeexpert.cpp +++ b/src/rendering/renderablevolumeexpert.cpp @@ -210,7 +210,7 @@ RenderableVolumeExpert::RenderableVolumeExpert(const ghoul::Dictionary& dictiona } } - setBoundingSphere(pss::CreatePSS(_boxScaling.length())); + setBoundingSphere(PowerScaledScalar::CreatePSS(_boxScaling.length())); } RenderableVolumeExpert::~RenderableVolumeExpert() { diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index e10e2eaece..86691afd84 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -178,7 +178,7 @@ void RenderEngine::render() const glm::vec3 viewdirection = _mainCamera->viewDirection(); const psc position = _mainCamera->position(); const psc origin = OsEng.interactionHandler().getOrigin(); - const pss pssl = (position - origin).length(); + const PowerScaledScalar pssl = (position - origin).length(); Freetype::print( sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE), diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index 64c0137886..17a55e4158 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -177,10 +177,10 @@ bool SceneGraph::initialize() // TODO: Set distance and camera direction in some more smart way // TODO: Set scaling dependent on the position and distance // set position for camera - const pss bound = positionNode->calculateBoundingSphere(); + const PowerScaledScalar bound = positionNode->calculateBoundingSphere(); // this part is full of magic! - glm::vec2 boundf = bound.getVec2f(); + glm::vec2 boundf = bound.vec2(); glm::vec2 scaling{1.0f, -boundf[1]}; boundf[0] *= 5.0f; diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index 6c4942e8a9..b0b3e752df 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -154,7 +154,7 @@ bool SceneGraphNode::deinitialize() _nodeName = ""; _renderableVisible = false; _boundingSphereVisible = false; - _boundingSphere = pss(0.0, 0.0); + _boundingSphere = PowerScaledScalar(0.0, 0.0); return true; } @@ -270,20 +270,20 @@ const std::vector& SceneGraphNode::children() const } // bounding sphere -pss SceneGraphNode::calculateBoundingSphere() +PowerScaledScalar SceneGraphNode::calculateBoundingSphere() { // set the bounding sphere to 0.0 _boundingSphere = 0.0; if (_children.size() > 0) { // node - pss maxChild; + PowerScaledScalar maxChild; // loop though all children and find the one furthest away/with the largest // bounding sphere for (size_t i = 0; i < _children.size(); ++i) { // when positions is dynamic, change this part to fins the most distant // position - pss child = _children.at(i)->getPosition().length() + PowerScaledScalar child = _children.at(i)->getPosition().length() + _children.at(i)->calculateBoundingSphere(); if (child > maxChild) { maxChild = child; @@ -313,7 +313,7 @@ const Renderable* SceneGraphNode::getRenderable() const } // private helper methods -bool SceneGraphNode::sphereInsideFrustum(const psc s_pos, const pss& s_rad, +bool SceneGraphNode::sphereInsideFrustum(const psc s_pos, const PowerScaledScalar& s_rad, const Camera* camera) { // direction the camera is looking at in power scale diff --git a/src/util/planet.cpp b/src/util/planet.cpp index 725605091b..5c174317f4 100644 --- a/src/util/planet.cpp +++ b/src/util/planet.cpp @@ -20,7 +20,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace openspace { -Planet::Planet(pss radius, int levels) { +Planet::Planet(PowerScaledScalar radius, int levels) { // describe datatype and Vertex structure to the vbo template std::vector > descriptor; diff --git a/src/util/powerscaledcoordinate.cpp b/src/util/powerscaledcoordinate.cpp index 9c674b4da2..4f0f4d4749 100644 --- a/src/util/powerscaledcoordinate.cpp +++ b/src/util/powerscaledcoordinate.cpp @@ -95,9 +95,9 @@ glm::vec3 PowerScaledCoordinate::vec3() const _vec[2] * pow(k, _vec[3])); } -pss PowerScaledCoordinate::length() const +PowerScaledScalar PowerScaledCoordinate::length() const { - return pss(glm::length(glm::vec3(_vec[0], _vec[1], _vec[2])), _vec[3]); + return PowerScaledScalar(glm::length(glm::vec3(_vec[0], _vec[1], _vec[2])), _vec[3]); } glm::vec3 PowerScaledCoordinate::direction() const @@ -195,24 +195,24 @@ PowerScaledCoordinate PowerScaledCoordinate::operator*(const float& rhs) const return PowerScaledCoordinate(_vec[0] * rhs, _vec[1] * rhs, _vec[2] * rhs, _vec[3]); } -PowerScaledCoordinate& PowerScaledCoordinate::operator*=(const pss& rhs) +PowerScaledCoordinate& PowerScaledCoordinate::operator*=(const PowerScaledScalar& rhs) { - double ds = this->_vec[3] - rhs.vec_[1]; + double ds = this->_vec[3] - rhs._data[1]; if (ds >= 0) { double p = pow(k, -ds); *this = PowerScaledCoordinate( - rhs.vec_[0] * p * _vec[0], rhs.vec_[0] * p * _vec[1], - rhs.vec_[0] * p * _vec[2], this->_vec[3] + _vec[3]); + rhs._data[0] * p * _vec[0], rhs._data[0] * p * _vec[1], + rhs._data[0] * p * _vec[2], this->_vec[3] + _vec[3]); } else { double p = pow(k, ds); *this = PowerScaledCoordinate( - rhs.vec_[0] * _vec[0] * p, rhs.vec_[0] * _vec[1] * p, - rhs.vec_[0] * _vec[2] * p, rhs.vec_[1] + rhs.vec_[1]); + rhs._data[0] * _vec[0] * p, rhs._data[0] * _vec[1] * p, + rhs._data[0] * _vec[2] * p, rhs._data[1] + rhs._data[1]); } return *this; } -PowerScaledCoordinate PowerScaledCoordinate::operator*(const pss& rhs) const +PowerScaledCoordinate PowerScaledCoordinate::operator*(const PowerScaledScalar& rhs) const { return PowerScaledCoordinate(*this) *= rhs; } diff --git a/src/util/powerscaledscalar.cpp b/src/util/powerscaledscalar.cpp index ac6e1ee2d6..4f8bf23169 100644 --- a/src/util/powerscaledscalar.cpp +++ b/src/util/powerscaledscalar.cpp @@ -37,27 +37,19 @@ namespace openspace { } -pss::pss() { +PowerScaledScalar::PowerScaledScalar() : _data(0.f) { } -pss::pss(const glm::vec2 &v) { - vec_ = glm::dvec2(v); +PowerScaledScalar::PowerScaledScalar(const glm::vec2 &v) { + _data = std::move(v); } -pss::pss(const glm::dvec2 &v) { - vec_ = v; +PowerScaledScalar::PowerScaledScalar(float f1, float f2) { + _data = glm::vec2(f1, f2); } -pss::pss(const float &f1,const float &f2) { - vec_ = glm::dvec2(f1, f2); -} - -pss::pss(const double &d1,const double &d2) { - vec_ = glm::dvec2(d1, d2); -} - -pss pss::CreatePSS(double d1) { +PowerScaledScalar PowerScaledScalar::CreatePSS(double d1) { char buff[30]; // find the number with maximum number of digits @@ -69,237 +61,187 @@ pss pss::CreatePSS(double d1) { // rescale and return double tp = 1.0 / pow(k, digits); - return pss(d1*tp, digits); + return PowerScaledScalar(d1*tp, digits); } -void pss::print() const { - std::printf("[\n %f\n %f\n]\n",vec_[0], vec_[1]); -} -void pss::print(const char *name) const { - std::printf("%s = [\n %f\n %f\n]\n", name, vec_[0], vec_[1]); +const glm::vec2& PowerScaledScalar::vec2() const { + return _data; } -const double * pss::value_ptr() { - return glm::value_ptr(vec_); +float PowerScaledScalar::lengthf() const { + return static_cast(_data[0] * pow(k,_data[1])); } -const float * pss::value_ptrf() { - // need existing variable to return pointer to, local variables perish.. - vecf_ = glm::vec2(vec_); - return glm::value_ptr(vecf_); -} - -glm::dvec2 pss::getVec2() const{ - return vec_; -} - -glm::vec2 pss::getVec2f() const { - vecf_ = glm::vec2(vec_); - return vecf_; -} - -double pss::length() const { - return vec_[0] * pow(k,vec_[1]); -} - -float pss::lengthf() const { - return static_cast(vec_[0] * pow(k,vec_[1])); -} - -pss& pss::operator=(const pss &rhs) { +PowerScaledScalar& PowerScaledScalar::operator=(const PowerScaledScalar &rhs) { if (this != &rhs){ - this->vec_ = rhs.vec_; + this->_data = rhs._data; } return *this; // Return a reference to myself. } -pss & pss::operator=(const glm::vec2 &rhs) { - this->vec_ = glm::dvec2(rhs); +PowerScaledScalar & PowerScaledScalar::operator=(const glm::vec2 &rhs) { + this->_data = glm::vec2(rhs); return *this; // Return a reference to myself. } -pss & pss::operator=(const float &rhs) { - this->vec_ = glm::dvec2(rhs,0.0); +PowerScaledScalar & PowerScaledScalar::operator=(float rhs) { + this->_data = glm::vec2(rhs,0.0); return *this; // Return a reference to myself. } -pss & pss::operator=(const glm::dvec2 &rhs) { - this->vec_ = rhs; - return *this; // Return a reference to myself. -} +PowerScaledScalar & PowerScaledScalar::operator+=(const PowerScaledScalar &rhs) { -pss & pss::operator=(const double&rhs) { - this->vec_ = glm::dvec2(rhs,0.0); - return *this; // Return a reference to myself. -} - -pss & pss::operator+=(const pss &rhs) { - - double ds = this->vec_[1] - rhs.vec_[1]; + double ds = this->_data[1] - rhs._data[1]; if(ds >= 0) { - *this = pss(rhs.vec_[0]*pow(k,-ds) + this->vec_[0], this->vec_[1]); + *this = PowerScaledScalar(rhs._data[0]*pow(k,-ds) + this->_data[0], this->_data[1]); } else { - *this = pss(rhs.vec_[0] + this->vec_[0]*pow(k,ds), rhs.vec_[1]); + *this = PowerScaledScalar(rhs._data[0] + this->_data[0]*pow(k,ds), rhs._data[1]); } return *this; } -const pss pss::operator+(const pss &rhs) const { - return pss(*this) += rhs; +const PowerScaledScalar PowerScaledScalar::operator+(const PowerScaledScalar &rhs) const { + return PowerScaledScalar(*this) += rhs; } -pss & pss::operator-=(const pss &rhs) { +PowerScaledScalar & PowerScaledScalar::operator-=(const PowerScaledScalar &rhs) { - double ds = this->vec_[1] - rhs.vec_[1]; + double ds = this->_data[1] - rhs._data[1]; if(ds >= 0) { - *this = pss(-rhs.vec_[0]*pow(k,-ds) + this->vec_[0], this->vec_[1]); + *this = PowerScaledScalar(-rhs._data[0]*pow(k,-ds) + this->_data[0], this->_data[1]); } else { - *this = pss(-rhs.vec_[0] + this->vec_[0]*pow(k,ds), rhs.vec_[1]); + *this = PowerScaledScalar(-rhs._data[0] + this->_data[0]*pow(k,ds), rhs._data[1]); } return *this; } -const pss pss::operator-(const pss &rhs) const { - return pss(*this) -= rhs; +const PowerScaledScalar PowerScaledScalar::operator-(const PowerScaledScalar &rhs) const { + return PowerScaledScalar(*this) -= rhs; } -pss & pss::operator*=(const pss &rhs) { - double ds = this->vec_[1] - rhs.vec_[1]; +PowerScaledScalar & PowerScaledScalar::operator*=(const PowerScaledScalar &rhs) { + double ds = this->_data[1] - rhs._data[1]; if(ds >= 0) { - *this = pss(rhs.vec_[0]*pow(k,-ds) * this->vec_[0], this->vec_[1]+this->vec_[1]); + *this = PowerScaledScalar(rhs._data[0]*pow(k,-ds) * this->_data[0], this->_data[1]+this->_data[1]); } else { - *this = pss(rhs.vec_[0] * this->vec_[0]*pow(k,ds), rhs.vec_[1]+rhs.vec_[1]); + *this = PowerScaledScalar(rhs._data[0] * this->_data[0]*pow(k,ds), rhs._data[1]+rhs._data[1]); } return *this; } -const pss pss::operator*(const pss &rhs) const { - return pss(*this) *= rhs; +const PowerScaledScalar PowerScaledScalar::operator*(const PowerScaledScalar &rhs) const { + return PowerScaledScalar(*this) *= rhs; } -pss & pss::operator*=(const double &rhs) { - double ds = this->vec_[1]; + +PowerScaledScalar & PowerScaledScalar::operator*=(const float &rhs) { + double ds = this->_data[1]; if(ds >= 0) { - *this = pss(rhs*pow(k,-ds) * this->vec_[0], this->vec_[1]); + *this = PowerScaledScalar(rhs*pow(k,-ds) * this->_data[0],this->_data[1]+this->_data[1]); } else { - *this = pss(rhs * this->vec_[0]*pow(k,ds), 0.0); + *this = PowerScaledScalar(rhs * this->_data[0]*pow(k,ds), 0.0); } return *this; } - -const pss pss::operator*(const double &rhs) const { - return pss(*this) *= rhs; +const PowerScaledScalar PowerScaledScalar::operator*(const float &rhs) const { + return PowerScaledScalar(*this) *= rhs; } -pss & pss::operator*=(const float &rhs) { - double ds = this->vec_[1]; +float& PowerScaledScalar::operator[](unsigned int idx) { + return _data[idx]; +} + +float PowerScaledScalar::operator[](unsigned int idx) const { + return _data[idx]; +} + +bool PowerScaledScalar::operator==(const PowerScaledScalar &other) const { + return _data == other._data; +} + +bool PowerScaledScalar::operator<(const PowerScaledScalar &other) const { + double ds = this->_data[1] - other._data[1]; if(ds >= 0) { - *this = pss(rhs*pow(k,-ds) * this->vec_[0],this->vec_[1]+this->vec_[1]); - } else { - *this = pss(rhs * this->vec_[0]*pow(k,ds), 0.0); - } - - return *this; -} - -const pss pss::operator*(const float &rhs) const { - return pss(*this) *= rhs; -} - -double& pss::operator[](unsigned int idx) { - return vec_[idx]; -} -const double& pss::operator[](unsigned int idx) const { - return vec_[idx]; -} - -bool pss::operator==(const pss &other) const { - return vec_ == other.vec_; -} - -bool pss::operator<(const pss &other) const { - double ds = this->vec_[1] - other.vec_[1]; - if(ds >= 0) { - double upscaled = other.vec_[0]*pow(k,-ds); - return vec_[0] < upscaled; + double upscaled = other._data[0]*pow(k,-ds); + return _data[0] < upscaled; /* bool retur =(vec_[0] < upscaled); std::printf("this: %f, upscaled: %f, this upscaled; + double upscaled = _data[0]*pow(k,-ds); + return other._data[0] > upscaled; } } -bool pss::operator>(const pss &other) const { - double ds = this->vec_[1] - other.vec_[1]; +bool PowerScaledScalar::operator>(const PowerScaledScalar &other) const { + double ds = this->_data[1] - other._data[1]; if(ds >= 0) { - double upscaled = other.vec_[0]*pow(k,-ds); - return vec_[0] > upscaled; + double upscaled = other._data[0]*pow(k,-ds); + return _data[0] > upscaled; } else { - double upscaled = vec_[0]*pow(k,-ds); - return other.vec_[0] < upscaled; + double upscaled = _data[0]*pow(k,-ds); + return other._data[0] < upscaled; } } -bool pss::operator<=(const pss &other) const { +bool PowerScaledScalar::operator<=(const PowerScaledScalar &other) const { return *this < other || *this == other; } -bool pss::operator>=(const pss &other) const { +bool PowerScaledScalar::operator>=(const PowerScaledScalar &other) const { return *this > other || *this == other; } -bool pss::operator==(const double &other) const { - double ds = this->vec_[1]; +bool PowerScaledScalar::operator==(double other) const { + double ds = this->_data[1]; if(ds >= 0) { double upscaled = other*pow(k,-ds); - return vec_[0] == upscaled; + return _data[0] == upscaled; } else { - double upscaled = vec_[0]*pow(k,-ds); + double upscaled = _data[0]*pow(k,-ds); return other == upscaled; } } -bool pss::operator<(const double &other) const { - double ds = this->vec_[1]; +bool PowerScaledScalar::operator<(double other) const { + double ds = this->_data[1]; if(ds >= 0) { double upscaled = other*pow(k,-ds); - return vec_[0] < upscaled; + return _data[0] < upscaled; } else { - double upscaled = vec_[0]*pow(k,-ds); + double upscaled = _data[0]*pow(k,-ds); return other > upscaled; } } -bool pss::operator>(const double &other) const { - double ds = this->vec_[1]; +bool PowerScaledScalar::operator>(double other) const { + double ds = this->_data[1]; if(ds >= 0) { double upscaled = other*pow(k,-ds); - return vec_[0] > upscaled; + return _data[0] > upscaled; } else { - double upscaled = vec_[0]*pow(k,-ds); + double upscaled = _data[0]*pow(k,-ds); return other < upscaled; } } -bool pss::operator<=(const double &other) const { +bool PowerScaledScalar::operator<=(double other) const { return *this < other || *this == other; } -bool pss::operator>=(const double &other) const { +bool PowerScaledScalar::operator>=(double other) const { return *this > other || *this == other; } -std::ostream& operator<<(::std::ostream& os, const pss& rhs) { +std::ostream& operator<<(::std::ostream& os, const PowerScaledScalar& rhs) { os << "(" << rhs[0] << ", " << rhs[1] << ")"; return os; } diff --git a/src/util/powerscaledsphere.cpp b/src/util/powerscaledsphere.cpp index 0ffc17e21e..84c3f0ad24 100644 --- a/src/util/powerscaledsphere.cpp +++ b/src/util/powerscaledsphere.cpp @@ -36,7 +36,7 @@ const std::string _loggerCat = "PowerScaledSphere"; namespace openspace { -PowerScaledSphere::PowerScaledSphere(const pss& radius, int segments) +PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segments) : _vaoID(0) , _vBufferID(0) , _iBufferID(0)