+//------------------------------------------------------------------------
+void VISU_TimeAnimation::saveImages( int theFieldId,
+ double& theOneVal, int& theNbFiles,
+ QList<int>& theIndexList )
+{
+ if (myDumpFormat.compare("AVI") != 0) {
+ QString aFile(myDumpPath);
+
+ int aFrameNb = myFrame; // parallel animation mode
+ if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) // successive animation mode
+ aFrameNb = getRelativeFrameNumber(myFrame).second;
+
+ int aMaxNb = myFieldsLst[theFieldId].myTiming.size();
+ int nbDigits = QString("%1").arg(aMaxNb).length();
+ QString aFormat = QString("%.%1d_").arg(nbDigits);
+
+ QString aName;
+ aName.sprintf(aFormat.toLatin1().data(), aFrameNb);
+ aName += QString("%1").arg(myFieldsLst[theFieldId].myTiming[aFrameNb]);
+
+ int aPos = -1;
+ while ((aPos = aName.indexOf(".")) > -1 )
+ aName.replace(aPos, 1, "_");
+ aFile += aName;
+ aFile += ".";
+ aFile += myDumpFormat.toLower();
+ ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
+ (myView,&SVTK_ViewWindow::RefreshDumpImage)); // IPAL13602
+ ProcessEvent(new TMemFun2ArgEvent<SUIT_ViewWindow,bool,const QString&,const QString&>
+ (myView,&SUIT_ViewWindow::dumpViewToFormat,aFile,myDumpFormat));
+ } else {
+ QFileInfo aFileInfo(myDumpPath);
+ QString aDirPath = aFileInfo.absolutePath();
+ QString aBaseName = aFileInfo.fileName();
+
+ if( myTimeStampFrequency > 1 && myFrame % myTimeStampFrequency != 0 )
+ return;
+
+ switch (myFrame) {
+ case 0:
+ break;
+ case 1:
+ myFileIndex += 5;
+ break;
+ default:
+ if (myProportional) {
+ FieldData& aFirstFieldData = myFieldsLst[0];
+ double p = (aFirstFieldData.myTiming[myFrame] -
+ aFirstFieldData.myTiming[myFrame-1]) / theOneVal;
+ myFileIndex += (long) (5*p);
+ } else {
+ myFileIndex += 5;
+ }
+ }
+
+ QString aFile = aDirPath + QDir::separator() + aBaseName;
+ aFile += "_";
+ aFile += QString("%1").arg(myFileIndex).rightJustified(8, '0');
+ aFile += ".jpeg";
+
+ /* check image size is divisable 16
+ myView->dumpViewToFormat(aFile,"JPEG");
+ */
+ SUIT_ViewWindow* aView = myView;
+ ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>(myView,&SVTK_ViewWindow::RefreshDumpImage)); // IPAL13602
+ QImage img = ProcessEvent(new TMemFunEvent<SUIT_ViewWindow,QImage>(aView,&SUIT_ViewWindow::dumpView));
+ if (!img.isNull()) {
+ int width = img.width(); width = (width/16)*16;
+ int height = img.height(); height = (height/16)*16;
+ QImage copy = img.copy(0, 0, width, height);
+ if (copy.save(aFile, "JPEG")) {
+ theIndexList.append(myFileIndex);
+ theNbFiles++;
+ }
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::run()
+{
+ if (!myView) {
+ MESSAGE("Viewer is not defined for animation");
+ return;
+ }
+
+ bool isDumping = !myDumpPath.isEmpty();
+ myFileIndex = 0;
+ QList<int> anIndexList;
+
+ if ( myAnimationMode == VISU::Animation::PARALLEL ) // parallel animation mode
+ parallelAnimation( isDumping, anIndexList );
+ else //successive animation mode
+ successiveAnimation( isDumping, anIndexList );
+
+ // make AVI file if need
+ if (isDumping && myDumpFormat.compare("AVI") == 0 && myExecutionState->IsActive()) {
+ double aFPS = 17.3 * mySpeed / myTimeStampFrequency;
+
+ QFileInfo aFileInfo(myDumpPath);
+ QString aDirPath = aFileInfo.absolutePath();
+ QString aBaseName = aFileInfo.fileName();
+
+ // add missing files
+ if (anIndexList.count() > 1) {
+ QString aFFile = aDirPath + "/" + aBaseName;
+ aFFile += QString("_%1.jpeg");
+ int aStartIndex = anIndexList[0], anEndIndex;
+ for (int i = 1; i < anIndexList.count(); i++) {
+ anEndIndex = anIndexList[i];
+ QString aCurFile = aFFile.arg(QString::number(aStartIndex).rightJustified(8, '0'));
+ QStringList aCommands;
+ QString aSeparator;
+ for (int j = aStartIndex+1; j < anEndIndex; j++) {
+ QString aFile = aFFile.arg(QString::number(j).rightJustified(8, '0'));
+#ifndef WIN32
+ aCommands.append(QString("ln -s %1 %2").arg(aCurFile).arg(aFile));
+ aSeparator = QString(" ; \\\n");
+#else
+ aCommands.append(QString("COPY /Y %1 %2 > NUL").arg(QString(aCurFile).replace("/","\\\\")).arg(QString(aFile).replace("/","\\\\")));
+ aSeparator = QString(" & ");
+#endif
+ }
+ system(aCommands.join(aSeparator).toLatin1().data());
+ aStartIndex = anEndIndex;
+ }
+ }
+
+ // make AVI file
+ QString aPattern = aDirPath + "/" + aBaseName;
+ aPattern += "_\%08d.jpeg";
+
+ QString aCmd = myAVIMaker;
+ aCmd += " -I p";
+ aCmd += " -v 0";
+ aCmd += QString(" -f %1").arg(aFPS);
+ // aCmd += QString(" -n %1").arg(aNbFiles);
+ aCmd += QString(" -n %1").arg(myFileIndex+1);
+ aCmd += QString(" -j \"%1\"").arg(aPattern);
+ aCmd += " | yuv2lav";
+ aCmd += QString(" -o \"%1\"").arg(myDumpPath);
+ #ifdef WIN32
+ aCmd += " -f aA";
+ #endif
+ system(aCmd.toLatin1().data());
+
+ // remove temporary jpeg files
+#ifndef WIN32
+ aCmd = "( ";
+ aCmd += QString("cd %1").arg(aDirPath);
+ aCmd += "; ls";
+ aCmd += QString(" | egrep '%1_[0-9]*.jpeg'").arg(aBaseName);
+ aCmd += " | xargs rm";
+ aCmd += " )";
+#else
+ QString tmpFile = QString("_") + aBaseName + "_tempfile";
+ QString diskName = aDirPath.split("/")[0];
+ aCmd = diskName + " && (cd " + aDirPath.replace("/","\\\\") +
+ " && ((dir /b | findstr " + aBaseName + "_[0-9]*.jpeg > " + tmpFile +
+ ") & (for /f %i in (" + tmpFile + ") do (del \"%i\")) & (del " + tmpFile + "))) > NUL";
+#endif
+ system(aCmd.toLatin1().data());
+ }
+
+ if (myExecutionState->IsActive())
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(this,&VISU_TimeAnimation::_emitStopped));
+ myExecutionState->SetActive(false);
+}
+
+//------------------------------------------------------------------------