From 207db3c82486d526cae0291f98f06898dc65260b Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 27 Dec 2019 23:29:28 +0100 Subject: [PATCH] Remove PowerScaledCoordinates and rename PowerScaledSphere to Sphere (closes #4) --- include/openspace/properties/property.h | 4 +- include/openspace/util/camera.h | 2 - .../openspace/util/powerscaledcoordinate.h | 114 ------- .../util/{powerscaledsphere.h => sphere.h} | 18 +- include/openspace/util/updatestructures.h | 1 - .../rendering/atmospheredeferredcaster.cpp | 1 - modules/base/rendering/renderablesphere.cpp | 6 +- modules/base/rendering/renderablesphere.h | 4 +- modules/base/shaders/imageplane_vs.glsl | 4 +- modules/iswa/rendering/datasphere.cpp | 4 +- modules/iswa/rendering/datasphere.h | 4 +- modules/iswa/rendering/iswacygnet.cpp | 6 +- .../space/rendering/simplespheregeometry.cpp | 6 +- .../space/rendering/simplespheregeometry.h | 4 +- .../rendering/renderablemodelprojection.cpp | 6 +- .../rendering/renderableplaneprojection.cpp | 30 +- .../rendering/toyvolumeraycaster.cpp | 1 - .../volume/rendering/basicvolumeraycaster.cpp | 1 - src/CMakeLists.txt | 6 +- src/util/powerscaledcoordinate.cpp | 322 ------------------ .../{powerscaledsphere.cpp => sphere.cpp} | 17 +- tests/main.cpp | 1 - tests/test_powerscalecoordinates.inl | 63 ---- 23 files changed, 56 insertions(+), 569 deletions(-) delete mode 100644 include/openspace/util/powerscaledcoordinate.h rename include/openspace/util/{powerscaledsphere.h => sphere.h} (86%) delete mode 100644 src/util/powerscaledcoordinate.cpp rename src/util/{powerscaledsphere.cpp => sphere.cpp} (93%) delete mode 100644 tests/test_powerscalecoordinates.inl diff --git a/include/openspace/properties/property.h b/include/openspace/properties/property.h index 6d7bbc3d3f..1b2f9fdbec 100644 --- a/include/openspace/properties/property.h +++ b/include/openspace/properties/property.h @@ -395,9 +395,7 @@ public: /** * Default view options that can be used in the Property::setViewOption method. The * values are: Property::ViewOptions::Color = \c color, - * Property::ViewOptions::LightPosition = \c lightPosition, - * Property::ViewOptions::PowerScaledScalar = \c powerScaledScalar, and - * Property::ViewOptions::PowerScaledCoordinate = \c powerScaledCoordinate. + * Property::ViewOptions::LightPosition = \c lightPosition */ struct ViewOptions { static const char* Color; diff --git a/include/openspace/util/camera.h b/include/openspace/util/camera.h index 8131d04191..8335329b31 100644 --- a/include/openspace/util/camera.h +++ b/include/openspace/util/camera.h @@ -25,7 +25,6 @@ #ifndef __OPENSPACE_CORE___CAMERA___H__ #define __OPENSPACE_CORE___CAMERA___H__ -#include #include #include #include @@ -36,7 +35,6 @@ class SceneGraphNode; /** * This class still needs some more love. Suggested improvements: - * - Remove psc from the camera class interface. * - Accessors should return constant references to double precision class members. * - Remove the scaling variable (What is it used for?) * - Remove the maxFov and sinMaxfov variables. Redundant since the fov is embedded diff --git a/include/openspace/util/powerscaledcoordinate.h b/include/openspace/util/powerscaledcoordinate.h deleted file mode 100644 index 64f258940c..0000000000 --- a/include/openspace/util/powerscaledcoordinate.h +++ /dev/null @@ -1,114 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#ifndef __OPENSPACE_CORE___POWERSCALEDCOORDINATE___H__ -#define __OPENSPACE_CORE___POWERSCALEDCOORDINATE___H__ - -#include - -namespace openspace { - -class PowerScaledScalar; - -class PowerScaledCoordinate { -public: - // constructors - PowerScaledCoordinate() = default; - - PowerScaledCoordinate(PowerScaledCoordinate&& rhs); - PowerScaledCoordinate(const PowerScaledCoordinate& rhs); - - // Sets the power scaled coordinates directly - PowerScaledCoordinate(glm::vec4 v); - PowerScaledCoordinate(float f1, float f2, float f3, float f4); - // Sets the power scaled coordinates with w = 0 - PowerScaledCoordinate(glm::vec3 v); - - static PowerScaledCoordinate CreatePowerScaledCoordinate(double d1, double d2, - double d3); - - // get functions - // return the full, unmodified PSC - const glm::vec4& vec4() const; - - // returns the rescaled, "normal" coordinates - glm::vec3 vec3() const; - - // return the full psc as dvec4() - glm::dvec4 dvec4() const; - - // rescaled return as dvec3 - glm::dvec3 dvec3() const; - - // length of the vector as a pss - float length() const; - glm::vec3 direction() const; - - // operator overloading - PowerScaledCoordinate& operator=(const PowerScaledCoordinate& rhs); - PowerScaledCoordinate& operator=(PowerScaledCoordinate&& rhs); - PowerScaledCoordinate& operator+=(const PowerScaledCoordinate& rhs); - PowerScaledCoordinate operator+(const PowerScaledCoordinate& rhs) const; - PowerScaledCoordinate& operator-=(const PowerScaledCoordinate& rhs); - PowerScaledCoordinate operator-(const PowerScaledCoordinate& rhs) const; - float& operator[](unsigned int idx); - float operator[](unsigned int idx) const; - double dot(const PowerScaledCoordinate& rhs) const; - double angle(const PowerScaledCoordinate& rhs) const; - - // scalar operators - PowerScaledCoordinate operator*(const double& rhs) const; - PowerScaledCoordinate operator*(const float& rhs) const; - PowerScaledCoordinate operator*(const glm::mat4& matrix) const; - - - // comparison - bool operator==(const PowerScaledCoordinate& other) const; - bool operator!=(const PowerScaledCoordinate& other) const; - bool operator<(const PowerScaledCoordinate& other) const; - bool operator>(const PowerScaledCoordinate& other) const; - bool operator<=(const PowerScaledCoordinate& other) const; - bool operator>=(const PowerScaledCoordinate& other) const; - - // glm integration - PowerScaledCoordinate& operator=(const glm::dvec4& rhs); - PowerScaledCoordinate& operator=(const glm::vec4& rhs); - PowerScaledCoordinate& operator=(const glm::dvec3& rhs); - PowerScaledCoordinate& operator=(const glm::vec3& rhs); - - friend std::ostream& operator<<(std::ostream& os, const PowerScaledCoordinate& rhs); - - // allow the power scaled scalars to access private members - friend class PowerScaledScalar; - -private: - // internal glm vector - glm::vec4 _vec = glm::vec4(0.f); -}; - -typedef PowerScaledCoordinate psc; - -} // namespace openspace - -#endif // __OPENSPACE_CORE___POWERSCALEDCOORDINATE___H__ diff --git a/include/openspace/util/powerscaledsphere.h b/include/openspace/util/sphere.h similarity index 86% rename from include/openspace/util/powerscaledsphere.h rename to include/openspace/util/sphere.h index 8be00b6f0b..47ff24e061 100644 --- a/include/openspace/util/powerscaledsphere.h +++ b/include/openspace/util/sphere.h @@ -22,22 +22,20 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_CORE___POWERSCALEDSPHERE___H__ -#define __OPENSPACE_CORE___POWERSCALEDSPHERE___H__ +#ifndef __OPENSPACE_CORE___SPHERE___H__ +#define __OPENSPACE_CORE___SPHERE___H__ #include #include namespace openspace { -class PowerScaledSphere; - -class PowerScaledSphere { +class Sphere { public: - PowerScaledSphere(float radius, int segments = 8); - PowerScaledSphere(glm::vec3 radius, int segments); - PowerScaledSphere(const PowerScaledSphere& cpy); - ~PowerScaledSphere(); + Sphere(float radius, int segments = 8); + Sphere(glm::vec3 radius, int segments); + Sphere(const Sphere& cpy); + ~Sphere(); bool initialize(); @@ -62,4 +60,4 @@ public: } // namespace openspace -#endif // __OPENSPACE_CORE___POWERSCALEDSPHERE___H__ +#endif // __OPENSPACE_CORE___SPHERE___H__ diff --git a/include/openspace/util/updatestructures.h b/include/openspace/util/updatestructures.h index f6ecef64a4..406181eebc 100644 --- a/include/openspace/util/updatestructures.h +++ b/include/openspace/util/updatestructures.h @@ -26,7 +26,6 @@ #define __OPENSPACE_CORE___UPDATESTRUCTURES___H__ #include -#include #include namespace openspace { diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index 3e5dec47ad..3cb7b040ff 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -60,7 +60,6 @@ #include #include -#include #include #include #include diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index 1d653791fd..c3ffa2dc70 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -304,7 +304,7 @@ bool RenderableSphere::isReady() const { } void RenderableSphere::initializeGL() { - _sphere = std::make_unique(_size, _segments); + _sphere = std::make_unique(_size, _segments); _sphere->initialize(); _shader = BaseModule::ProgramObjectManager.request( @@ -467,7 +467,7 @@ void RenderableSphere::update(const UpdateData&) { } if (_sphereIsDirty) { - _sphere = std::make_unique(_size, _segments); + _sphere = std::make_unique(_size, _segments); _sphere->initialize(); _sphereIsDirty = false; } diff --git a/modules/base/rendering/renderablesphere.h b/modules/base/rendering/renderablesphere.h index b7ff144fbd..e8e195eb71 100644 --- a/modules/base/rendering/renderablesphere.h +++ b/modules/base/rendering/renderablesphere.h @@ -40,7 +40,7 @@ namespace ghoul::opengl { namespace openspace { -class PowerScaledSphere; +class Sphere; struct RenderData; struct UpdateData; @@ -80,7 +80,7 @@ private: ghoul::opengl::ProgramObject* _shader = nullptr; std::unique_ptr _texture; - std::unique_ptr _sphere; + std::unique_ptr _sphere; UniformCache(opacity, modelViewProjection, modelViewRotation, colorTexture, _mirrorTexture) _uniformCache; diff --git a/modules/base/shaders/imageplane_vs.glsl b/modules/base/shaders/imageplane_vs.glsl index 0962157b38..995c35950c 100644 --- a/modules/base/shaders/imageplane_vs.glsl +++ b/modules/base/shaders/imageplane_vs.glsl @@ -22,6 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +// @TODO (abock, 2019-12-27) Move this file to the spacecraftinstruments module + #version __CONTEXT__ #include "PowerScaling/powerScaling_vs.hglsl" @@ -36,7 +38,7 @@ uniform mat4 modelViewProjectionTransform; void main() { - vec4 position = vec4(in_position.xyz * pow(10, in_position.w), 1); + vec4 position = vec4(in_position.xyz, 1); vec4 positionClipSpace = modelViewProjectionTransform * position; vec4 positionScreenSpace = z_normalization(positionClipSpace); diff --git a/modules/iswa/rendering/datasphere.cpp b/modules/iswa/rendering/datasphere.cpp index 10cdc263a2..cb68d437c7 100644 --- a/modules/iswa/rendering/datasphere.cpp +++ b/modules/iswa/rendering/datasphere.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -88,7 +88,7 @@ void DataSphere::initializeGL() { bool DataSphere::createGeometry() { const float radius = 6.371f * _radius * glm::pow(10.f, 6.f); int segments = 100; - _sphere = std::make_unique(radius, segments); + _sphere = std::make_unique(radius, segments); _sphere->initialize(); return true; } diff --git a/modules/iswa/rendering/datasphere.h b/modules/iswa/rendering/datasphere.h index 2ec89762ea..66b5948a93 100644 --- a/modules/iswa/rendering/datasphere.h +++ b/modules/iswa/rendering/datasphere.h @@ -29,7 +29,7 @@ namespace openspace { -class PowerScaledSphere; +class Sphere; /** * DataSphere is a concrete IswaCygnet with data files as its input source. The class @@ -53,7 +53,7 @@ protected: void setUniforms() override; std::vector textureData() override; - std::unique_ptr _sphere; + std::unique_ptr _sphere; float _radius; }; diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index 663ba6dca4..967613f9bf 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -157,12 +156,13 @@ void IswaCygnet::render(const RenderData& data, RendererTasks&) { } transform = transform * _rotation; - psc position = + glm::vec4 pposition = static_cast(glm::dvec4(data.modelTransform.translation, 0.0)) + transform * glm::vec4( _data.spatialScale.x * _data.offset, _data.spatialScale.w ); + glm::vec3 position = glm::vec3(pposition) * pow(10.f, pposition.w); // Activate shader _shader->activate(); @@ -173,7 +173,7 @@ void IswaCygnet::render(const RenderData& data, RendererTasks&) { _shader->setUniform("ModelTransform", transform); _shader->setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f)); - _shader->setUniform("objpos", glm::vec4(position.vec3(), 0.f)); + _shader->setUniform("objpos", glm::vec4(position, 0.f)); _shader->setUniform("camrot", glm::mat4(data.camera.viewRotationMatrix())); _shader->setUniform("scaling", glm::vec2(1.f, 0.f)); diff --git a/modules/space/rendering/simplespheregeometry.cpp b/modules/space/rendering/simplespheregeometry.cpp index 347752cc3c..4b8fcdd514 100644 --- a/modules/space/rendering/simplespheregeometry.cpp +++ b/modules/space/rendering/simplespheregeometry.cpp @@ -25,9 +25,9 @@ #include #include -#include #include -#include +#include +#include namespace { constexpr openspace::properties::Property::PropertyInfo RadiusInfo = { @@ -124,7 +124,7 @@ void SimpleSphereGeometry::createSphere() { const glm::vec3 radius = _radius.value(); delete _sphere; - _sphere = new PowerScaledSphere(radius, _segments); + _sphere = new Sphere(radius, _segments); _sphere->initialize(); } diff --git a/modules/space/rendering/simplespheregeometry.h b/modules/space/rendering/simplespheregeometry.h index 8148ec052e..abed585ab9 100644 --- a/modules/space/rendering/simplespheregeometry.h +++ b/modules/space/rendering/simplespheregeometry.h @@ -32,7 +32,7 @@ namespace openspace { class Renderable; - class PowerScaledSphere; + class Sphere; } // namespace openspace namespace openspace::documentation { struct Documentation; } @@ -57,7 +57,7 @@ private: properties::Vec3Property _radius; properties::IntProperty _segments; - PowerScaledSphere* _sphere; + Sphere* _sphere; }; } // namespace openspace::planetgeometry diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index 8dba28ee8d..556c946e1f 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -461,11 +461,7 @@ void RenderableModelProjection::attitudeParameters(double time) { lightTime ); - // @TODO: Remove this and replace with cpos = p * 1000 ? - psc position = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z); - - position[3] += 4; - const glm::vec3 cpos = position.vec3(); + const glm::vec3 cpos = p * 10000.0; const float distance = glm::length(cpos); const float radius = boundingSphere(); diff --git a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp index 48508ce2f8..85eed498c2 100644 --- a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp @@ -227,8 +227,7 @@ void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime ); // The apparent position, CN+S, makes image align best with target - // @TODO: Remove these powerscaled coordinates - psc projection[4]; + glm::dvec3 projection[4]; for (size_t j = 0; j < bounds.size(); ++j) { bounds[j] = SpiceManager::ref().frameTransformationMatrix( frame, @@ -246,12 +245,8 @@ void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime currentTime ) * cornerPosition; - projection[j] = PowerScaledCoordinate::CreatePowerScaledCoordinate( - cornerPosition[0], - cornerPosition[1], - cornerPosition[2] - ); - projection[j][3] += 3; + // km -> m + projection[j] = cornerPosition * 1000.0; } if (!_moving) { @@ -264,21 +259,28 @@ void RenderablePlaneProjection::updatePlane(const Image& img, double currentTime } } + glm::vec3 p[4] = { + glm::vec3(projection[0]), + glm::vec3(projection[1]), + glm::vec3(projection[2]), + glm::vec3(projection[3]) + + }; const GLfloat vertex_data[] = { // square of two triangles drawn within fov in target coordinates // x y z w s t // Lower left 1 - projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 0, + p[1].x, p[1].y, p[1].z, 0.f, 0.f, 0.f, // Upper right 2 - projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 1, + p[3].x, p[3].y, p[3].z, 0.f, 1.f, 1.f, // Upper left 3 - projection[2][0], projection[2][1], projection[2][2], projection[2][3], 0, 1, + p[2].x, p[2].y, p[2].z, 0.f, 0.f, 1.f, // Lower left 4 = 1 - projection[1][0], projection[1][1], projection[1][2], projection[1][3], 0, 0, + p[1].x, p[1].y, p[1].z, 0.f, 0.f, 0.f, // Lower right 5 - projection[0][0], projection[0][1], projection[0][2], projection[0][3], 1, 0, + p[0].x, p[0].y, p[0].z, 0.f, 1.f, 0.f, // Upper left 6 = 2 - projection[3][0], projection[3][1], projection[3][2], projection[3][3], 1, 1, + p[3].x, p[3].y, p[3].z, 0.f, 1.f, 1.f, }; glBindVertexArray(_quad); diff --git a/modules/toyvolume/rendering/toyvolumeraycaster.cpp b/modules/toyvolume/rendering/toyvolumeraycaster.cpp index 2f5f82f0ac..97d71c05bf 100644 --- a/modules/toyvolume/rendering/toyvolumeraycaster.cpp +++ b/modules/toyvolume/rendering/toyvolumeraycaster.cpp @@ -24,7 +24,6 @@ #include -#include #include #include #include diff --git a/modules/volume/rendering/basicvolumeraycaster.cpp b/modules/volume/rendering/basicvolumeraycaster.cpp index f81912cfeb..b404d97bb3 100644 --- a/modules/volume/rendering/basicvolumeraycaster.cpp +++ b/modules/volume/rendering/basicvolumeraycaster.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6bae69e26..bba42b68da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -177,11 +177,10 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/util/httprequest.cpp ${OPENSPACE_BASE_DIR}/src/util/keys.cpp ${OPENSPACE_BASE_DIR}/src/util/openspacemodule.cpp - ${OPENSPACE_BASE_DIR}/src/util/powerscaledcoordinate.cpp - ${OPENSPACE_BASE_DIR}/src/util/powerscaledsphere.cpp ${OPENSPACE_BASE_DIR}/src/util/progressbar.cpp ${OPENSPACE_BASE_DIR}/src/util/resourcesynchronization.cpp ${OPENSPACE_BASE_DIR}/src/util/screenlog.cpp + ${OPENSPACE_BASE_DIR}/src/util/sphere.cpp ${OPENSPACE_BASE_DIR}/src/util/spicemanager.cpp ${OPENSPACE_BASE_DIR}/src/util/spicemanager_lua.inl ${OPENSPACE_BASE_DIR}/src/util/syncbuffer.cpp @@ -371,11 +370,10 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/util/keys.h ${OPENSPACE_BASE_DIR}/include/openspace/util/mouse.h ${OPENSPACE_BASE_DIR}/include/openspace/util/openspacemodule.h - ${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledcoordinate.h - ${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledsphere.h ${OPENSPACE_BASE_DIR}/include/openspace/util/progressbar.h ${OPENSPACE_BASE_DIR}/include/openspace/util/resourcesynchronization.h ${OPENSPACE_BASE_DIR}/include/openspace/util/screenlog.h + ${OPENSPACE_BASE_DIR}/include/openspace/util/sphere.h ${OPENSPACE_BASE_DIR}/include/openspace/util/spicemanager.h ${OPENSPACE_BASE_DIR}/include/openspace/util/syncable.h ${OPENSPACE_BASE_DIR}/include/openspace/util/syncbuffer.h diff --git a/src/util/powerscaledcoordinate.cpp b/src/util/powerscaledcoordinate.cpp deleted file mode 100644 index e5d1f5df75..0000000000 --- a/src/util/powerscaledcoordinate.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#include - -#include -#include - -namespace { - constexpr const double k = 10.0; -} // namespace - -namespace openspace { - -PowerScaledCoordinate::PowerScaledCoordinate(PowerScaledCoordinate&& rhs) { - _vec = std::move(rhs._vec); -} - -PowerScaledCoordinate::PowerScaledCoordinate(glm::vec4 v) { - _vec = std::move(v); -} - -PowerScaledCoordinate::PowerScaledCoordinate(glm::vec3 v) { - _vec = glm::vec4(v, 0.f); -} - -PowerScaledCoordinate::PowerScaledCoordinate(float f1, float f2, float f3, float f4) { - _vec = glm::vec4(f1, f2, f3, f4); -} - -PowerScaledCoordinate::PowerScaledCoordinate(const PowerScaledCoordinate& rhs) { - _vec = rhs._vec; -} - -PowerScaledCoordinate -PowerScaledCoordinate::CreatePowerScaledCoordinate(double d1, double d2, double d3) -{ - char buff[600]; - - // find the number with maximum number of digits - double ad1 = std::abs(d1); - double ad2 = std::abs(d2); - double ad3 = std::abs(d3); - double max = (ad2 > ad1) ? ad2 : (ad3 > ad1) ? ad3 : ad1; - - // find out how many digits - // TODO: profile the next two lines and replace with something more efficient (ab) -#ifdef _MSC_VER - sprintf_s(buff, 600, "%.0f", max); - //sprintf(buff, "%.0f", max); -#else - sprintf(buff, "%.0f", max); -#endif - size_t digits = strlen(buff); - - //digits += 3; - - // rescale and return - double tp = 1.0 / pow(k, digits); - return PowerScaledCoordinate( - static_cast(d1 * tp), - static_cast(d2 * tp), - static_cast(d3 * tp), - static_cast(digits)); -} - -const glm::vec4& PowerScaledCoordinate::vec4() const -{ - return _vec; -} - -glm::vec3 PowerScaledCoordinate::vec3() const -{ - return glm::vec3(_vec[0] * pow(k, _vec[3]), _vec[1] * pow(k, _vec[3]), - _vec[2] * pow(k, _vec[3])); -} - -glm::dvec4 PowerScaledCoordinate::dvec4() const -{ - //return _vec; - return glm::dvec4(_vec); -} - -glm::dvec3 PowerScaledCoordinate::dvec3() const -{ - double p = pow(static_cast(k), static_cast(_vec[3])); - return glm::dvec3( static_cast(_vec[0]) * p, static_cast(_vec[1]) * p, - static_cast(_vec[2]) * p); -} - -float PowerScaledCoordinate::length() const -{ - return glm::length(glm::vec3(_vec[0], _vec[1], _vec[2])) * std::pow(10, _vec[3]); -} - -glm::vec3 PowerScaledCoordinate::direction() const -{ - glm::vec3 tmp(_vec[0], _vec[1], _vec[2]); - return glm::normalize(glm::vec3(_vec[0], _vec[1], _vec[2])); -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator=(const PowerScaledCoordinate& rhs) -{ - if (this != &rhs) { - _vec = rhs._vec; - } - return *this; // Return a reference to myself. -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator=(const glm::vec4& rhs) { - _vec = rhs; - return *this; // Return a reference to myself. -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator=(const glm::vec3& rhs) { - _vec = glm::vec4(rhs[0], rhs[1], rhs[2], 0.0); - return *this; // Return a reference to myself. -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator=(const glm::dvec4& rhs) { - _vec = glm::vec4(rhs); - return *this; // Return a reference to myself. -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator=(const glm::dvec3& rhs) { - _vec = glm::vec4(rhs[0], rhs[1], rhs[2], 0.0); - return *this; // Return a reference to myself. -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator=(PowerScaledCoordinate&& rhs) { - _vec = std::move(rhs._vec); - return *this; -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator+=(const PowerScaledCoordinate& rhs) -{ - double ds = _vec[3] - rhs._vec[3]; - if (ds >= 0.0) { - double p = pow(k, -ds); - *this = PowerScaledCoordinate(static_cast(rhs._vec[0] * p + _vec[0]), - static_cast(rhs._vec[1] * p + _vec[1]), - static_cast(rhs._vec[2] * p + _vec[2]), - _vec[3]); - } else { - double p = pow(k, ds); - *this = PowerScaledCoordinate(static_cast(rhs._vec[0] + _vec[0] * p), - static_cast(rhs._vec[1] + _vec[1] * p), - static_cast(rhs._vec[2] + _vec[2] * p), - rhs._vec[3]); - } - - return *this; -} - -PowerScaledCoordinate PowerScaledCoordinate:: - operator+(const PowerScaledCoordinate& rhs) const -{ - return PowerScaledCoordinate(*this) += rhs; -} - -PowerScaledCoordinate& PowerScaledCoordinate::operator-=(const PowerScaledCoordinate& rhs) -{ - double ds = this->_vec[3] - rhs._vec[3]; - if (ds >= 0.0) { - double p = pow(k, -ds); - *this = PowerScaledCoordinate(static_cast(-rhs._vec[0] * p + _vec[0]), - static_cast(-rhs._vec[1] * p + _vec[1]), - static_cast(-rhs._vec[2] * p + _vec[2]), - _vec[3]); - } else { - double p = pow(k, ds); - *this = PowerScaledCoordinate(static_cast(-rhs._vec[0] + _vec[0] * p), - static_cast(-rhs._vec[1] + _vec[1] * p), - static_cast(-rhs._vec[2] + _vec[2] * p), - rhs._vec[3]); - } - - return *this; -} - -PowerScaledCoordinate PowerScaledCoordinate::operator*(const double& rhs) const -{ - return PowerScaledCoordinate(static_cast(_vec[0] * rhs), - static_cast(_vec[1] * rhs), - static_cast(_vec[2] * rhs), _vec[3]); -} - -PowerScaledCoordinate PowerScaledCoordinate::operator*(const float& rhs) const -{ - return PowerScaledCoordinate(_vec[0] * rhs, _vec[1] * rhs, _vec[2] * rhs, _vec[3]); -} - -PowerScaledCoordinate PowerScaledCoordinate::operator*(const glm::mat4& matrix) const -{ - return matrix * _vec; -} - -PowerScaledCoordinate PowerScaledCoordinate:: - operator-(const PowerScaledCoordinate& rhs) const -{ - return PowerScaledCoordinate(*this) -= rhs; -} - -float& PowerScaledCoordinate::operator[](unsigned int idx) -{ - return _vec[idx]; -} - -float PowerScaledCoordinate::operator[](unsigned int idx) const -{ - return _vec[idx]; -} - -double PowerScaledCoordinate::dot(const PowerScaledCoordinate& rhs) const -{ - double ds = _vec[3] - rhs._vec[3]; - if (ds >= 0.0) { - double p = pow(k, -ds); - glm::dvec3 uPowerScaledCoordinatealed(rhs._vec[0] * p, rhs._vec[1] * p, - rhs._vec[2] * p); - glm::dvec3 shortened(_vec[0], _vec[1], _vec[2]); - return glm::dot(uPowerScaledCoordinatealed, shortened); - } else { - double p = pow(k, ds); - glm::dvec3 uPowerScaledCoordinatealed(_vec[0] * p, _vec[1] * p, _vec[2] * p); - glm::dvec3 shortened(rhs._vec[0], rhs._vec[1], rhs._vec[2]); - return glm::dot(uPowerScaledCoordinatealed, shortened); - } -} - -double PowerScaledCoordinate::angle(const PowerScaledCoordinate& rhs) const -{ - glm::dvec3 uPowerScaledCoordinatealed(rhs._vec[0], rhs._vec[1], rhs._vec[2]); - glm::dvec3 shortened(_vec[0], _vec[1], _vec[2]); - uPowerScaledCoordinatealed = glm::normalize(uPowerScaledCoordinatealed); - shortened = glm::normalize(shortened); - - return acos(glm::dot(uPowerScaledCoordinatealed, shortened)); -} - -bool PowerScaledCoordinate::operator==(const PowerScaledCoordinate& other) const -{ - return _vec == other._vec; -} - -bool PowerScaledCoordinate::operator!=(const PowerScaledCoordinate& other) const -{ - return _vec != other._vec; -} - -bool PowerScaledCoordinate::operator<(const PowerScaledCoordinate& other) const -{ - double ds = _vec[3] - other._vec[3]; - if (ds >= 0) { - double p = pow(k, -ds); - glm::dvec3 upscaled(other._vec[0] * p, other._vec[1] * p, - other._vec[2] * p); - glm::dvec3 shortened(_vec[0], _vec[1], _vec[2]); - return glm::length(shortened) < glm::length(upscaled); - } else { - double p = pow(k, ds); - glm::dvec3 upscaled(_vec[0] * p, _vec[1] * p, _vec[2] * p); - glm::dvec3 shortened(other._vec[0], other._vec[1], other._vec[2]); - return glm::length(shortened) < glm::length(upscaled); - } -} - -bool PowerScaledCoordinate::operator>(const PowerScaledCoordinate& other) const -{ - double ds = this->_vec[3] - other._vec[3]; - if (ds >= 0) { - double p = pow(k, -ds); - glm::dvec3 upscaled(other._vec[0] * p, other._vec[1] * p, - other._vec[2] * p); - glm::dvec3 shortened(_vec[0], _vec[1], _vec[2]); - return glm::length(shortened) > glm::length(upscaled); - } else { - double p = pow(k, ds); - glm::dvec3 upscaled(_vec[0] * p, _vec[1] * p, _vec[2] * p); - glm::dvec3 shortened(other._vec[0], other._vec[1], other._vec[2]); - return glm::length(shortened) > glm::length(upscaled); - } -} - -bool PowerScaledCoordinate::operator<=(const PowerScaledCoordinate& other) const -{ - return *this < other || *this == other; -} - -bool PowerScaledCoordinate::operator>=(const PowerScaledCoordinate& other) const -{ - return *this > other || *this == other; -} - -std::ostream& operator<<(::std::ostream& os, const PowerScaledCoordinate& rhs) -{ - os << "(" << rhs[0] << ", " << rhs[1] << ", " << rhs[2] << "; " << rhs[3] << ")"; - return os; -} - -} // namespace openspace diff --git a/src/util/powerscaledsphere.cpp b/src/util/sphere.cpp similarity index 93% rename from src/util/powerscaledsphere.cpp rename to src/util/sphere.cpp index 25319ddba1..cbd3cfc4dc 100644 --- a/src/util/powerscaledsphere.cpp +++ b/src/util/sphere.cpp @@ -22,9 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include -#include #include #include @@ -34,12 +33,12 @@ namespace { namespace openspace { -PowerScaledSphere::PowerScaledSphere(float radius, int segments) - : PowerScaledSphere(glm::vec3(radius), segments) +Sphere::Sphere(float radius, int segments) + : Sphere(glm::vec3(radius), segments) {} // Alternative Constructor for using accurate triaxial ellipsoid -PowerScaledSphere::PowerScaledSphere(glm::vec3 radius, int segments) +Sphere::Sphere(glm::vec3 radius, int segments) : _isize(6 * segments * segments) , _vsize((segments + 1) * (segments + 1)) , _varray(new Vertex[_vsize]) @@ -110,7 +109,7 @@ PowerScaledSphere::PowerScaledSphere(glm::vec3 radius, int segments) } } -PowerScaledSphere::PowerScaledSphere(const PowerScaledSphere& cpy) +Sphere::Sphere(const Sphere& cpy) : _vaoID(cpy._vaoID) , _vBufferID(cpy._vBufferID) , _iBufferID(cpy._iBufferID) @@ -125,7 +124,7 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledSphere& cpy) std::memcpy(_iarray, cpy._iarray, _isize * sizeof(int)); } -PowerScaledSphere::~PowerScaledSphere() { +Sphere::~Sphere() { delete[] _varray; delete[] _iarray; @@ -137,7 +136,7 @@ PowerScaledSphere::~PowerScaledSphere() { glDeleteVertexArrays(1, &_vaoID); } -bool PowerScaledSphere::initialize() { +bool Sphere::initialize() { // Initialize and upload to graphics card if (_vaoID == 0) { glGenVertexArrays(1, &_vaoID); @@ -197,7 +196,7 @@ bool PowerScaledSphere::initialize() { return true; } -void PowerScaledSphere::render() { +void Sphere::render() { glBindVertexArray(_vaoID); // select first VAO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID); glDrawElements(GL_TRIANGLES, _isize, GL_UNSIGNED_INT, nullptr); diff --git a/tests/main.cpp b/tests/main.cpp index b5c3cd717f..8fa9ef3765 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -66,7 +66,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/test_powerscalecoordinates.inl b/tests/test_powerscalecoordinates.inl deleted file mode 100644 index 23b22a70a9..0000000000 --- a/tests/test_powerscalecoordinates.inl +++ /dev/null @@ -1,63 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#include - -#include - -class PowerscaleCoordinatesTest : public testing::Test { -protected: - PowerscaleCoordinatesTest() { - } - - ~PowerscaleCoordinatesTest() { - } - - void reset() { - } - - openspace::Scene* scenegraph; -}; - - -TEST_F(PowerscaleCoordinatesTest, psc) { - - openspace::psc reference(2.f, 1.f, 1.1f, 1.f); - - openspace::psc first(1.f, 0.f, 1.f, 0.f); - openspace::psc second(1.9f, 1.f, 1.f, 1.f); - - EXPECT_EQ(reference, first + second); - EXPECT_TRUE(reference == (first + second)); - - openspace::psc third = first; - first[0] = 0.0; - - EXPECT_TRUE(third != first); - - -} - - -