From 7e6b1df3e92570bba41163988749e92d62e18dc4 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Fri, 9 Feb 2024 14:26:00 -0800 Subject: [PATCH] Animation: Improve initialization management (#1274) --- application/testing/CMakeLists.txt | 2 +- library/private/animationManager.h | 3 ++- library/src/animationManager.cxx | 35 +++++++++++++++++---------- library/src/loader_impl.cxx | 39 ++++++++++++++++++------------ 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index 2078cdc43d..d4d281ad71 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -543,7 +543,7 @@ if(F3D_PLUGIN_BUILD_EXODUS) f3d_test(NAME TestInteractionAnimationInvert DATA small.ex2 ARGS -sb --load-plugins=exodus --animation-speed-factor=-0.0000001 --animation-time=0.00429998 INTERACTION DEFAULT_LIGHTS)#Space;Space; # Test Generic Importer Verbose animation. Regex contains the time range. - f3d_test(NAME TestVerboseAnimationSingleTimestep DATA single_timestep.e ARGS --load-plugins=exodus --verbose NO_BASELINE REGEXP "time range delta is zero") + f3d_test(NAME TestVerboseAnimationSingleTimestep DATA single_timestep.e ARGS --load-plugins=exodus --verbose NO_BASELINE REGEXP "time range delta is invalid") # Test no render animation time. Regex contains a part of the range of the ACCL field. f3d_test(NAME TestNoRenderAnimation DATA small.ex2 ARGS --load-plugins=exodus --animation-time=0.003 REGEXP "-521950, 6.57485" NO_RENDER) diff --git a/library/private/animationManager.h b/library/private/animationManager.h index c341bf26ab..aed4b3c19c 100644 --- a/library/private/animationManager.h +++ b/library/private/animationManager.h @@ -35,8 +35,9 @@ class animationManager /** * Initialize the animation manager, required before playing the animation. * Provided pointers are expected to be not null except interactor. + * Return true if at least one animation is available, false otherwise. */ - void Initialize( + bool Initialize( const options* options, window* window, interactor_impl* interactor, vtkImporter* importer); /** diff --git a/library/src/animationManager.cxx b/library/src/animationManager.cxx index e407ef1220..bc8ce6628d 100644 --- a/library/src/animationManager.cxx +++ b/library/src/animationManager.cxx @@ -16,7 +16,7 @@ namespace f3d::detail { //---------------------------------------------------------------------------- -void animationManager::Initialize( +bool animationManager::Initialize( const options* options, window* window, interactor_impl* interactor, vtkImporter* importer) { this->HasAnimation = false; @@ -63,9 +63,23 @@ void animationManager::Initialize( this->ProgressWidget = nullptr; } + int animationIndex = options->getAsInt("scene.animation.index"); + double animationTime = options->getAsDouble("scene.animation.time"); + if (availAnimations <= 0) { - log::debug("No animations available in this file"); + log::debug("No animation available in this file"); + if (animationIndex > 0) + { + log::warn("An animation index has been specified but there are no animation available."); + } + if (animationTime != 0) + { + log::warn("No animation available, cannot load a specific animation time"); + } + + this->HasAnimation = false; + return false; } else { @@ -77,12 +91,7 @@ void animationManager::Initialize( } log::debug(""); - int animationIndex = options->getAsInt("scene.animation.index"); - if (animationIndex != 0 && availAnimations <= 0) - { - log::warn("An animation index has been specified but there are no animation available."); - } - else if (animationIndex > 0 && animationIndex >= availAnimations) + if (animationIndex > 0 && animationIndex >= availAnimations) { log::warn( "Specified animation index is greater than the highest possible animation index, enabling " @@ -105,8 +114,7 @@ void animationManager::Initialize( // Recover time ranges for all enabled animations this->TimeRange[0] = std::numeric_limits::infinity(); this->TimeRange[1] = -std::numeric_limits::infinity(); - vtkIdType nbAnims = this->Importer->GetNumberOfAnimations(); - for (vtkIdType animIndex = 0; animIndex < nbAnims; animIndex++) + for (vtkIdType animIndex = 0; animIndex < availAnimations; animIndex++) { if (this->Importer->IsAnimationEnabled(animIndex)) { @@ -131,11 +139,12 @@ void animationManager::Initialize( this->HasAnimation = true; } } - if (this->TimeRange[0] == this->TimeRange[1]) + if (this->TimeRange[0] >= this->TimeRange[1]) { - log::warn("Animation(s) time range delta is zero: [", this->TimeRange[0], ", ", + log::warn("Animation(s) time range delta is invalid: [", this->TimeRange[0], ", ", this->TimeRange[1], "]. Disabling animation."); this->HasAnimation = false; + return false; } else { @@ -147,6 +156,7 @@ void animationManager::Initialize( { this->StartAnimation(); } + return true; } //---------------------------------------------------------------------------- @@ -247,7 +257,6 @@ bool animationManager::LoadAtTime(double timeValue) { if (!this->HasAnimation) { - log::warn("No animation available, cannot load a specific animation time"); return false; } if (timeValue < this->TimeRange[0] || timeValue > this->TimeRange[1]) diff --git a/library/src/loader_impl.cxx b/library/src/loader_impl.cxx index bd6237b527..e36c408b4a 100644 --- a/library/src/loader_impl.cxx +++ b/library/src/loader_impl.cxx @@ -149,15 +149,18 @@ class loader_impl::internals progressWidget->Off(); // Initialize the animation using temporal information from the importer - this->AnimationManager.Initialize( - &this->Options, &this->Window, this->Interactor, this->GenericImporter); - - double animationTime = this->Options.getAsDouble("scene.animation.time"); - double timeRange[2]; - this->AnimationManager.GetTimeRange(timeRange); - if (animationTime != timeRange[0]) + if (this->AnimationManager.Initialize( + &this->Options, &this->Window, this->Interactor, this->GenericImporter)) { - this->AnimationManager.LoadAtTime(animationTime); + double animationTime = this->Options.getAsDouble("scene.animation.time"); + double timeRange[2]; + this->AnimationManager.GetTimeRange(timeRange); + + // We assume importers import data at timeRange[0] when not specified + if (animationTime != timeRange[0]) + { + this->AnimationManager.LoadAtTime(animationTime); + } } // Display the importer description @@ -307,15 +310,19 @@ loader& loader_impl::loadScene(const std::string& filePath) progressWidget->Off(); // Initialize the animation using temporal information from the importer - this->Internals->AnimationManager.Initialize(&this->Internals->Options, &this->Internals->Window, - this->Internals->Interactor, this->Internals->CurrentFullSceneImporter); - - double animationTime = this->Internals->Options.getAsDouble("scene.animation.time"); - double timeRange[2]; - this->Internals->AnimationManager.GetTimeRange(timeRange); - if (animationTime != timeRange[0]) + if (this->Internals->AnimationManager.Initialize(&this->Internals->Options, + &this->Internals->Window, this->Internals->Interactor, + this->Internals->CurrentFullSceneImporter)) { - this->Internals->AnimationManager.LoadAtTime(animationTime); + double animationTime = this->Internals->Options.getAsDouble("scene.animation.time"); + double timeRange[2]; + this->Internals->AnimationManager.GetTimeRange(timeRange); + + // We assume importers import data at timeRange[0] when not specified + if (animationTime != timeRange[0]) + { + this->Internals->AnimationManager.LoadAtTime(animationTime); + } } // Display output description