From 5b30ed990d941657caa326a49b63be385a7a1627 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 27 Apr 2011 09:24:55 +0000 Subject: [PATCH] Added a mutex for VISU_TimeAnimation::myDumpPath member (to avoid problems with animation in batch mode) --- src/VISU_I/VISU_TimeAnimation.cxx | 49 +++++++++++++++++++++++++------ src/VISU_I/VISU_TimeAnimation.h | 6 ++-- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/VISU_I/VISU_TimeAnimation.cxx b/src/VISU_I/VISU_TimeAnimation.cxx index 497166a3..48465c85 100644 --- a/src/VISU_I/VISU_TimeAnimation.cxx +++ b/src/VISU_I/VISU_TimeAnimation.cxx @@ -118,6 +118,30 @@ namespace VISU }; + //------------------------------------------------------------------------ + class DumpPath + { + QString myPath; + QMutex myPathMutex; + public: + DumpPath(QString thePath = QString()) + : myPath(thePath) {} + + QString GetPath() { + QString aPath; + myPathMutex.lock(); + aPath = myPath; + myPathMutex.unlock(); + return aPath; + } + void SetPath(QString thePath) { + myPathMutex.lock(); + myPath = thePath; + myPathMutex.unlock(); + } + }; + + //------------------------------------------------------------------------ struct TCompositeMinMaxController : virtual TVTKMinMaxController { @@ -205,7 +229,8 @@ VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy, myAnimEntry = ""; - myDumpPath = ""; + myDumpPath = new VISU::DumpPath( "" ); + myAVIMaker = "jpeg2yuv"; myDumpMode = VISU::GetResourceMgr()->integerValue("VISU", "dump_mode", 0); @@ -231,7 +256,7 @@ VISU_TimeAnimation::~VISU_TimeAnimation() delete myExecutionState; - myDumpPath = ""; + delete myDumpPath; /* Terminates the execution of the thread. * The thread may or may not be terminated immediately, @@ -1248,7 +1273,7 @@ void VISU_TimeAnimation::parallelAnimation( bool& theIsDumping, QList& theI } } int delay = (int)(1000. * k / mySpeed); - theIsDumping = !myDumpPath.isEmpty(); + theIsDumping = !myDumpPath->GetPath().isEmpty(); if (delay < 1 && theIsDumping) { // We must unlock mutex for some time before grabbing to allow view updating delay = 1; @@ -1362,7 +1387,7 @@ void VISU_TimeAnimation::successiveAnimation( bool& theIsDumping, QList& th } } int delay = (int)(1000. * k / mySpeed); - theIsDumping = !myDumpPath.isEmpty(); + theIsDumping = !myDumpPath->GetPath().isEmpty(); if (delay < 1 && theIsDumping) { // We must unlock mutex for some time before grabbing to allow view updating delay = 1; @@ -1401,7 +1426,7 @@ void VISU_TimeAnimation::saveImages( int theFieldId, QList& theIndexList ) { if (myDumpFormat.compare("AVI") != 0) { - QString aFile(myDumpPath); + QString aFile(myDumpPath->GetPath()); int aFrameNb = myFrame; // parallel animation mode if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) // successive animation mode @@ -1426,7 +1451,7 @@ void VISU_TimeAnimation::saveImages( int theFieldId, ProcessEvent(new TMemFun2ArgEvent (myView,&SUIT_ViewWindow::dumpViewToFormat,aFile,myDumpFormat)); } else { - QFileInfo aFileInfo(myDumpPath); + QFileInfo aFileInfo(myDumpPath->GetPath()); QString aDirPath = aFileInfo.absolutePath(); QString aBaseName = aFileInfo.fileName(); @@ -1481,7 +1506,7 @@ void VISU_TimeAnimation::run() return; } - bool isDumping = !myDumpPath.isEmpty(); + bool isDumping = !myDumpPath->GetPath().isEmpty(); myFileIndex = 0; QList anIndexList; @@ -1494,7 +1519,7 @@ void VISU_TimeAnimation::run() if (isDumping && myDumpFormat.compare("AVI") == 0 && myExecutionState->IsActive()) { double aFPS = 17.3 * mySpeed / myTimeStampFrequency; - QFileInfo aFileInfo(myDumpPath); + QFileInfo aFileInfo(myDumpPath->GetPath()); QString aDirPath = aFileInfo.absolutePath(); QString aBaseName = aFileInfo.fileName(); @@ -1535,7 +1560,7 @@ void VISU_TimeAnimation::run() aCmd += QString(" -n %1").arg(myFileIndex+1); aCmd += QString(" -j \"%1\"").arg(aPattern); aCmd += " | yuv2lav"; - aCmd += QString(" -o \"%1\"").arg(myDumpPath); + aCmd += QString(" -o \"%1\"").arg(myDumpPath->GetPath()); #ifdef WIN32 aCmd += " -f aA"; #endif @@ -1671,6 +1696,12 @@ bool VISU_TimeAnimation::getIndicesFromSequence( QString theSequence, QListSetPath( QString( thePath ) ); +} + //------------------------------------------------------------------------ std::string VISU_TimeAnimation::setDumpFormat(const char* theFormat) { diff --git a/src/VISU_I/VISU_TimeAnimation.h b/src/VISU_I/VISU_TimeAnimation.h index ececa386..3618c623 100644 --- a/src/VISU_I/VISU_TimeAnimation.h +++ b/src/VISU_I/VISU_TimeAnimation.h @@ -46,6 +46,7 @@ namespace VISU //class Result_i; class ColoredPrs3d_i; class ExecutionState; + class DumpPath; } struct FieldData @@ -155,7 +156,7 @@ class VISU_I_EXPORT VISU_TimeAnimation: public QThread bool getIndicesFromSequence( QString theSequence, QList& theIndices ); - void dumpTo(const char* thePath) { myDumpPath = thePath; } + void dumpTo(const char* thePath); std::string setDumpFormat(const char* theFormat); void setTimeStampFrequency(CORBA::Long theFrequency); @@ -218,11 +219,12 @@ class VISU_I_EXPORT VISU_TimeAnimation: public QThread bool myCleaningMemoryAtEachFrame; _PTR(Study) myStudy; + VISU::DumpPath* myDumpPath; + VISU::Animation::AnimationMode myAnimationMode; double myTimeMinVal, myTimeMaxVal; //!< Range of time stams, set by user double myTimeMin , myTimeMax ; //!< Range of time stams, available for animation QString mySequence; - QString myDumpPath; QString myDumpFormat; QString myAVIMaker; long myFileIndex; -- 2.39.2