Skip to content

Commit

Permalink
Animation: Improve initialization management (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal authored Feb 9, 2024
1 parent 7a3bdde commit 7e6b1df
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion library/private/animationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
35 changes: 22 additions & 13 deletions library/src/animationManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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 "
Expand All @@ -105,8 +114,7 @@ void animationManager::Initialize(
// Recover time ranges for all enabled animations
this->TimeRange[0] = std::numeric_limits<double>::infinity();
this->TimeRange[1] = -std::numeric_limits<double>::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))
{
Expand All @@ -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
{
Expand All @@ -147,6 +156,7 @@ void animationManager::Initialize(
{
this->StartAnimation();
}
return true;
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -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])
Expand Down
39 changes: 23 additions & 16 deletions library/src/loader_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7e6b1df

Please sign in to comment.