Back to index

salome-gui  6.5.0
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions
SVTK_Recorder Class Reference

#include <SVTK_Recorder.h>

Collaboration diagram for SVTK_Recorder:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 vtkTypeRevisionMacro (SVTK_Recorder, vtkObject)
void SetRenderWindow (vtkRenderWindow *theRenderWindow)
vtkRenderWindow * RenderWindow ()
void SetName (const char *theName)
const char * Name () const
void SetNbFPS (const double theNbFPS)
double NbFPS () const
void SetQuality (int theQuality)
int GetQuality () const
void SetProgressiveMode (bool theProgressiveMode)
bool GetProgressiveMode () const
void SetUseSkippedFrames (bool theUseSkippedFrames)
bool UseSkippedFrames () const
void Record ()
void Pause ()
void Stop ()
int State () const
int ErrorStatus () const
void CheckExistAVIMaker ()

Static Public Member Functions

static SVTK_RecorderNew ()

Protected Types

enum  State { SVTK_Recorder_Unknown = 0, SVTK_Recorder_Record, SVTK_Recorder_Stop }
typedef std::vector< int > TFrameIndexes

Protected Member Functions

 SVTK_Recorder ()
 ~SVTK_Recorder ()
void DoRecord ()
void MakeFileAVI ()
void AddSkippedFrames ()
void PreWrite ()

Static Protected Member Functions

static void ProcessEvents (vtkObject *theObject, unsigned long theEvent, void *theClientData, void *theCallData)

Protected Attributes

int myState
int myPaused
int myErrorStatus
float myPriority
double myTimeStart
int myFrameIndex
int myNbWrittenFrames
double myNbFPS
int myQuality
bool myProgressiveMode
TFrameIndexes myFrameIndexes
bool myUseSkippedFrames
std::string myName
std::string myNameAVIMaker
vtkCallbackCommand * myCommand
vtkRenderWindow * myRenderWindow
vtkWindowToImageFilter * myFilter
SVTK_ImageWriterMgrmyWriterMgr

Private Member Functions

 SVTK_Recorder (const SVTK_Recorder &)
void operator= (const SVTK_Recorder &)

Detailed Description

Definition at line 34 of file SVTK_Recorder.h.


Member Typedef Documentation

typedef std::vector<int> SVTK_Recorder::TFrameIndexes [protected]

Definition at line 140 of file SVTK_Recorder.h.


Member Enumeration Documentation

enum int SVTK_Recorder::State [protected]
Enumerator:
SVTK_Recorder_Unknown 
SVTK_Recorder_Record 
SVTK_Recorder_Stop 

Definition at line 37 of file SVTK_Recorder.h.


Constructor & Destructor Documentation

Definition at line 77 of file SVTK_Recorder.cxx.

               :
  myRenderWindow(NULL),
  myState(SVTK_Recorder_Stop),
  myNbFPS(5.5),
  myQuality(100),
  myProgressiveMode(true),
  myUseSkippedFrames(true),
  myErrorStatus(0),
  myCommand(vtkCallbackCommand::New()),
  myPriority(0.0),
  myTimeStart(0.0),
  myFrameIndex(0),
  myPaused(0),
  myFilter(vtkWindowToImageFilter::New()),
  myWriterMgr(new SVTK_ImageWriterMgr),
  myNbWrittenFrames(0),
  myNameAVIMaker("jpeg2yuv")
{
  myCommand->SetClientData(this); 
  myCommand->SetCallback(SVTK_Recorder::ProcessEvents);
}

Here is the call graph for this function:

Definition at line 102 of file SVTK_Recorder.cxx.

{
  myCommand->Delete();
  myFilter->Delete();
  delete myWriterMgr;
}

Member Function Documentation

Definition at line 411 of file SVTK_Recorder.cxx.

{
  myErrorStatus = 0;

  if(myFrameIndexes.size() < 2)
    return;

  size_t anId = 0, anEnd = myFrameIndexes.size() - 1;
  for(; anId < anEnd; anId++){
    int aStartIndex = myFrameIndexes[anId];
    if(aStartIndex < 0)
      continue;

    int aFinishIndex = abs(myFrameIndexes[anId + 1]);
    if(aStartIndex + 1 == aFinishIndex)
      continue;

    std::string anInitialName;
    std::ostringstream aStream;
    GetNameJPEG(myName,aStartIndex,anInitialName);
    for(int anIndex = aStartIndex + 1; anIndex < aFinishIndex; anIndex++){
      myNbWrittenFrames++;
      std::string anCurrentName;
      GetNameJPEG(myName,anIndex,anCurrentName);
  #ifndef WIN32
      aStream<<"ln -s "<< anInitialName<<" "<<anCurrentName<<";";
  #else
      aStream<<"COPY /Y "<<QString::fromStdString(anInitialName).replace("/","\\\\").toStdString()<<
                " "<<QString::fromStdString(anCurrentName).replace("/","\\\\").toStdString()<<" > NUL";
  #endif
      if(anIndex + 1 < aFinishIndex)
  #ifndef WIN32
        aStream<<" \\";
        aStream<<endl;
  #else
        aStream<<" & ";
  #endif
    }
    std::string aString(aStream.str());
    system(aString.c_str());
    if(MYDEBUG) cout<<"SVTK_Recorder::AddSkippedFrames - "<<aString<<endl;
  }
}

Definition at line 113 of file SVTK_Recorder.cxx.

{
  myErrorStatus = 0;
  std::ostringstream aStream;
#ifndef WIN32
  aStream<<"which "<<myNameAVIMaker<<" 2> /dev/null";
#else
  aStream<<"setlocal & set P2=.;%PATH% & (for %e in (%PATHEXT%) do @for %i in ("<<myNameAVIMaker<<"%e) do @if NOT \"%~$P2:i\"==\"\" exit /b 0) & exit /b 1";
#endif
  std::string anAVIMakeCheck = aStream.str();
  int iErr = system(anAVIMakeCheck.c_str());
  if(iErr != 0)
    myErrorStatus = 127;
}
void SVTK_Recorder::DoRecord ( ) [protected]

Definition at line 334 of file SVTK_Recorder.cxx.

{
  if(myPaused)
    return;

  if(myFrameIndex < 0){
    myFrameIndex = 0;
    myTimeStart = vtkTimerLog::GetUniversalTime();
  }else{
    int aFrameIndex = GetFrameIndex(myTimeStart,myNbFPS);
    if(aFrameIndex <= myFrameIndex)
      return;

    // If there was a "pause" we correct the myTimeStart
    int aLastFrameIndex = myFrameIndexes.back();
    if(aLastFrameIndex < 0){
      myFrameIndexes.back() = abs(myFrameIndexes.back());
      double aPauseTime = fabs((double)(aFrameIndex - myFrameIndex - 1)) / myNbFPS;
      if(MYDEBUG) 
        cout<<"SVTK_Recorder::DoRecord - aFrameIndex = "<<aFrameIndex<<
          "; aPauseTime = "<<aPauseTime<<endl;
      myTimeStart += aPauseTime;
    }

    aFrameIndex = GetFrameIndex(myTimeStart,myNbFPS);
    if(aFrameIndex <= myFrameIndex)
      return;

    myFrameIndex = aFrameIndex;
  }

  myFrameIndexes.push_back(myFrameIndex);
  if(MYDEBUG) cout<<"SVTK_Recorder::DoRecord - myFrameIndex = "<<myFrameIndex<<endl;

  myRenderWindow->RemoveObserver(myCommand);
  myFilter->Modified();

  std::string aName;
  GetNameJPEG(myName,myFrameIndex,aName);

  PreWrite();

  vtkImageData *anImageData = vtkImageData::New(); 
  anImageData->DeepCopy(myFilter->GetOutput());

  myWriterMgr->StartImageWriter(anImageData,aName,myProgressiveMode,myQuality);
  myNbWrittenFrames++;

  myRenderWindow->AddObserver(vtkCommand::EndEvent,
                              myCommand,
                              myPriority);
}

Here is the call graph for this function:

Definition at line 227 of file SVTK_Recorder.cxx.

{
  return myErrorStatus;
}

Definition at line 202 of file SVTK_Recorder.cxx.

{
  return myProgressiveMode;
}

Definition at line 170 of file SVTK_Recorder.cxx.

{
  return myQuality;
}

Definition at line 459 of file SVTK_Recorder.cxx.

{
  myErrorStatus = 0;
  std::ostringstream aStream;
  aStream<<myNameAVIMaker<<
    " -I p"<<
    " -v 0"<<
    //" -f "<<int(myNbFPS)<<" "<<
    " -f "<<myNbFPS<<" "<<
    " -n "<<myNbWrittenFrames<<" "<<
    " -j \""<<myName<<"_\%06d.jpeg\" "<<
    "| yuv2lav"<<" -o \""<<myName<<"\"";
#ifdef WIN32
  aStream<<" -f aA";   
#endif
  std::string aString(aStream.str());
  myErrorStatus = system(aString.c_str());

  if(MYDEBUG) cout<<"SVTK_Recorder::MakeFileAVI - "<<aString<<endl;

  QFileInfo aFileInfo(myName.c_str());
  QString aDirPath = aFileInfo.absoluteDir().path();
  QString aBaseName = aFileInfo.fileName();
  QString aCommand;
#ifndef WIN32
  aCommand = QString("(cd ") + aDirPath + 
    "; ls " +
    " | egrep '" + aBaseName + "_[0-9]*.jpeg'" +
    " | xargs rm " +
    ")";
#else
  QString tmpFile = QString("_") + aBaseName + "_tempfile";
  QString diskName = aDirPath.split("/")[0];
  aCommand = diskName + " && (cd " + aDirPath.replace("/","\\\\") + 
       " && ((dir /b | findstr " + aBaseName + "_[0-9]*.jpeg > " + tmpFile + 
       ") & (for /f %i in (" + tmpFile + ") do (del \"%i\")) & (del " + tmpFile + "))) > NUL";
#endif

  if(MYDEBUG) cout<<"SVTK_Recorder::MakeFileAVI - "<<(const char*)aCommand.toLatin1()<<endl;
  system((const char*)aCommand.toLatin1());
}
const char * SVTK_Recorder::Name ( ) const

Definition at line 138 of file SVTK_Recorder.cxx.

{
  return myName.c_str();
}
double SVTK_Recorder::NbFPS ( ) const

Definition at line 154 of file SVTK_Recorder.cxx.

{
  return myNbFPS;
}
static SVTK_Recorder* SVTK_Recorder::New ( ) [static]
void SVTK_Recorder::operator= ( const SVTK_Recorder ) [private]

Definition at line 311 of file SVTK_Recorder.cxx.

{
  myPaused = myPaused ? 0 : 1;
  if(myPaused && !myFrameIndexes.empty()){
    myFrameIndexes.back() *= -1;
    if(MYDEBUG) cout<<"SVTK_Recorder::Pause - myFrameIndexes.back() = "<<myFrameIndexes.back()<<endl;
  }
}
void SVTK_Recorder::PreWrite ( ) [protected]

Definition at line 391 of file SVTK_Recorder.cxx.

{
  vtkImageData *anImageData = myFilter->GetOutput();
  //
  if(!anImageData){
    myErrorStatus = 20;
    return;
  }
  anImageData->UpdateInformation();
  int *anExtent = anImageData->GetWholeExtent();
  anImageData->SetUpdateExtent(anExtent[0], anExtent[1],
                               anExtent[2], anExtent[3],
                               0,0);
  anImageData->UpdateData();
}
void SVTK_Recorder::ProcessEvents ( vtkObject *  theObject,
unsigned long  theEvent,
void theClientData,
void theCallData 
) [static, protected]

Definition at line 243 of file SVTK_Recorder.cxx.

{
  if(vtkObject* anObj = reinterpret_cast<vtkObject*>(theClientData)){ 
    if(SVTK_Recorder* aSelf = dynamic_cast<SVTK_Recorder*>(anObj)){
      if(theEvent==vtkCommand::EndEvent){
        if(aSelf->State() == SVTK_Recorder::SVTK_Recorder_Record){
          aSelf->DoRecord();
        }
      }
    }
  }
}

Here is the caller graph for this function:

Definition at line 263 of file SVTK_Recorder.cxx.

{
  if(myState == SVTK_Recorder_Stop){
    if(myRenderWindow){
      myState = SVTK_Recorder_Record;
      myFilter->SetInput(myRenderWindow);
      myFrameIndex = -1;
      myNbWrittenFrames = 0;
      myRenderWindow->RemoveObserver(myCommand);
      myRenderWindow->AddObserver(vtkCommand::EndEvent,
                                  myCommand,
                                  myPriority);
      myRenderWindow->Render();
    }
  }
}
vtkRenderWindow * SVTK_Recorder::RenderWindow ( )

Definition at line 186 of file SVTK_Recorder.cxx.

{
  return myRenderWindow;
}
void SVTK_Recorder::SetName ( const char *  theName)

Definition at line 132 of file SVTK_Recorder.cxx.

{
  myName = theName;
}

Here is the caller graph for this function:

void SVTK_Recorder::SetNbFPS ( const double  theNbFPS)

Definition at line 147 of file SVTK_Recorder.cxx.

{
  myNbFPS = theNbFPS;
}

Here is the caller graph for this function:

void SVTK_Recorder::SetProgressiveMode ( bool  theProgressiveMode)

Definition at line 195 of file SVTK_Recorder.cxx.

{
  myProgressiveMode = theProgressiveMode;
}

Here is the caller graph for this function:

void SVTK_Recorder::SetQuality ( int  theQuality)

Definition at line 163 of file SVTK_Recorder.cxx.

{
  myQuality = theQuality;
}

Here is the caller graph for this function:

void SVTK_Recorder::SetRenderWindow ( vtkRenderWindow *  theRenderWindow)

Definition at line 179 of file SVTK_Recorder.cxx.

{
  myRenderWindow = theRenderWindow;
}
void SVTK_Recorder::SetUseSkippedFrames ( bool  theUseSkippedFrames)

Definition at line 211 of file SVTK_Recorder.cxx.

{
  myUseSkippedFrames = theUseSkippedFrames;
}

Here is the caller graph for this function:

int SVTK_Recorder::State ( ) const

Definition at line 284 of file SVTK_Recorder.cxx.

{
  QApplication::setOverrideCursor( Qt::WaitCursor );

  if(myState == SVTK_Recorder_Record){ 
    if(!myPaused)
      DoRecord();

    myWriterMgr->Stop();

    if(myUseSkippedFrames)
      AddSkippedFrames();

    myFrameIndexes.clear();

    MakeFileAVI();
  }
  myState = SVTK_Recorder_Stop;
  myPaused = 0;

  QApplication::restoreOverrideCursor();
}

Definition at line 218 of file SVTK_Recorder.cxx.

{
  return myUseSkippedFrames;
}

Member Data Documentation

vtkCallbackCommand* SVTK_Recorder::myCommand [protected]

Definition at line 147 of file SVTK_Recorder.h.

Definition at line 128 of file SVTK_Recorder.h.

vtkWindowToImageFilter* SVTK_Recorder::myFilter [protected]

Definition at line 149 of file SVTK_Recorder.h.

int SVTK_Recorder::myFrameIndex [protected]

Definition at line 133 of file SVTK_Recorder.h.

Definition at line 141 of file SVTK_Recorder.h.

std::string SVTK_Recorder::myName [protected]

Definition at line 144 of file SVTK_Recorder.h.

std::string SVTK_Recorder::myNameAVIMaker [protected]

Definition at line 145 of file SVTK_Recorder.h.

double SVTK_Recorder::myNbFPS [protected]

Definition at line 136 of file SVTK_Recorder.h.

Definition at line 134 of file SVTK_Recorder.h.

int SVTK_Recorder::myPaused [protected]

Definition at line 127 of file SVTK_Recorder.h.

float SVTK_Recorder::myPriority [protected]

Definition at line 130 of file SVTK_Recorder.h.

Definition at line 138 of file SVTK_Recorder.h.

int SVTK_Recorder::myQuality [protected]

Definition at line 137 of file SVTK_Recorder.h.

vtkRenderWindow* SVTK_Recorder::myRenderWindow [protected]

Definition at line 148 of file SVTK_Recorder.h.

int SVTK_Recorder::myState [protected]

Definition at line 126 of file SVTK_Recorder.h.

double SVTK_Recorder::myTimeStart [protected]

Definition at line 131 of file SVTK_Recorder.h.

Definition at line 142 of file SVTK_Recorder.h.

Definition at line 150 of file SVTK_Recorder.h.


The documentation for this class was generated from the following files: