diff --git a/modules/base/rendering/renderablelabels.cpp b/modules/base/rendering/renderablelabels.cpp index d5f84a2427..1cd59dee12 100644 --- a/modules/base/rendering/renderablelabels.cpp +++ b/modules/base/rendering/renderablelabels.cpp @@ -31,19 +31,19 @@ #include #include #include -#include +#include #include -#include -#include -#include -#include +#include #include #include +#include +#include +#include #include +#include #include #include #include -#include #include namespace { @@ -175,7 +175,6 @@ namespace { "Fade-In/-Out ending speed.", "Fade-In/-Out ending speed." }; - } // namespace namespace openspace { @@ -641,8 +640,8 @@ void RenderableLabels::render(const RenderData& data, RendererTasks&) { data.camera.positionVec3(), data.modelTransform.translation ); - float sUnit = getUnit(_fadeStartUnitOption); - float eUnit = getUnit(_fadeEndUnitOption); + float sUnit = unit(_fadeStartUnitOption); + float eUnit = unit(_fadeEndUnitOption); float startX = _fadeStartDistance * sUnit; float endX = _fadeEndDistance * eUnit; //fadeInVariable = changedPerlinSmoothStepFunc(distanceNodeToCamera, startX, endX); @@ -767,49 +766,22 @@ float RenderableLabels::linearSmoothStepFunc(float x, float startX, float endX, } } -float RenderableLabels::getUnit(int unit) const { - - float scale = 0.f; +float RenderableLabels::unit(int unit) const { switch (static_cast(unit)) { - case Meter: - scale = 1.f; - break; - case Kilometer: - scale = 1e3; - break; - case Megameter: - scale = 1e6; - break; - case Gigameter: - scale = 1e9; - break; - case AU: - scale = 149597870700.f; - break; - case Terameter: - scale = 1e12; - break; - case Petameter: - scale = 1e15; - break; - case Parsec: - scale = static_cast(PARSEC); - break; - case Kiloparsec: - scale = static_cast(1e3 * PARSEC); - break; - case Megaparsec: - scale = static_cast(1e6 * PARSEC); - break; - case Gigaparsec: - scale = static_cast(1e9 * PARSEC); - break; - case GigalightYears: - scale = static_cast(306391534.73091 * PARSEC); - break; + case Meter: return 1.f; + case Kilometer: return 1e3; + case Megameter: return 1e6; + case Gigameter: return 1e9; + case AU: return 149597870700.f; + case Terameter: return 1e12; + case Petameter: return 1e15; + case Parsec: return static_cast(PARSEC); + case Kiloparsec: return static_cast(1e3 * PARSEC); + case Megaparsec: return static_cast(1e6 * PARSEC); + case Gigaparsec: return static_cast(1e9 * PARSEC); + case GigalightYears: return static_cast(306391534.73091 * PARSEC); + default: throw std::logic_error("Missing case label"); } - - return scale; } } // namespace openspace diff --git a/modules/base/rendering/renderablelabels.h b/modules/base/rendering/renderablelabels.h index 4546ad9211..df69d50544 100644 --- a/modules/base/rendering/renderablelabels.h +++ b/modules/base/rendering/renderablelabels.h @@ -72,7 +72,7 @@ public: protected: properties::OptionProperty _blendMode; - float getUnit(int unit) const; + float unit(int unit) const; // Data may require some type of transformation prior the spice transformation being // applied. diff --git a/modules/base/rendering/renderablenodeline.cpp b/modules/base/rendering/renderablenodeline.cpp index 8d809df5f4..7725b8e4ab 100644 --- a/modules/base/rendering/renderablenodeline.cpp +++ b/modules/base/rendering/renderablenodeline.cpp @@ -67,6 +67,22 @@ namespace { "Line Width", "This value specifies the line width." }; + + // Returns a position that is relative to the current anchor node. This is a method to + // handle precision problems that occur when approaching a line end point + glm::dvec3 coordinatePosFromAnchorNode(const glm::dvec3& worldPos) { + using namespace openspace; + glm::dvec3 anchorNodePos(0.0); + + const interaction::OrbitalNavigator& nav = + global::navigationHandler.orbitalNavigator(); + + if (nav.anchorNode()) { + anchorNodePos = nav.anchorNode()->worldPosition(); + } + glm::dvec3 diffPos = worldPos - anchorNodePos; + return diffPos; + } } // namespace namespace openspace { @@ -143,19 +159,16 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary) addProperty(_opacity); } -double RenderableNodeLine::getDistance() -{ +double RenderableNodeLine::distance() const { return glm::distance(_startPos, _endPos); } -const std::string RenderableNodeLine::getStart() -{ - return _start.value(); +std::string RenderableNodeLine::start() const { + return _start; } -const std::string RenderableNodeLine::getEnd() -{ - return _end.value(); +std::string RenderableNodeLine::end() const { + return _end; } void RenderableNodeLine::initializeGL() { @@ -183,7 +196,6 @@ void RenderableNodeLine::initializeGL() { } void RenderableNodeLine::deinitializeGL() { - glDeleteVertexArrays(1, &_vaoId); _vaoId = 0; @@ -210,19 +222,21 @@ void RenderableNodeLine::unbindGL() { glBindVertexArray(0); } -void RenderableNodeLine::bindGL() -{ +void RenderableNodeLine::bindGL() { glBindVertexArray(_vaoId); glBindBuffer(GL_ARRAY_BUFFER, _vBufferId); } -void RenderableNodeLine::updateVertexData() -{ +void RenderableNodeLine::updateVertexData() { _vertexArray.clear(); // Update the positions of the nodes - _startPos = getCoordinatePosFromAnchorNode(global::renderEngine.scene()->sceneGraphNode(_start)->worldPosition()); - _endPos = getCoordinatePosFromAnchorNode(global::renderEngine.scene()->sceneGraphNode(_end)->worldPosition()); + _startPos = coordinatePosFromAnchorNode( + global::renderEngine.scene()->sceneGraphNode(_start)->worldPosition() + ); + _endPos = coordinatePosFromAnchorNode( + global::renderEngine.scene()->sceneGraphNode(_end)->worldPosition() + ); _vertexArray.push_back(_startPos.x); _vertexArray.push_back(_startPos.y); @@ -242,14 +256,13 @@ void RenderableNodeLine::updateVertexData() GL_DYNAMIC_DRAW ); - //update vertex attributes + // update vertex attributes glVertexAttribPointer(_locVertex, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr); unbindGL(); } void RenderableNodeLine::render(const RenderData& data, RendererTasks&) { - updateVertexData(); _program->activate(); @@ -257,7 +270,10 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) { glm::dmat4 anchorTranslation(1.0); // Update anchor node information, used to counter precision problems if (global::navigationHandler.orbitalNavigator().anchorNode()) { - anchorTranslation = glm::translate(glm::dmat4(1.0), global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition()); + anchorTranslation = glm::translate( + glm::dmat4(1.0), + global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition() + ); } const glm::dmat4 modelTransform = @@ -278,8 +294,12 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) { GLfloat currentLineWidth; glGetFloatv(GL_LINE_WIDTH, ¤tLineWidth); - GLenum blendEquationRGB, blendEquationAlpha, blendDestAlpha, - blendDestRGB, blendSrcAlpha, blendSrcRGB; + GLenum blendEquationRGB; + GLenum blendEquationAlpha; + GLenum blendDestAlpha; + GLenum blendDestRGB; + GLenum blendSrcAlpha; + GLenum blendSrcRGB; glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB); glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha); glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha); @@ -311,34 +331,19 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) { } } -void RenderableNodeLine::validateNodes() -{ +void RenderableNodeLine::validateNodes() { if (!global::renderEngine.scene()->sceneGraphNode(_start)) { - LERROR(fmt::format("There is no scenegraph node with id {}, defaults to 'Root'", _start)); + LERROR(fmt::format( + "There is no scenegraph node with id {}, defaults to 'Root'", _start + )); _start = Root; } if (!global::renderEngine.scene()->sceneGraphNode(_end)) { - LERROR(fmt::format("There is no scenegraph node with id {}, defaults to 'Root'", _end)); + LERROR(fmt::format( + "There is no scenegraph node with id {}, defaults to 'Root'", _end + )); _end = Root; } } - -/* Returns a position that is relative to the current - anchor node. This is a method to handle precision - problems that occur when approaching a line end point */ -glm::dvec3 RenderableNodeLine::getCoordinatePosFromAnchorNode(glm::dvec3 worldPos) { - - glm::dvec3 anchorNodePos(0); - - if (global::navigationHandler.orbitalNavigator().anchorNode()) { - anchorNodePos = global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition(); - } - glm::dvec3 diffPos = glm::dvec3(worldPos.x - anchorNodePos.x, worldPos.y - anchorNodePos.y, - worldPos.z - anchorNodePos.z); - - return diffPos; -} - - } // namespace openspace diff --git a/modules/base/rendering/renderablenodeline.h b/modules/base/rendering/renderablenodeline.h index 53cd54a860..5c7f4f6a88 100644 --- a/modules/base/rendering/renderablenodeline.h +++ b/modules/base/rendering/renderablenodeline.h @@ -34,11 +34,10 @@ #include namespace ghoul::opengl { class ProgramObject; } +namespace openspace::documentation { struct Documentation; } namespace openspace { -namespace documentation { struct Documentation; } - class Translation; /** @@ -52,10 +51,10 @@ public: static documentation::Documentation Documentation(); // Get the distance between the start and end node - double getDistance(); + double distance() const; - const std::string getStart(); - const std::string getEnd(); + std::string start() const; + std::string end() const; private: void initializeGL() override; @@ -69,8 +68,6 @@ private: void unbindGL(); void bindGL(); - glm::dvec3 getCoordinatePosFromAnchorNode(glm::dvec3 worldPos); - ghoul::opengl::ProgramObject* _program; /// The vertex attribute location for position /// must correlate to layout location in vertex shader diff --git a/modules/vislab/rendering/renderabledistancelabel.cpp b/modules/vislab/rendering/renderabledistancelabel.cpp index 3ff5082758..1d2cac67b8 100644 --- a/modules/vislab/rendering/renderabledistancelabel.cpp +++ b/modules/vislab/rendering/renderabledistancelabel.cpp @@ -24,13 +24,13 @@ #include -#include #include #include #include #include #include #include +#include #include namespace { @@ -39,8 +39,8 @@ namespace { constexpr openspace::properties::Property::PropertyInfo NodeLineInfo = { "NodeLine", "Node Line", - "Property to track a nodeline. When tracking the label text will be updating the distance " - "from the nodeline start and end. " + "Property to track a nodeline. When tracking the label text will be updating the " + "distance from the nodeline start and end." }; } @@ -78,38 +78,45 @@ RenderableDistanceLabel::RenderableDistanceLabel(const ghoul::Dictionary& dictio } } -void RenderableDistanceLabel::update(const UpdateData& data) { +void RenderableDistanceLabel::update(const UpdateData&) { + if (_errorThrown) { + return; + } - SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodelineId); - - if (nodelineNode && !_errorThrown) { + RenderEngine& RE = global::renderEngine; + SceneGraphNode* nodelineNode = RE.scene()->sceneGraphNode(_nodelineId); + if (nodelineNode) { // Calculate distance - RenderableNodeLine* nodeline = dynamic_cast(nodelineNode->renderable()); + RenderableNodeLine* nodeline = dynamic_cast( + nodelineNode->renderable() + ); if (!nodeline) { LERROR("Expected renderable to be of type 'RenderableNodeLine'"); _errorThrown = true; return; } - double myDistance = nodeline->getDistance(); + double myDistance = nodeline->distance(); // Format string - float scale = getUnit(Kilometer); + float scale = unit(Kilometer); std::string distanceText = std::to_string(std::round(myDistance / scale)); - int pos = distanceText.find("."); + int pos = static_cast(distanceText.find(".")); std::string subStr = distanceText.substr(pos); distanceText.erase(pos, subStr.size()); std::string finalText = distanceText + " Km"; setLabelText(finalText); // Update placement of label with transformation matrix - glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->getStart())->worldPosition(); - glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->getEnd())->worldPosition(); + SceneGraphNode* startNode = RE.scene()->sceneGraphNode(nodeline->start()); + glm::dvec3 start = startNode->worldPosition(); + SceneGraphNode* endNode = RE.scene()->sceneGraphNode(nodeline->end()); + glm::dvec3 end = endNode->worldPosition(); glm::dvec3 goalPos = start + (end - start) / 2.0; _transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos); } - else if (!_errorThrown) { + else { LERROR(fmt::format("There is no scenegraph node with id {}", _nodelineId)); _errorThrown = true; } diff --git a/modules/vislab/rendering/renderabledistancelabel.h b/modules/vislab/rendering/renderabledistancelabel.h index d6eee298f4..42f0f4165d 100644 --- a/modules/vislab/rendering/renderabledistancelabel.h +++ b/modules/vislab/rendering/renderabledistancelabel.h @@ -22,7 +22,6 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ - #ifndef __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__ #define __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__ @@ -38,6 +37,7 @@ public: void update(const UpdateData& data) override; static documentation::Documentation Documentation(); +private: properties::StringProperty _nodelineId; bool _errorThrown = false; diff --git a/modules/vislab/vislabmodule.cpp b/modules/vislab/vislabmodule.cpp index ac49e60b77..9546cc9704 100644 --- a/modules/vislab/vislabmodule.cpp +++ b/modules/vislab/vislabmodule.cpp @@ -25,14 +25,13 @@ #include #include +#include #include #include -#include namespace openspace { -VisLabModule::VisLabModule() : OpenSpaceModule(Name) { -} +VisLabModule::VisLabModule() : OpenSpaceModule(Name) {} void VisLabModule::internalInitialize(const ghoul::Dictionary&) { auto renderableFactory = FactoryManager::ref().factory(); diff --git a/modules/vislab/vislabmodule.h b/modules/vislab/vislabmodule.h index 7e43152cac..797fcde9f5 100644 --- a/modules/vislab/vislabmodule.h +++ b/modules/vislab/vislabmodule.h @@ -25,7 +25,6 @@ #ifndef __OPENSPACE_MODULE_VISLAB___VISLABMODULE___H__ #define __OPENSPACE_MODULE_VISLAB___VISLABMODULE___H__ - #include namespace openspace { @@ -38,7 +37,6 @@ public: private: void internalInitialize(const ghoul::Dictionary&) override; - }; } // namespace openspace