1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

0028056: Draw Harness, ViewerTest - correct vanimation command to produce stable timestamp on seek

This commit is contained in:
kgv 2016-11-09 16:20:32 +03:00 committed by apn
parent 72523826de
commit bf7b2cebbe
3 changed files with 55 additions and 26 deletions

View File

@ -163,7 +163,8 @@ void AIS_Animation::UpdateTotalDuration()
//============================================================================= //=============================================================================
void AIS_Animation::StartTimer (const Standard_Real theStartPts, void AIS_Animation::StartTimer (const Standard_Real theStartPts,
const Standard_Real thePlaySpeed, const Standard_Real thePlaySpeed,
const Standard_Boolean theToUpdate) const Standard_Boolean theToUpdate,
const Standard_Boolean theToStopTimer)
{ {
if (myTimer.IsNull()) if (myTimer.IsNull())
{ {
@ -173,6 +174,11 @@ void AIS_Animation::StartTimer (const Standard_Real theStartPts,
myTimer->Seek (theStartPts); myTimer->Seek (theStartPts);
myTimer->SetPlaybackSpeed (thePlaySpeed); myTimer->SetPlaybackSpeed (thePlaySpeed);
Start (theToUpdate); Start (theToUpdate);
if (theToStopTimer)
{
myTimer->Stop();
myTimer->Seek (theStartPts);
}
} }
//============================================================================= //=============================================================================

View File

@ -101,9 +101,14 @@ public:
//! Start animation with internally defined timer instance. //! Start animation with internally defined timer instance.
//! Calls ::Start() internally. //! Calls ::Start() internally.
//! @param theStartPts starting timer position (presentation timestamp)
//! @param thePlaySpeed playback speed (1.0 means normal speed)
//! @param theToUpdate flag to update defined animations to specified start position
//! @param theToStopTimer flag to pause timer at the starting position
Standard_EXPORT virtual void StartTimer (const Standard_Real theStartPts, Standard_EXPORT virtual void StartTimer (const Standard_Real theStartPts,
const Standard_Real thePlaySpeed, const Standard_Real thePlaySpeed,
const Standard_Boolean theToUpdate); const Standard_Boolean theToUpdate,
const Standard_Boolean theToStopTimer = Standard_False);
//! Update single frame of animation, update timer state //! Update single frame of animation, update timer state
//! @return current time of timeline progress. //! @return current time of timeline progress.

View File

@ -6447,11 +6447,13 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
return 0; return 0;
} }
// animation parameters
Standard_Boolean toPlay = Standard_False; Standard_Boolean toPlay = Standard_False;
Standard_Real aPlaySpeed = 1.0; Standard_Real aPlaySpeed = 1.0;
Standard_Real aPlayStartTime = anAnimation->StartPts(); Standard_Real aPlayStartTime = anAnimation->StartPts();
Standard_Real aPlayDuration = anAnimation->Duration(); Standard_Real aPlayDuration = anAnimation->Duration();
Standard_Real aPlayFrameRate = 0.0; Standard_Integer aFpsNum = 0;
Standard_Integer aFpsDen = 1;
Standard_Boolean isFreeCamera = Standard_False; Standard_Boolean isFreeCamera = Standard_False;
Standard_Boolean isLockLoop = Standard_False; Standard_Boolean isLockLoop = Standard_False;
Handle(V3d_View) aView = ViewerTest::CurrentView(); Handle(V3d_View) aView = ViewerTest::CurrentView();
@ -6459,6 +6461,7 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
{ {
TCollection_AsciiString anArg (theArgVec[anArgIter]); TCollection_AsciiString anArg (theArgVec[anArgIter]);
anArg.LowerCase(); anArg.LowerCase();
// general options
if (anArg == "-reset" if (anArg == "-reset"
|| anArg == "-clear") || anArg == "-clear")
{ {
@ -6477,6 +6480,7 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
aParentAnimation->Remove (anAnimation); aParentAnimation->Remove (anAnimation);
} }
} }
// playback options
else if (anArg == "-play") else if (anArg == "-play")
{ {
toPlay = Standard_True; toPlay = Standard_True;
@ -6544,8 +6548,28 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
std::cout << "Syntax error at " << anArg << ".\n"; std::cout << "Syntax error at " << anArg << ".\n";
return 1; return 1;
} }
aPlayFrameRate = Draw::Atof (theArgVec[anArgIter]);
TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
if (aSplitIndex == 0)
{
aFpsNum = aFpsArg.IntegerValue();
} }
else
{
const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
aFpsArg.Split (aFpsArg.Length() - 1);
const TCollection_AsciiString aNumStr = aFpsArg;
aFpsNum = aNumStr.IntegerValue();
aFpsDen = aDenStr.IntegerValue();
if (aFpsDen < 1)
{
std::cout << "Syntax error at " << anArg << ".\n";
return 1;
}
}
}
// animation definition options
else if (anArg == "-start" else if (anArg == "-start"
|| anArg == "-starttime" || anArg == "-starttime"
|| anArg == "-startpts") || anArg == "-startpts")
@ -6805,14 +6829,14 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
TheIsAnimating = Standard_True; TheIsAnimating = Standard_True;
const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False); const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera()); Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True); anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
if (isFreeCamera) if (isFreeCamera)
{ {
aView->Camera()->Copy (aCameraBack); aView->Camera()->Copy (aCameraBack);
} }
const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration; const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
if (aPlayFrameRate < Precision::Confusion()) if (aFpsNum <= 0)
{ {
while (!anAnimation->IsStopped()) while (!anAnimation->IsStopped())
{ {
@ -6863,38 +6887,32 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
} }
else else
{ {
Standard_Real aMaxFPS = 0.0; OSD_Timer aPerfTimer;
aPerfTimer.Start();
// Manage frame-rated animation here // Manage frame-rated animation here
Standard_Real aPts = aPlayStartTime; Standard_Real aPts = aPlayStartTime;
while (aPts <= anUpperPts) int64_t aNbFrames = 0;
for (; aPts <= anUpperPts;)
{ {
const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aFpsDen) / Standard_Real(aFpsNum)) * Standard_Real(aNbFrames));
aPts = aPlayStartTime + aRecPts;
++aNbFrames;
if (!anAnimation->Update (aPts)) if (!anAnimation->Update (aPts))
{ {
break; break;
} }
Standard_Real aProgress = anAnimation->ElapsedTime();
Standard_Real aNextRatedPts = aPts + 1.0 / aPlayFrameRate;
Standard_Real aPrevPts = aPts;
aPts = aNextRatedPts < aProgress ? aNextRatedPts : aProgress;
Standard_Real aCurrentFPS = 1.0 / (aPts - aPrevPts);
if (aMaxFPS < aCurrentFPS)
{
aMaxFPS = aCurrentFPS;
}
}
if (aView->IsInvalidated())
{
aView->Redraw(); aView->Redraw();
} }
else
{ aPerfTimer.Stop();
aView->RedrawImmediate();
}
anAnimation->Stop(); anAnimation->Stop();
theDI << aMaxFPS; const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
theDI << "Average FPS: " << aRecFps << "\n"
<< "Nb. Frames: " << Standard_Real(aNbFrames);
aView->Redraw();
} }
aView->SetImmediateUpdate (wasImmediateUpdate); aView->SetImmediateUpdate (wasImmediateUpdate);