From 570c8306906d077b0f820d979470be9290c02224 Mon Sep 17 00:00:00 2001 From: Andreas Engberg Date: Mon, 10 Nov 2025 11:30:35 +0100 Subject: [PATCH] update timeline on reducekeyframes --- .../interaction/keyframerecordinghandler.h | 2 +- src/interaction/keyframerecordinghandler.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/openspace/interaction/keyframerecordinghandler.h b/include/openspace/interaction/keyframerecordinghandler.h index 00e7ab236f..60580ed3ee 100644 --- a/include/openspace/interaction/keyframerecordinghandler.h +++ b/include/openspace/interaction/keyframerecordinghandler.h @@ -53,7 +53,7 @@ public: void play(); bool hasKeyframeRecording() const; std::vector keyframes() const; - std::vector reduceKeyframes() const; + std::vector reduceKeyframes(); static openspace::scripting::LuaLibrary luaLibrary(); diff --git a/src/interaction/keyframerecordinghandler.cpp b/src/interaction/keyframerecordinghandler.cpp index 3513a65ae6..c12c4ac2e2 100644 --- a/src/interaction/keyframerecordinghandler.cpp +++ b/src/interaction/keyframerecordinghandler.cpp @@ -216,7 +216,7 @@ SessionRecording::Entry::Camera interpolate(const SessionRecording::Entry::Camer return c; } -double isInterpolatedKeyframe(const SessionRecording::Entry::Camera& truth, +bool isInterpolatedKeyframe(const SessionRecording::Entry::Camera& truth, const SessionRecording::Entry::Camera& interpolated) { // a - b if all of the components are ideally = 0 @@ -244,7 +244,7 @@ double isInterpolatedKeyframe(const SessionRecording::Entry::Camera& truth, return posDiff < 1e-5; } -std::vector KeyframeRecordingHandler::reduceKeyframes() const { +std::vector KeyframeRecordingHandler::reduceKeyframes() { SessionRecording timeline = _timeline; //timeline.entries.reserve(_timeline.entries.size()); //const auto& entries = _timeline.entries; @@ -252,8 +252,8 @@ std::vector KeyframeRecordingHandler::reduceKeyframes() const //auto& r = timeline.entries; //r.push_back(entries[0]); - - for (size_t i = 1; i < timeline.entries.size() - 1; i++) { + size_t i = 1; + while (i < timeline.entries.size() - 1) { auto A = timeline.entries.begin() + i - 1; auto B = timeline.entries.begin() + i; auto C = timeline.entries.begin() + i + 1; @@ -303,14 +303,17 @@ std::vector KeyframeRecordingHandler::reduceKeyframes() const SessionRecording::Entry::Camera interpolated = interpolate(a, c, t); // Compare the interpolated keyframe with the existing keyframe, we only keep // keyframes that are sufficiently different - if (isInterpolatedKeyframe(b, interpolated)) { + bool shouldErase = isInterpolatedKeyframe(b, interpolated); + if (shouldErase) { timeline.entries.erase(B); - i--; + } + else { + i++; } } - + _timeline = timeline; return sessionRecordingToDictionary(timeline); }