From 1c40a62b7ba51376939194e391b1c28c78d9a7f3 Mon Sep 17 00:00:00 2001 From: Adam Rohdin Date: Wed, 22 Feb 2023 14:00:11 +0100 Subject: [PATCH 1/6] Optimizes update function for RenderableTrailTrajectory and enables iterative calcuations for the trail vertices --- .../rendering/renderabletrailtrajectory.cpp | 141 +++++++++++------- .../rendering/renderabletrailtrajectory.h | 22 +++ 2 files changed, 107 insertions(+), 56 deletions(-) diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index 8799a98c06..8e6467dbe2 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -111,6 +111,13 @@ documentation::Documentation RenderableTrailTrajectory::Documentation() { ); } +void RenderableTrailTrajectory::reset() { + _needsFullSweep = true; + _sweepIteration = 0; + _maxVertex = glm::vec3(-std::numeric_limits::max()); + _minVertex = glm::vec3(std::numeric_limits::max()); +} + RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& dictionary) : RenderableTrail(dictionary) , _startTime(StartTimeInfo) @@ -121,18 +128,18 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di { const Parameters p = codegen::bake(dictionary); - _translation->onParameterChange([this]() { _needsFullSweep = true; }); + _translation->onParameterChange([this]() { reset(); }); _startTime = p.startTime; - _startTime.onChange([this] { _needsFullSweep = true; }); + _startTime.onChange([this] { reset(); }); addProperty(_startTime); _endTime = p.endTime; - _endTime.onChange([this] { _needsFullSweep = true; }); + _endTime.onChange([this] { reset(); }); addProperty(_endTime); _sampleInterval = p.sampleInterval; - _sampleInterval.onChange([this] { _needsFullSweep = true; }); + _sampleInterval.onChange([this] { reset(); }); addProperty(_sampleInterval); _timeStampSubsamplingFactor = @@ -143,6 +150,9 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di _renderFullTrail = p.showFullTrail.value_or(_renderFullTrail); addProperty(_renderFullTrail); + _maxVertex = glm::vec3(-std::numeric_limits::max()); + _minVertex = glm::vec3(std::numeric_limits::max()); + // We store the vertices with ascending temporal order _primaryRenderInformation.sorting = RenderInformation::VertexSorting::OldestFirst; } @@ -173,50 +183,87 @@ void RenderableTrailTrajectory::deinitializeGL() { void RenderableTrailTrajectory::update(const UpdateData& data) { if (_needsFullSweep) { - // Convert the start and end time from string representations to J2000 seconds - _start = SpiceManager::ref().ephemerisTimeFromDate(_startTime); - _end = SpiceManager::ref().ephemerisTimeFromDate(_endTime); - const double totalSampleInterval = _sampleInterval / _timeStampSubsamplingFactor; - // How many values do we need to compute given the distance between the start and - // end date and the desired sample interval - const int nValues = static_cast((_end - _start) / totalSampleInterval); + if (_sweepIteration == 0) { + // Convert the start and end time from string representations to J2000 seconds + _start = SpiceManager::ref().ephemerisTimeFromDate(_startTime); + _end = SpiceManager::ref().ephemerisTimeFromDate(_endTime); - // Make space for the vertices - _vertexArray.clear(); - _vertexArray.resize(nValues); + _totalSampleInterval = _sampleInterval / _timeStampSubsamplingFactor; + + _nValues = static_cast((_end - _start) / _totalSampleInterval); - // ... fill all of the values - for (int i = 0; i < nValues; ++i) { - const glm::vec3 p = _translation->position({ - {}, - Time(_start + i * totalSampleInterval), - Time(0.0) - }); - _vertexArray[i] = { p.x, p.y, p.z }; + // Make space for the vertices + _vertexArray.clear(); + _vertexArray.resize(_nValues); + + _sweeping = true; } - // ... and upload them to the GPU - glBindVertexArray(_primaryRenderInformation._vaoID); - glBindBuffer(GL_ARRAY_BUFFER, _primaryRenderInformation._vBufferID); - glBufferData( - GL_ARRAY_BUFFER, - _vertexArray.size() * sizeof(TrailVBOLayout), - _vertexArray.data(), - GL_STATIC_DRAW - ); + + if (_sweeping) { + // Calculate sweeping range for this iteration + int startIndex = _sweepIteration * _sweepChunk; + int nextIndex = (_sweepIteration + 1) * _sweepChunk; + int stopIndex = (nextIndex < _nValues) ? nextIndex : _nValues; - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + // ... fill all of the values + for (int i = startIndex; i < stopIndex; ++i) { + const glm::vec3 p = _translation->position({ + {}, + Time(_start + i * _totalSampleInterval), + Time(0.0) + }); + _vertexArray[i] = { p.x, p.y, p.z }; - // We clear the indexArray just in case. The base class will take care not to use - // it if it is empty - _indexArray.clear(); + // Set max and min vertex for bounding sphere calculations + _maxVertex.x = std::max(_maxVertex.x, p.x); + _maxVertex.y = std::max(_maxVertex.y, p.y); + _maxVertex.z = std::max(_maxVertex.z, p.z); + + _minVertex.x = std::min(_minVertex.x, p.x); + _minVertex.y = std::min(_minVertex.y, p.y); + _minVertex.z = std::min(_minVertex.z, p.z); + } + ++_sweepIteration; + + if (stopIndex == _nValues) { + _sweepIteration = 0; + _sweeping = false; + + setBoundingSphere(glm::distance(_maxVertex, _minVertex) / 2.f); + } + } + + + if (!_sweeping) { + // ... and upload them to the GPU + glBindVertexArray(_primaryRenderInformation._vaoID); + glBindBuffer(GL_ARRAY_BUFFER, _primaryRenderInformation._vBufferID); + glBufferData( + GL_ARRAY_BUFFER, + _vertexArray.size() * sizeof(TrailVBOLayout), + _vertexArray.data(), + GL_STATIC_DRAW + ); + + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + + // We clear the indexArray just in case. The base class will take care not to use + // it if it is empty + _indexArray.clear(); + + _subsamplingIsDirty = true; + _needsFullSweep = false; + } - _subsamplingIsDirty = true; - _needsFullSweep = false; } + // Early return as we don't need to do the render portion if we are still doing a full sweep + if (_needsFullSweep) + return; + // This has to be done every update step; if (_renderFullTrail) { // If the full trail should be rendered at all times, we can directly render the @@ -299,24 +346,6 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { glBindVertexArray(0); - // Updating bounding sphere - glm::vec3 maxVertex(-std::numeric_limits::max()); - glm::vec3 minVertex(std::numeric_limits::max()); - - auto setMax = [&maxVertex, &minVertex](const TrailVBOLayout& vertexData) { - maxVertex.x = std::max(maxVertex.x, vertexData.x); - maxVertex.y = std::max(maxVertex.y, vertexData.y); - maxVertex.z = std::max(maxVertex.z, vertexData.z); - - minVertex.x = std::min(minVertex.x, vertexData.x); - minVertex.y = std::min(minVertex.y, vertexData.y); - minVertex.z = std::min(minVertex.z, vertexData.z); - }; - - std::for_each(_vertexArray.begin(), _vertexArray.end(), setMax); - - setBoundingSphere(glm::distance(maxVertex, minVertex) / 2.f); - } } // namespace openspace diff --git a/modules/base/rendering/renderabletrailtrajectory.h b/modules/base/rendering/renderabletrailtrajectory.h index d349e9e619..26209a111b 100644 --- a/modules/base/rendering/renderabletrailtrajectory.h +++ b/modules/base/rendering/renderabletrailtrajectory.h @@ -60,6 +60,13 @@ public: static documentation::Documentation Documentation(); private: + + /// Reset some variables to default state + void reset(); + + /// The number of vertices that we do calculations for during each frame of the full sweep pass + static const int _sweepChunk = 200; + /// The start time of the trail properties::StringProperty _startTime; /// The end time of the trail @@ -84,6 +91,21 @@ private: double _start = 0.0; /// The conversion of the _endTime into the internal time format double _end = 0.0; + + //tracker for sweeping + int _sweepIteration = 0; + + //flag for if the sweep is done or not + bool _sweeping = false; + + /// How many values do we need to compute given the distance between the start and end date and the desired sample interval + int _nValues = 0; + + int _totalSampleInterval = 0; + + /// Max and min vertex used to calculate the bounding sphere + glm::vec3 _maxVertex; + glm::vec3 _minVertex; }; } // namespace openspace From 23cbfd47ee9f2c0305ef990fbc54f2af09e020d2 Mon Sep 17 00:00:00 2001 From: Adam Rohdin Date: Wed, 22 Feb 2023 15:11:22 +0100 Subject: [PATCH 2/6] Updated comments and swapped a Boolean Flag for an early return --- .../rendering/renderabletrailtrajectory.cpp | 108 ++++++++---------- .../rendering/renderabletrailtrajectory.h | 5 +- 2 files changed, 49 insertions(+), 64 deletions(-) diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index 8e6467dbe2..d597362424 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -190,80 +190,68 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { _end = SpiceManager::ref().ephemerisTimeFromDate(_endTime); _totalSampleInterval = _sampleInterval / _timeStampSubsamplingFactor; - _nValues = static_cast((_end - _start) / _totalSampleInterval); // Make space for the vertices _vertexArray.clear(); _vertexArray.resize(_nValues); - - _sweeping = true; - } - - - if (_sweeping) { - // Calculate sweeping range for this iteration - int startIndex = _sweepIteration * _sweepChunk; - int nextIndex = (_sweepIteration + 1) * _sweepChunk; - int stopIndex = (nextIndex < _nValues) ? nextIndex : _nValues; - - // ... fill all of the values - for (int i = startIndex; i < stopIndex; ++i) { - const glm::vec3 p = _translation->position({ - {}, - Time(_start + i * _totalSampleInterval), - Time(0.0) - }); - _vertexArray[i] = { p.x, p.y, p.z }; - - // Set max and min vertex for bounding sphere calculations - _maxVertex.x = std::max(_maxVertex.x, p.x); - _maxVertex.y = std::max(_maxVertex.y, p.y); - _maxVertex.z = std::max(_maxVertex.z, p.z); - - _minVertex.x = std::min(_minVertex.x, p.x); - _minVertex.y = std::min(_minVertex.y, p.y); - _minVertex.z = std::min(_minVertex.z, p.z); - } - ++_sweepIteration; - - if (stopIndex == _nValues) { - _sweepIteration = 0; - _sweeping = false; - - setBoundingSphere(glm::distance(_maxVertex, _minVertex) / 2.f); - } } + // Calculate sweeping range for this iteration + int startIndex = _sweepIteration * _sweepChunk; + int nextIndex = (_sweepIteration + 1) * _sweepChunk; + int stopIndex = (nextIndex < _nValues) ? nextIndex : _nValues; - if (!_sweeping) { - // ... and upload them to the GPU - glBindVertexArray(_primaryRenderInformation._vaoID); - glBindBuffer(GL_ARRAY_BUFFER, _primaryRenderInformation._vBufferID); - glBufferData( - GL_ARRAY_BUFFER, - _vertexArray.size() * sizeof(TrailVBOLayout), - _vertexArray.data(), - GL_STATIC_DRAW - ); + // Calculate all vertex positions + for (int i = startIndex; i < stopIndex; ++i) { + const glm::vec3 p = _translation->position({ + {}, + Time(_start + i * _totalSampleInterval), + Time(0.0) + }); + _vertexArray[i] = { p.x, p.y, p.z }; - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + // Set max and min vertex for bounding sphere calculations + _maxVertex.x = std::max(_maxVertex.x, p.x); + _maxVertex.y = std::max(_maxVertex.y, p.y); + _maxVertex.z = std::max(_maxVertex.z, p.z); - // We clear the indexArray just in case. The base class will take care not to use - // it if it is empty - _indexArray.clear(); - - _subsamplingIsDirty = true; - _needsFullSweep = false; + _minVertex.x = std::min(_minVertex.x, p.x); + _minVertex.y = std::min(_minVertex.y, p.y); + _minVertex.z = std::min(_minVertex.z, p.z); } + ++_sweepIteration; + if (stopIndex == _nValues) { + _sweepIteration = 0; + setBoundingSphere(glm::distance(_maxVertex, _minVertex) / 2.f); + } + else { + // Early return as we don't need to render if we are still doing full sweep calculations + return; + } + + // Upload vertices to the GPU + glBindVertexArray(_primaryRenderInformation._vaoID); + glBindBuffer(GL_ARRAY_BUFFER, _primaryRenderInformation._vBufferID); + glBufferData( + GL_ARRAY_BUFFER, + _vertexArray.size() * sizeof(TrailVBOLayout), + _vertexArray.data(), + GL_STATIC_DRAW + ); + + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + + // We clear the indexArray just in case. The base class will take care not to use + // it if it is empty + _indexArray.clear(); + + _subsamplingIsDirty = true; + _needsFullSweep = false; } - // Early return as we don't need to do the render portion if we are still doing a full sweep - if (_needsFullSweep) - return; - // This has to be done every update step; if (_renderFullTrail) { // If the full trail should be rendered at all times, we can directly render the diff --git a/modules/base/rendering/renderabletrailtrajectory.h b/modules/base/rendering/renderabletrailtrajectory.h index 26209a111b..a8af780cc5 100644 --- a/modules/base/rendering/renderabletrailtrajectory.h +++ b/modules/base/rendering/renderabletrailtrajectory.h @@ -92,12 +92,9 @@ private: /// The conversion of the _endTime into the internal time format double _end = 0.0; - //tracker for sweeping + /// Keeps track of the sweep iteration and is used to calculate which vertices we work on each frame. int _sweepIteration = 0; - //flag for if the sweep is done or not - bool _sweeping = false; - /// How many values do we need to compute given the distance between the start and end date and the desired sample interval int _nValues = 0; From 4e519f7a1dde0df08425ec51173264bd0d1880dc Mon Sep 17 00:00:00 2001 From: Adam Rohdin Date: Thu, 23 Feb 2023 13:57:30 +0100 Subject: [PATCH 3/6] Fixed accidental change from Double to Int variable when definition was moved from local to instance. --- modules/base/rendering/renderabletrailtrajectory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/base/rendering/renderabletrailtrajectory.h b/modules/base/rendering/renderabletrailtrajectory.h index a8af780cc5..a3f6de9ef2 100644 --- a/modules/base/rendering/renderabletrailtrajectory.h +++ b/modules/base/rendering/renderabletrailtrajectory.h @@ -98,7 +98,7 @@ private: /// How many values do we need to compute given the distance between the start and end date and the desired sample interval int _nValues = 0; - int _totalSampleInterval = 0; + double _totalSampleInterval = 0.0; /// Max and min vertex used to calculate the bounding sphere glm::vec3 _maxVertex; From 89cf05eb5f4c9cdfc8af9b3f419cf9084880ed8d Mon Sep 17 00:00:00 2001 From: Adam Rohdin Date: Mon, 27 Feb 2023 10:50:24 +0100 Subject: [PATCH 4/6] Changes based on PR feedback --- .../rendering/renderabletrailtrajectory.cpp | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index d597362424..4b64354e99 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -111,13 +111,6 @@ documentation::Documentation RenderableTrailTrajectory::Documentation() { ); } -void RenderableTrailTrajectory::reset() { - _needsFullSweep = true; - _sweepIteration = 0; - _maxVertex = glm::vec3(-std::numeric_limits::max()); - _minVertex = glm::vec3(std::numeric_limits::max()); -} - RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& dictionary) : RenderableTrail(dictionary) , _startTime(StartTimeInfo) @@ -125,6 +118,8 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di , _sampleInterval(SampleIntervalInfo, 2.0, 2.0, 1e6) , _timeStampSubsamplingFactor(TimeSubSampleInfo, 1, 1, 1000000000) , _renderFullTrail(RenderFullPathInfo, false) + , _maxVertex(glm::vec3(-std::numeric_limits::max())) + , _minVertex(glm::vec3(std::numeric_limits::max())) { const Parameters p = codegen::bake(dictionary); @@ -150,9 +145,6 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di _renderFullTrail = p.showFullTrail.value_or(_renderFullTrail); addProperty(_renderFullTrail); - _maxVertex = glm::vec3(-std::numeric_limits::max()); - _minVertex = glm::vec3(std::numeric_limits::max()); - // We store the vertices with ascending temporal order _primaryRenderInformation.sorting = RenderInformation::VertexSorting::OldestFirst; } @@ -181,6 +173,13 @@ void RenderableTrailTrajectory::deinitializeGL() { RenderableTrail::deinitializeGL(); } +void RenderableTrailTrajectory::reset() { + _needsFullSweep = true; + _sweepIteration = 0; + _maxVertex = glm::vec3(-std::numeric_limits::max()); + _minVertex = glm::vec3(std::numeric_limits::max()); +} + void RenderableTrailTrajectory::update(const UpdateData& data) { if (_needsFullSweep) { @@ -200,7 +199,7 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { // Calculate sweeping range for this iteration int startIndex = _sweepIteration * _sweepChunk; int nextIndex = (_sweepIteration + 1) * _sweepChunk; - int stopIndex = (nextIndex < _nValues) ? nextIndex : _nValues; + int stopIndex = std::min(nextIndex, _nValues); // Calculate all vertex positions for (int i = startIndex; i < stopIndex; ++i) { @@ -208,17 +207,12 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { {}, Time(_start + i * _totalSampleInterval), Time(0.0) - }); + }); _vertexArray[i] = { p.x, p.y, p.z }; // Set max and min vertex for bounding sphere calculations - _maxVertex.x = std::max(_maxVertex.x, p.x); - _maxVertex.y = std::max(_maxVertex.y, p.y); - _maxVertex.z = std::max(_maxVertex.z, p.z); - - _minVertex.x = std::min(_minVertex.x, p.x); - _minVertex.y = std::min(_minVertex.y, p.y); - _minVertex.z = std::min(_minVertex.z, p.z); + _maxVertex = glm::max(_maxVertex, p); + _minVertex = glm::min(_minVertex, p); } ++_sweepIteration; From 25a6b287e7a854a0cb689cb4148d80e4c100502d Mon Sep 17 00:00:00 2001 From: Adam Rohdin Date: Thu, 2 Mar 2023 14:55:26 +0100 Subject: [PATCH 5/6] Fixed overflow bug and enabled sweepChunkSize to be set in assets --- .../rendering/renderabletrailtrajectory.cpp | 34 +++++++++++++++---- .../rendering/renderabletrailtrajectory.h | 4 +-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index 4b64354e99..5883360365 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -83,6 +83,13 @@ namespace { "'false', only the trail until the current time in the application will be shown" }; + constexpr openspace::properties::Property::PropertyInfo SweepChunkSizeInfo = { + "SweepChunkSize", + "Sweep Chunk Size", + "The number of vertices that will be calculated each frame whenever the trail needs to be recalculated. " + "A greater value will result in more calculations per frame." + }; + struct [[codegen::Dictionary(RenderableTrailTrajectory)]] Parameters { // [[codegen::verbatim(StartTimeInfo.description)]] std::string startTime [[codegen::annotation("A valid date in ISO 8601 format")]]; @@ -98,6 +105,9 @@ namespace { // [[codegen::verbatim(RenderFullPathInfo.description)]] std::optional showFullTrail; + + // [[codegen::verbatim(SweepChunkSizeInfo.description)]] + std::optional sweepChunkSize; }; #include "renderabletrailtrajectory_codegen.cpp" } // namespace @@ -145,6 +155,8 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di _renderFullTrail = p.showFullTrail.value_or(_renderFullTrail); addProperty(_renderFullTrail); + _sweepChunkSize = p.sweepChunkSize.value_or(_sweepChunkSize); + // We store the vertices with ascending temporal order _primaryRenderInformation.sorting = RenderInformation::VertexSorting::OldestFirst; } @@ -184,22 +196,32 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { if (_needsFullSweep) { if (_sweepIteration == 0) { + // Max number of vertices + constexpr unsigned int maxNumberOfVertices = 1000000; + // Convert the start and end time from string representations to J2000 seconds _start = SpiceManager::ref().ephemerisTimeFromDate(_startTime); _end = SpiceManager::ref().ephemerisTimeFromDate(_endTime); + double timespan = _end - _start; _totalSampleInterval = _sampleInterval / _timeStampSubsamplingFactor; - _nValues = static_cast((_end - _start) / _totalSampleInterval); + + // Cap _numberOfVertices in order to prevent overflow and extreme performance degredation/RAM usage + _numberOfVertices = std::min(static_cast(timespan / _totalSampleInterval), maxNumberOfVertices); + + // We need to recalcuate the _totalSampleInterval if _numberOfVertices eqals maxNumberOfVertices + // If we don't do this the position for each vertex will not be correct for the number of vertices we are doing along the trail. + _totalSampleInterval = (_numberOfVertices == maxNumberOfVertices) ? (timespan / _numberOfVertices) : _totalSampleInterval; // Make space for the vertices _vertexArray.clear(); - _vertexArray.resize(_nValues); + _vertexArray.resize(_numberOfVertices); } // Calculate sweeping range for this iteration - int startIndex = _sweepIteration * _sweepChunk; - int nextIndex = (_sweepIteration + 1) * _sweepChunk; - int stopIndex = std::min(nextIndex, _nValues); + unsigned int startIndex = _sweepIteration * _sweepChunkSize; + unsigned int nextIndex = (_sweepIteration + 1) * _sweepChunkSize; + unsigned int stopIndex = std::min(nextIndex, _numberOfVertices); // Calculate all vertex positions for (int i = startIndex; i < stopIndex; ++i) { @@ -216,7 +238,7 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { } ++_sweepIteration; - if (stopIndex == _nValues) { + if (stopIndex == _numberOfVertices) { _sweepIteration = 0; setBoundingSphere(glm::distance(_maxVertex, _minVertex) / 2.f); } diff --git a/modules/base/rendering/renderabletrailtrajectory.h b/modules/base/rendering/renderabletrailtrajectory.h index a3f6de9ef2..eb3d8e8988 100644 --- a/modules/base/rendering/renderabletrailtrajectory.h +++ b/modules/base/rendering/renderabletrailtrajectory.h @@ -65,7 +65,7 @@ private: void reset(); /// The number of vertices that we do calculations for during each frame of the full sweep pass - static const int _sweepChunk = 200; + unsigned int _sweepChunkSize = 200; /// The start time of the trail properties::StringProperty _startTime; @@ -96,7 +96,7 @@ private: int _sweepIteration = 0; /// How many values do we need to compute given the distance between the start and end date and the desired sample interval - int _nValues = 0; + unsigned int _numberOfVertices = 0; double _totalSampleInterval = 0.0; From f0f278a9a2945821415fb5bb93474f17aeb3bd4e Mon Sep 17 00:00:00 2001 From: Adam Rohdin Date: Tue, 7 Mar 2023 16:19:33 +0100 Subject: [PATCH 6/6] Updated comments in order to adhere to the repo line length standard --- .../rendering/renderabletrailtrajectory.cpp | 22 +++++++++++++------ .../rendering/renderabletrailtrajectory.h | 7 +++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index 5883360365..68120b0427 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -86,7 +86,8 @@ namespace { constexpr openspace::properties::Property::PropertyInfo SweepChunkSizeInfo = { "SweepChunkSize", "Sweep Chunk Size", - "The number of vertices that will be calculated each frame whenever the trail needs to be recalculated. " + "The number of vertices that will be calculated each frame whenever the trail " + "needs to be recalculated. " "A greater value will result in more calculations per frame." }; @@ -206,12 +207,18 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { _totalSampleInterval = _sampleInterval / _timeStampSubsamplingFactor; - // Cap _numberOfVertices in order to prevent overflow and extreme performance degredation/RAM usage - _numberOfVertices = std::min(static_cast(timespan / _totalSampleInterval), maxNumberOfVertices); + // Cap _numberOfVertices in order to prevent overflow and extreme performance + // degredation/RAM usage + _numberOfVertices = std::min( + static_cast(timespan / _totalSampleInterval), + maxNumberOfVertices + ); - // We need to recalcuate the _totalSampleInterval if _numberOfVertices eqals maxNumberOfVertices - // If we don't do this the position for each vertex will not be correct for the number of vertices we are doing along the trail. - _totalSampleInterval = (_numberOfVertices == maxNumberOfVertices) ? (timespan / _numberOfVertices) : _totalSampleInterval; + // We need to recalcuate the _totalSampleInterval if _numberOfVertices eqals + // maxNumberOfVertices. If we don't do this the position for each vertex + // will not be correct for the number of vertices we are doing along the trail. + _totalSampleInterval = (_numberOfVertices == maxNumberOfVertices) ? + (timespan / _numberOfVertices) : _totalSampleInterval; // Make space for the vertices _vertexArray.clear(); @@ -243,7 +250,8 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { setBoundingSphere(glm::distance(_maxVertex, _minVertex) / 2.f); } else { - // Early return as we don't need to render if we are still doing full sweep calculations + // Early return as we don't need to render if we are still + // doing full sweep calculations return; } diff --git a/modules/base/rendering/renderabletrailtrajectory.h b/modules/base/rendering/renderabletrailtrajectory.h index eb3d8e8988..704e072dae 100644 --- a/modules/base/rendering/renderabletrailtrajectory.h +++ b/modules/base/rendering/renderabletrailtrajectory.h @@ -64,7 +64,7 @@ private: /// Reset some variables to default state void reset(); - /// The number of vertices that we do calculations for during each frame of the full sweep pass + /// The number of vertices that we calculate during each frame of the full sweep pass unsigned int _sweepChunkSize = 200; /// The start time of the trail @@ -92,10 +92,11 @@ private: /// The conversion of the _endTime into the internal time format double _end = 0.0; - /// Keeps track of the sweep iteration and is used to calculate which vertices we work on each frame. + /// Tracks sweep iteration, is used to calculate which vertices to work on per frame int _sweepIteration = 0; - /// How many values do we need to compute given the distance between the start and end date and the desired sample interval + /// How many points do we need to compute given the distance between the + /// start and end date and the desired sample interval unsigned int _numberOfVertices = 0; double _totalSampleInterval = 0.0;