// Author :\r
// Module :\r
// $Header$\r
+\r
#include "VVTK_ImageWriter.h"\r
+\r
+#include <qsemaphore.h>\r
+\r
#include <vtkImageData.h>\r
-#include <vtkJPEGWriter.h>\r
#include <vtkImageClip.h>\r
-//\r
-//===============================================\r
-// function: VVTK_ImageWriter\r
-// purpose :\r
-//===============================================\r
-VVTK_ImageWriter::VVTK_ImageWriter()\r
-: QThread()\r
-{\r
- myName=NULL;\r
- myProgressive=0;\r
- myQuality=0;\r
- myImageData=0;\r
- myConstraint16Flag=true;\r
- myErrorStatus=0;\r
-}\r
-//===============================================\r
-// function: ~\r
-// purpose :\r
-//===============================================\r
-VVTK_ImageWriter::~VVTK_ImageWriter()\r
-{\r
-}\r
-//===============================================\r
-// function: SetName\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriter::SetName(const char *aName)\r
-{\r
- myName=(char *)aName;\r
-}\r
-//===============================================\r
-// function: Name\r
-// purpose :\r
-//===============================================\r
-const char* VVTK_ImageWriter::Name()const\r
-{\r
- return myName;\r
-}\r
-//===============================================\r
-// function: SetProgressive\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriter::SetProgressive(const int aProgressive)\r
-{\r
- myProgressive=aProgressive;\r
-}\r
-//===============================================\r
-// function: Progressive\r
-// purpose :\r
-//===============================================\r
-int VVTK_ImageWriter::Progressive()const\r
-{\r
- return myProgressive;\r
-}\r
-//===============================================\r
-// function: SetQuality\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriter::SetQuality(const int aQuality)\r
-{\r
- myQuality=aQuality;\r
-}\r
-//===============================================\r
-// function: Quality\r
-// purpose :\r
-//===============================================\r
-int VVTK_ImageWriter::Quality()const\r
-{\r
- return myQuality;\r
-}\r
-//===============================================\r
-// function: SetImageData\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriter::SetImageData(vtkImageData* pImageData)\r
-{\r
- myImageData=pImageData;\r
-}\r
-//===============================================\r
-// function: ImageData\r
-// purpose :\r
-//===============================================\r
-vtkImageData* VVTK_ImageWriter::ImageData()\r
-{\r
- return myImageData;\r
-}\r
-//===============================================\r
-// function: SetConstraint16Flag\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriter::SetConstraint16Flag(const bool aFlag)\r
-{\r
- myConstraint16Flag=aFlag;\r
-}\r
-//===============================================\r
-// function: Constraint16Flag\r
-// purpose :\r
-//===============================================\r
-bool VVTK_ImageWriter::Constraint16Flag()const\r
-{\r
- return myConstraint16Flag;\r
-}\r
-//===============================================\r
-// function: ErrorStatus\r
-// purpose :\r
-//===============================================\r
-int VVTK_ImageWriter::ErrorStatus()const\r
+#include <vtkJPEGWriter.h>\r
+#include <vtkSmartPointer.h>\r
+\r
+#ifdef _DEBUG_\r
+static int MYDEBUG = 0;\r
+#else\r
+static int MYDEBUG = 0;\r
+#endif\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+VVTK_ImageWriter\r
+::VVTK_ImageWriter(QSemaphore* theSemaphore,\r
+ vtkImageData* theImageData,\r
+ const std::string& theName,\r
+ int theProgressive,\r
+ int theQuality):\r
+ mySemaphore(theSemaphore),\r
+ myImageData(theImageData),\r
+ myName(theName),\r
+ myProgressive(theProgressive),\r
+ myQuality(theQuality),\r
+ myConstraint16Flag(true)\r
+{}\r
+\r
+//----------------------------------------------------------------------------\r
+VVTK_ImageWriter\r
+::~VVTK_ImageWriter()\r
{\r
- return myErrorStatus;\r
+ if(MYDEBUG) cout<<"VVTK_ImageWriter::~VVTK_ImageWriter - this = "<<this<<endl;\r
}\r
-//===============================================\r
-// function: run\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriter::run()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_ImageWriter\r
+::run()\r
{\r
- vtkJPEGWriter *pWriter=vtkJPEGWriter::New();\r
+ vtkJPEGWriter *aWriter = vtkJPEGWriter::New();\r
+ vtkImageData *anImageData = myImageData;\r
+ vtkSmartPointer<vtkImageClip> anImageClip;\r
//\r
- vtkImageData *pImageData=myImageData;\r
- vtkImageClip *pImageClip=NULL;\r
- //\r
- if (myConstraint16Flag){ \r
+ if(myConstraint16Flag){ \r
int uExtent[6];\r
- unsigned int width, height;\r
- //\r
myImageData->GetUpdateExtent(uExtent);\r
- width =uExtent[1]-uExtent[0]+1;\r
- height=uExtent[3]-uExtent[2]+1;\r
- width =(width/16)*16;\r
- height=(height/16)*16;\r
- uExtent[1]=uExtent[0]+width -1;\r
- uExtent[3]=uExtent[2]+height-1;\r
+ unsigned int width = uExtent[1] - uExtent[0] + 1;\r
+ unsigned int height = uExtent[3] - uExtent[2] + 1;\r
+ width = (width / 16) * 16;\r
+ height= (height / 16) * 16;\r
+ uExtent[1] = uExtent[0] + width - 1;\r
+ uExtent[3] = uExtent[2] + height - 1;\r
//\r
- pImageClip=vtkImageClip::New();\r
- pImageClip->SetInput(myImageData);\r
- pImageClip->SetOutputWholeExtent(uExtent);\r
- pImageClip->ClipDataOn();\r
- pImageData=pImageClip->GetOutput();\r
+ anImageClip = vtkImageClip::New();\r
+ anImageClip->Delete();\r
+\r
+ anImageClip->SetInput(myImageData);\r
+ anImageClip->SetOutputWholeExtent(uExtent);\r
+ anImageClip->ClipDataOn();\r
+ anImageData = anImageClip->GetOutput();\r
}\r
//\r
- pWriter->WriteToMemoryOff();\r
- pWriter->SetFileName(myName);\r
- pWriter->SetQuality(myQuality);\r
- pWriter->SetProgressive(myProgressive);\r
- pWriter->SetInput(pImageData);\r
- //\r
- pWriter->Write();\r
- //\r
- if (myConstraint16Flag){\r
- pImageClip->Delete();\r
- }\r
- pWriter->Delete();\r
- delete myName;\r
+ aWriter->WriteToMemoryOff();\r
+ aWriter->SetFileName(myName.c_str());\r
+ aWriter->SetQuality(myQuality);\r
+ aWriter->SetProgressive(myProgressive);\r
+ aWriter->SetInput(anImageData);\r
+ aWriter->Write();\r
+\r
+ aWriter->Delete();\r
myImageData->Delete();\r
+\r
+ if(MYDEBUG) cout<<"VVTK_ImageWriter::run() - this = "<<this<<endl;\r
+ *mySemaphore -= 1;\r
}\r
\r
// Author :\r
// Module :\r
// $Header$\r
+\r
+\r
#ifndef _VVTK_ImageWriter_Header_File_\r
#define _VVTK_ImageWriter_Header_File_\r
\r
#include <qthread.h>\r
+#include <string>\r
\r
class vtkImageData;\r
+class QSemaphore;\r
\r
-class VVTK_ImageWriter : public QThread {\r
-public:\r
- VVTK_ImageWriter();\r
- ~VVTK_ImageWriter();\r
- \r
- void SetName(const char *aName);\r
- const char *Name()const;\r
-\r
- void SetProgressive(const int aProgressive);\r
- int Progressive()const;\r
-\r
- void SetQuality(const int aQuality);\r
- int Quality()const;\r
\r
- void SetImageData(vtkImageData*);\r
- vtkImageData* ImageData();\r
+class VVTK_ImageWriter : public QThread \r
+{\r
+public:\r
+ VVTK_ImageWriter(QSemaphore* theSemaphore,\r
+ vtkImageData* theImageData,\r
+ const std::string& theName,\r
+ int theProgressive,\r
+ int theQuality);\r
\r
- void SetConstraint16Flag(const bool bFlag);\r
- bool Constraint16Flag()const;\r
- \r
- int ErrorStatus()const;\r
+ ~VVTK_ImageWriter();\r
\r
-protected :\r
- virtual void run();\r
- void WriteSlice();\r
+ protected:\r
+ virtual\r
+ void\r
+ run();\r
\r
-protected :\r
- char *myName;\r
+ protected:\r
+ QSemaphore* mySemaphore;\r
+ vtkImageData *myImageData;\r
+ std::string myName;\r
int myProgressive;\r
int myQuality;\r
- int myErrorStatus;\r
bool myConstraint16Flag;\r
- \r
- vtkImageData *myImageData;\r
- \r
};\r
#endif\r
// Author :\r
// Module :\r
// $Header$\r
+\r
#include "VVTK_ImageWriterMgr.h"\r
+#include "VVTK_ImageWriter.h"\r
\r
-#include <qstring.h>\r
-#include <qthread.h>\r
#include <vtkImageData.h>\r
-#include "VVTK_ImageWriter.h"\r
\r
-//===============================================\r
-// function: \r
-// purpose :\r
-//===============================================\r
-VVTK_ImageWriterMgr::VVTK_ImageWriterMgr()\r
- : QThread()\r
-{\r
- myStop=0;\r
- myErrorStatus=0;\r
-}\r
-//===============================================\r
-// function: ~\r
-// purpose :\r
-//===============================================\r
-VVTK_ImageWriterMgr::~VVTK_ImageWriterMgr()\r
-{\r
-}\r
-//===============================================\r
-// function: Stop\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriterMgr::Stop()\r
-{\r
- myStop=1;\r
-}\r
-//===============================================\r
-// function: StartImageWriter\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriterMgr::StartImageWriter(const char *aName,\r
- const int aProgressive,\r
- const int aQuality,\r
- vtkImageData *pImageData)\r
+#include <qsemaphore.h>\r
+\r
+#include <limits>\r
+\r
+\r
+#ifdef _DEBUG_\r
+static int MYDEBUG = 0;\r
+#else\r
+static int MYDEBUG = 0;\r
+#endif\r
+\r
+//----------------------------------------------------------------------------\r
+VVTK_ImageWriterMgr\r
+::VVTK_ImageWriterMgr()\r
{\r
- VVTK_ImageWriter *pIW=new VVTK_ImageWriter; \r
- //\r
- myMutex.lock();\r
- myThreads.push_back(pIW);\r
- myMutex.unlock();\r
- //\r
- pIW->SetName(aName);\r
- pIW->SetQuality(aQuality);\r
- pIW->SetProgressive(aProgressive);\r
- pIW->SetImageData(pImageData);\r
- pIW->start();\r
+ int aMax = std::numeric_limits<int>::max();\r
+ mySemaphore = new QSemaphore(aMax);\r
+ *mySemaphore += aMax;\r
}\r
-//===============================================\r
-// function: run\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriterMgr::run()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+VVTK_ImageWriterMgr\r
+::~VVTK_ImageWriterMgr()\r
{\r
- while (1) {\r
- if (myErrorStatus){\r
- return;\r
- }\r
- if(myStop) {\r
- CleanAll();\r
- break;\r
- }\r
- //\r
- msleep(1000);\r
- CleanPartial(10);\r
- }\r
+ Stop();\r
+ delete mySemaphore;\r
}\r
-//===============================================\r
-// function: CleanPartial\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriterMgr::CleanPartial(const int aNumber)\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_ImageWriterMgr\r
+::StartImageWriter(vtkImageData *theImageData,\r
+ const std::string& theName,\r
+ const int theProgressive,\r
+ const int theQuality)\r
{\r
- void *p;\r
- VVTK_ImageWriter* pIW;\r
- //\r
- std::list <void *> aList;\r
- std::list <void *>::iterator aIter;\r
- //\r
- while (myMutex.locked());\r
- //\r
- myMutex.lock();\r
- //\r
- aIter=myThreads.begin();\r
- for (; aIter != myThreads.end() ; aIter++ ){\r
- void *p=*aIter;\r
- pIW=reinterpret_cast <VVTK_ImageWriter*>(*aIter);\r
- if (pIW->ErrorStatus()){\r
- myErrorStatus=10;\r
- return;\r
- }\r
- if (pIW->finished()){ \r
- aList.push_back(pIW);\r
- if(aList.size()>aNumber){\r
- break;\r
- }\r
- }\r
- }\r
- //\r
- aIter=aList.begin();\r
- for (; aIter != aList.end(); aIter++ ){\r
- p=*aIter;\r
- myThreads.remove(p);\r
- pIW=reinterpret_cast <VVTK_ImageWriter*>(p);\r
- vtkImageData* pImageData=pIW->ImageData();\r
- delete pIW;\r
- }\r
- myMutex.unlock();\r
+ VVTK_ImageWriter *anImageWriter = \r
+ new VVTK_ImageWriter(mySemaphore,\r
+ theImageData,\r
+ theName,\r
+ theProgressive,\r
+ theQuality);\r
+ myThreads.push_back(anImageWriter);\r
+\r
+ anImageWriter->start();\r
+\r
}\r
-//===============================================\r
-// function: CleanAll\r
-// purpose :\r
-//===============================================\r
-void VVTK_ImageWriterMgr::CleanAll()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_ImageWriterMgr\r
+::Stop()\r
{\r
- void *p;\r
- VVTK_ImageWriter* pIW;\r
- //\r
- std::list <void *>::iterator aIter;\r
- //\r
- // clean all\r
- while (myMutex.locked());\r
- myMutex.lock();\r
- while (myThreads.size()) {\r
- aIter=myThreads.begin();\r
- for (; aIter != myThreads.end() ; aIter++ ){\r
- void *p=*aIter;\r
- pIW=reinterpret_cast <VVTK_ImageWriter*>(*aIter);\r
- if (pIW->ErrorStatus()){\r
- myErrorStatus=10;\r
- myStop=0;\r
- return;\r
- }\r
- if (pIW->finished()){ \r
- delete pIW;\r
- myThreads.remove(p);\r
- break;\r
- }\r
- }\r
- }\r
- myMutex.unlock();\r
- myStop=0;\r
+ if(MYDEBUG) cout<<"VVTK_ImageWriterMgr::Stop - *mySemaphore -= "<<myThreads.size()<<endl;\r
+ *mySemaphore += myThreads.size();\r
+\r
+ for(size_t anId = 0, anEnd = myThreads.size(); anId < anEnd; anId++)\r
+ delete myThreads[anId];\r
+\r
+ myThreads.clear();\r
}\r
// Author :\r
// Module :\r
// $Header$\r
+\r
#ifndef _VVTK_ImageWriterMgr_Header_File_\r
#define _VVTK_ImageWriterMgr_Header_File_\r
\r
-#include <qthread.h>\r
-#include <list>\r
-//\r
+#include <string>\r
+#include <vector>\r
+\r
class QString;\r
class vtkImageData;\r
-class QMutex;\r
-//\r
-class VVTK_ImageWriterMgr : public QThread {\r
-public:\r
+class VVTK_ImageWriter;\r
+class QSemaphore;\r
+\r
+class VVTK_ImageWriterMgr\r
+{\r
+ public:\r
VVTK_ImageWriterMgr();\r
~VVTK_ImageWriterMgr();\r
\r
- void Stop();\r
- void StartImageWriter(const char *aName,\r
- const int aProgressive,\r
- const int aQuality,\r
- vtkImageData *pImageData);\r
- int ErrorStatus()const;\r
-\r
-protected :\r
- virtual void run();\r
- void CleanAll();\r
- void CleanPartial(const int aNumber);\r
-\r
-protected :\r
- int myStop;\r
- int myErrorStatus;\r
- std::list <void *> myThreads;\r
- QMutex myMutex;\r
+ void\r
+ StartImageWriter(vtkImageData *theImageData,\r
+ const std::string& theName,\r
+ const int theProgressive,\r
+ const int theQuality);\r
+\r
+ void\r
+ Stop();\r
+\r
+ protected:\r
+ typedef std::vector<VVTK_ImageWriter*> TWriterThreads;\r
+ TWriterThreads myThreads;\r
+\r
+ QSemaphore* mySemaphore;\r
};\r
+\r
+\r
#endif\r
\r
myStopAction->addTo( myRecordingToolBar );
connect( myStopAction, SIGNAL( activated() ), this, SLOT( OnStopRecording() ) );
- myRecorder=VVTK_Recorder::New();
+ myRecorder = VVTK_Recorder::New();
myRecorder->CheckExistAVIMaker();
- if (myRecorder->ErrorStatus()){
+ if(myRecorder->ErrorStatus())
myRecordingToolBar->setEnabled(false);
- }
}
//----------------------------------------------------------------------------
VVTK_MainWindow
::Initialize(SVTK_RenderWindowInteractor* theInteractor)
{
- vtkInteractorStyle* pVIS=theInteractor->GetInteractorStyle();
- SVTK_InteractorStyle *pInteractorStyle=dynamic_cast<SVTK_InteractorStyle*>(pVIS);
- if (pInteractorStyle){
- pInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer());
- pInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer());
+ vtkInteractorStyle* aStyle = theInteractor->GetInteractorStyle();
+ if(SVTK_InteractorStyle *anInteractorStyle = dynamic_cast<SVTK_InteractorStyle*>(aStyle)){
+ anInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer());
+ anInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer());
}
+
+ myRecorder->SetNbFPS(17.3);
+ myRecorder->SetQuality(100);
+ myRecorder->SetProgressiveMode(true);
+ myRecorder->SetUseSkippedFrames(true);
+ myRecorder->SetRenderWindow(theInteractor->getRenderWindow());
+
SVTK_MainWindow::Initialize(theInteractor);
}
VVTK_MainWindow::~VVTK_MainWindow()
{
- if (myRecorder){
+ if(myRecorder)
myRecorder->Delete();
- }
}
//----------------------------------------------------------------------------
void VVTK_MainWindow::OnStartRecording()
{
- //QString aFileName = "/data/pkv/IMAGES/TMP/abc";
- QString aFileName=QFileDialog::getSaveFileName( getenv( "HOME"), "*.avi", this );
- if( aFileName.isNull() ){
+ QString aFileName = QFileDialog::getSaveFileName( getenv( "HOME"), "*.avi", this );
+ if(aFileName.isNull())
return;
- }
- //
myStartAction->setEnabled( false );
myPlayAction->setEnabled( false );
myPauseAction->setEnabled( true );
myStopAction->setEnabled( true );
- //
- //====
- SVTK_RenderWindowInteractor* pInteractor=GetInteractor();
- vtkRenderWindow* pRenderWindow=pInteractor->getRenderWindow();
- //
+
myRecorder->SetName(aFileName.latin1());
- myRecorder->SetNbFPS(10);
- myRecorder->SetRenderWindow(pRenderWindow);
- //
myRecorder->Record();
}
#include <vtkJPEGWriter.h>\r
#include <vtkImageData.h>\r
\r
+#include <sstream>\r
+#include <iomanip>\r
+#include <iostream>\r
+\r
#include <unistd.h>\r
+#include <qapplication.h>\r
#include <qfileinfo.h>\r
\r
+#include "utilities.h"\r
\r
-static \r
- void GetNameJPEG(const char *pName, \r
- const int aIndex,\r
- char *pNameJPEG);\r
-//\r
+#ifdef _DEBUG_\r
+static int MYDEBUG = 0;\r
+#else\r
+static int MYDEBUG = 0;\r
+#endif\r
+\r
+\r
+namespace\r
+{\r
+ //----------------------------------------------------------------------------\r
+ inline\r
+ void\r
+ GetNameJPEG(const std::string& thePreffix, \r
+ const int theIndex,\r
+ std::string& theName)\r
+ {\r
+ using namespace std;\r
+ ostringstream aStream;\r
+ aStream<<thePreffix<<"_"<<setw(6)<<setfill('0')<<theIndex<<".jpeg";\r
+ theName = aStream.str();\r
+ }\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
vtkCxxRevisionMacro(VVTK_Recorder,"$Revision$");\r
vtkStandardNewMacro(VVTK_Recorder);\r
-//===============================================\r
-// function: VVTK_Recorder\r
-// purpose :\r
-//=============================================== \r
-VVTK_Recorder::VVTK_Recorder()\r
- : vtkObject()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+VVTK_Recorder\r
+::VVTK_Recorder():\r
+ myRenderWindow(NULL),\r
+ myState(VVTK_Recorder_Stop),\r
+ myNbFPS(5.5),\r
+ myQuality(100),\r
+ myProgressiveMode(true),\r
+ myUseSkippedFrames(true),\r
+ myErrorStatus(0),\r
+ myCommand(vtkCallbackCommand::New()),\r
+ myPriority(0.0),\r
+ myTimeStart(0.0),\r
+ myFrameIndex(0),\r
+ myPaused(0),\r
+ myFilter(vtkWindowToImageFilter::New()),\r
+ myWriterMgr(new VVTK_ImageWriterMgr),\r
+ myNbWrittenFrames(0),\r
+ myNameAVIMaker("jpeg2yuv")\r
{\r
- myRenderWindow=NULL;\r
- myFilter=NULL;\r
- myState=VVTK_Recorder_Stop;\r
- myNbFPS=10.;\r
- myErrorStatus=0;\r
- myCommand=vtkCallbackCommand::New();\r
myCommand->SetClientData(this); \r
myCommand->SetCallback(VVTK_Recorder::ProcessEvents);\r
- //\r
- myPriority=0.;\r
- myTimeStart=0.;\r
- myFrameIndex=0;\r
- myPaused=0;\r
- //\r
- myFilter=vtkWindowToImageFilter::New();\r
- myWriterMgr=new VVTK_ImageWriterMgr;\r
- myName=new char [512];\r
- myName[0]=0;\r
- myNbWrittenFrames=0;\r
- //\r
- myNameAVIMaker=new char[32];\r
- strcpy (myNameAVIMaker, "jpeg2yuv");\r
}\r
-//===============================================\r
-// function: ~\r
-// purpose :\r
-//=============================================== \r
-VVTK_Recorder::~VVTK_Recorder()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+VVTK_Recorder\r
+::~VVTK_Recorder()\r
{\r
myCommand->Delete();\r
myFilter->Delete();\r
delete myWriterMgr;\r
- delete myName;\r
- delete myNameAVIMaker;\r
}\r
-//===============================================\r
-// function: CheckExistAVIMaker\r
-// purpose :\r
-//=============================================== \r
-void VVTK_Recorder::CheckExistAVIMaker()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::CheckExistAVIMaker()\r
{\r
- int iErr, iES;\r
- //\r
- myErrorStatus=0;\r
- std::string anAVIMakeCheck("which ");\r
- anAVIMakeCheck += myNameAVIMaker;\r
- anAVIMakeCheck += " >& /dev/null";\r
- iErr=system(anAVIMakeCheck.c_str());\r
- iErr=WEXITSTATUS(iErr);\r
- if (iErr==127){\r
- myErrorStatus=iErr;\r
- }\r
+ myErrorStatus = 0;\r
+ using namespace std;\r
+ ostringstream aStream;\r
+ aStream<<"which "<<myNameAVIMaker<<" >& /dev/null";\r
+ std::string anAVIMakeCheck = aStream.str();\r
+ int iErr = system(anAVIMakeCheck.c_str());\r
+ if(iErr != 0)\r
+ myErrorStatus = 127;\r
}\r
-//===============================================\r
-// function: DoPlay\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::DoPlay()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::SetName(const char* theName)\r
{\r
+ myName = theName;\r
}\r
-//===============================================\r
-// function: DoStop\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::DoStop()\r
+\r
+const char* \r
+VVTK_Recorder::Name() const\r
{\r
+ return myName.c_str();\r
}\r
-//===============================================\r
-// function: SetName\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::SetName(const char* theName)\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::SetNbFPS(const double theNbFPS)\r
{\r
- strcpy(myName, theName);\r
+ myNbFPS = theNbFPS;\r
}\r
-//===============================================\r
-// function: Name\r
-// purpose :\r
-//===============================================\r
-const char* VVTK_Recorder::Name()const\r
+\r
+double\r
+VVTK_Recorder\r
+::NbFPS() const\r
{\r
- return myName;\r
+ return myNbFPS;\r
}\r
-//===============================================\r
-// function: SetNbFPS\r
-// purpose :\r
-//=============================================== \r
-void VVTK_Recorder::SetNbFPS(const double theNb)\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::SetQuality(int theQuality)\r
{\r
- myNbFPS=theNb;\r
+ myQuality = theQuality;\r
}\r
-//===============================================\r
-// function: NbFPS\r
-// purpose :\r
-//=============================================== \r
-double VVTK_Recorder::NbFPS()const\r
+\r
+int\r
+VVTK_Recorder\r
+::GetQuality() const\r
{\r
- return myNbFPS;\r
+ return myQuality;\r
}\r
-//===============================================\r
-// function: SetRenderWindow\r
-// purpose :\r
-//=============================================== \r
-void VVTK_Recorder::SetRenderWindow(vtkRenderWindow* pW)\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void \r
+VVTK_Recorder\r
+::SetRenderWindow(vtkRenderWindow* theRenderWindow)\r
{\r
- myRenderWindow=pW;\r
+ myRenderWindow = theRenderWindow;\r
}\r
-//===============================================\r
-// function: RenderWindow\r
-// purpose :\r
-//=============================================== \r
-vtkRenderWindow* VVTK_Recorder::RenderWindow()\r
+\r
+vtkRenderWindow* \r
+VVTK_Recorder\r
+::RenderWindow()\r
{\r
return myRenderWindow;\r
}\r
-//===============================================\r
-// function: ErrorStatus\r
-// purpose :\r
-//=============================================== \r
-int VVTK_Recorder::ErrorStatus()const\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::SetProgressiveMode(bool theProgressiveMode)\r
+{\r
+ myProgressiveMode = theProgressiveMode;\r
+}\r
+\r
+bool\r
+VVTK_Recorder\r
+::GetProgressiveMode() const\r
+{\r
+ return myProgressiveMode;\r
+}\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::SetUseSkippedFrames(bool theUseSkippedFrames)\r
+{\r
+ myUseSkippedFrames = theUseSkippedFrames;\r
+}\r
+\r
+bool\r
+VVTK_Recorder\r
+::UseSkippedFrames() const\r
+{\r
+ return myUseSkippedFrames;\r
+}\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+int\r
+VVTK_Recorder\r
+::ErrorStatus() const\r
{\r
return myErrorStatus;\r
}\r
-//===============================================\r
-// function: State\r
-// purpose :\r
-//=============================================== \r
-int VVTK_Recorder::State()const\r
+\r
+int\r
+VVTK_Recorder\r
+::State() const\r
{\r
return myState;\r
}\r
-//===============================================\r
-// function: ProcessEvents\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::ProcessEvents(vtkObject* vtkNotUsed(theObject), \r
- unsigned long theEvent,\r
- void* theClientData, \r
- void* vtkNotUsed(theCallData))\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::ProcessEvents(vtkObject* vtkNotUsed(theObject), \r
+ unsigned long theEvent,\r
+ void* theClientData, \r
+ void* vtkNotUsed(theCallData))\r
{\r
- if(vtkObject* anObj=reinterpret_cast<vtkObject*>(theClientData)){ \r
- if(VVTK_Recorder* aSelf=dynamic_cast<VVTK_Recorder*>(anObj)){\r
+ if(vtkObject* anObj = reinterpret_cast<vtkObject*>(theClientData)){ \r
+ if(VVTK_Recorder* aSelf = dynamic_cast<VVTK_Recorder*>(anObj)){\r
if(theEvent==vtkCommand::EndEvent){\r
if(aSelf->State() == VVTK_Recorder::VVTK_Recorder_Record){\r
aSelf->DoRecord();\r
}\r
}\r
\r
-//===============================================\r
-// function: Record\r
-// purpose :\r
-//=============================================== \r
-void VVTK_Recorder::Record()\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::Record()\r
{\r
- if (myState==VVTK_Recorder_Stop){\r
- if (myRenderWindow){\r
- myState=VVTK_Recorder_Record;\r
- //\r
+ if(myState == VVTK_Recorder_Stop){\r
+ if(myRenderWindow){\r
+ myState = VVTK_Recorder_Record;\r
myFilter->SetInput(myRenderWindow);\r
- //\r
- myFrameIndex=-1;\r
- myNbWrittenFrames=0;\r
- //\r
+ myFrameIndex = -1;\r
+ myNbWrittenFrames = 0;\r
myRenderWindow->RemoveObserver(myCommand);\r
myRenderWindow->AddObserver(vtkCommand::EndEvent,\r
myCommand,\r
}\r
}\r
}\r
-//===============================================\r
-// function: Play\r
-// purpose :\r
-//=============================================== \r
-void VVTK_Recorder::Play()\r
-{\r
- if (myState==VVTK_Recorder_Stop){\r
- if (myRenderWindow){\r
- myState=VVTK_Recorder_Play;\r
- }\r
- }\r
-}\r
-//===============================================\r
-// function: Stop\r
-// purpose :\r
-//=============================================== \r
-void VVTK_Recorder::Stop()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::Stop()\r
{\r
- if (myState==VVTK_Recorder_Record) { \r
+ QApplication::setOverrideCursor( Qt::waitCursor );\r
+\r
+ if(myState == VVTK_Recorder_Record){ \r
+ if(!myPaused)\r
+ DoRecord();\r
+\r
myWriterMgr->Stop();\r
- AddSkippedFrames();\r
+\r
+ if(myUseSkippedFrames)\r
+ AddSkippedFrames();\r
+\r
+ myFrameIndexes.clear();\r
+\r
MakeFileAVI();\r
}\r
- if (myState==VVTK_Recorder_Play){\r
- //...\r
- }\r
- myState=VVTK_Recorder_Stop;\r
+ myState = VVTK_Recorder_Stop;\r
+ myPaused = 0;\r
+\r
+ QApplication::restoreOverrideCursor();\r
}\r
-//===============================================\r
-// function: Pause\r
-// purpose :\r
-//=============================================== \r
-void VVTK_Recorder::Pause()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::Pause()\r
{\r
- myPaused=myPaused ? 0 : 1;\r
+ myPaused = myPaused ? 0 : 1;\r
+ if(myPaused && !myFrameIndexes.empty()){\r
+ size_t aLastId = myFrameIndexes.size() - 1;\r
+ myFrameIndexes[aLastId] *= -1;\r
+ }\r
}\r
-//===============================================\r
-// function: DoRecord\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::DoRecord()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::DoRecord()\r
{\r
- if (myPaused){\r
+ if(myPaused)\r
return;\r
- }\r
- //\r
- char *buf, aPrefix[512];\r
- double aTimeNow, dT;\r
- int aFrameIndex, aQuality, aProgressive;\r
- //\r
- if (myFrameIndex<0) {\r
- myFrameIndex=0;\r
- myTimeStart=vtkTimerLog::GetCurrentTime();\r
- //\r
- myWriterMgr->start();\r
- //\r
- }\r
- else {\r
- aTimeNow=vtkTimerLog::GetCurrentTime();\r
- dT=aTimeNow-myTimeStart;\r
- if (dT<0.){\r
- //printf(" * DoRecord() dT<0 returned\n");\r
+\r
+ if(myFrameIndex < 0){\r
+ myFrameIndex = 0;\r
+ myTimeStart = vtkTimerLog::GetCurrentTime();\r
+ }else{\r
+ double aTimeNow = vtkTimerLog::GetCurrentTime();\r
+ double aDelta = aTimeNow - myTimeStart;\r
+ if(aDelta < 0.0)\r
return;\r
- }\r
- aFrameIndex=(int)(dT*myNbFPS);\r
- if (aFrameIndex==myFrameIndex) {\r
+\r
+ int aFrameIndex = int(aDelta*myNbFPS);\r
+ if(aFrameIndex == myFrameIndex)\r
return;\r
- }\r
- myFrameIndex=aFrameIndex;\r
+\r
+ myFrameIndex = aFrameIndex;\r
}\r
- //\r
+\r
+ myFrameIndexes.push_back(myFrameIndex);\r
+ if(MYDEBUG) cout<<"VVTK_Recorder::DoRecord - myFrameIndex = "<<myFrameIndex<<endl;\r
+\r
myRenderWindow->RemoveObserver(myCommand);\r
- //\r
myFilter->Modified();\r
- //\r
- buf=new char [512];\r
- GetNameJPEG(myName, myFrameIndex, buf);\r
- //printf(" *buf: %s\n", buf);\r
- //\r
+\r
+ std::string aName;\r
+ GetNameJPEG(myName,myFrameIndex,aName);\r
+\r
PreWrite();\r
- //===============\r
- //\r
- aQuality=95;\r
- aProgressive=1;\r
- vtkImageData *pC=vtkImageData::New(); \r
- pC->DeepCopy(myFilter->GetOutput());\r
- //\r
- myWriterMgr->StartImageWriter(buf, aProgressive, aQuality, pC);\r
- ++myNbWrittenFrames;\r
- //\r
- //===============\r
+\r
+ vtkImageData *anImageData = vtkImageData::New(); \r
+ anImageData->DeepCopy(myFilter->GetOutput());\r
+\r
+ myWriterMgr->StartImageWriter(anImageData,aName,myProgressiveMode,myQuality);\r
+ myNbWrittenFrames++;\r
+\r
myRenderWindow->AddObserver(vtkCommand::EndEvent,\r
myCommand,\r
myPriority);\r
}\r
-//===============================================\r
-// function: PreWrite\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::PreWrite()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::PreWrite()\r
{\r
- vtkImageData *pImageData=myFilter->GetOutput();\r
+ vtkImageData *anImageData = myFilter->GetOutput();\r
//\r
- if (!pImageData){\r
- myErrorStatus=20;\r
+ if(!anImageData){\r
+ myErrorStatus = 20;\r
return;\r
}\r
- pImageData->UpdateInformation();\r
- int *wExtent=pImageData->GetWholeExtent();\r
- pImageData->SetUpdateExtent(wExtent[0], wExtent[1],\r
- wExtent[2], wExtent[3],\r
- 0,0);\r
- pImageData->UpdateData();\r
+ anImageData->UpdateInformation();\r
+ int *anExtent = anImageData->GetWholeExtent();\r
+ anImageData->SetUpdateExtent(anExtent[0], anExtent[1],\r
+ anExtent[2], anExtent[3],\r
+ 0,0);\r
+ anImageData->UpdateData();\r
}\r
-//===============================================\r
-// function: AddSkippedFrames\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::AddSkippedFrames()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::AddSkippedFrames()\r
{\r
- myErrorStatus=0;\r
- //...\r
+ myErrorStatus = 0;\r
+\r
+ if(myFrameIndexes.size() < 2)\r
+ return;\r
+\r
+ size_t anId = 0, anEnd = myFrameIndexes.size() - 1;\r
+ for(; anId < anEnd; anId++){\r
+ int aStartIndex = myFrameIndexes[anId];\r
+ if(aStartIndex < 0)\r
+ continue;\r
+\r
+ int aFinishIndex = abs(myFrameIndexes[anId + 1]);\r
+ if(aStartIndex + 1 == aFinishIndex)\r
+ continue;\r
+\r
+ std::string anInitialName;\r
+ std::ostringstream aStream;\r
+ GetNameJPEG(myName,aStartIndex,anInitialName);\r
+ for(int anIndex = aStartIndex + 1; anIndex < aFinishIndex; anIndex++){\r
+ myNbWrittenFrames++;\r
+ std::string anCurrentName;\r
+ GetNameJPEG(myName,anIndex,anCurrentName);\r
+ aStream<<"ln -s "<< anInitialName<<" "<<anCurrentName<<";";\r
+ if(anIndex + 1 < aFinishIndex)\r
+ aStream<<" \\";\r
+ aStream<<endl;\r
+ }\r
+ std::string aString(aStream.str());\r
+ system(aString.c_str());\r
+ if(MYDEBUG) cout<<"VVTK_Recorder::AddSkippedFrames - "<<aString<<endl;\r
+ }\r
}\r
-//===============================================\r
-// function: MakeFileAVI\r
-// purpose :\r
-//===============================================\r
-void VVTK_Recorder::MakeFileAVI()\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void\r
+VVTK_Recorder\r
+::MakeFileAVI()\r
{\r
- myErrorStatus=0;\r
- //\r
- int iNbFPS;\r
- char aCmd[1024], fmt[]={"_\%06d.jpeg"};\r
- //"jpeg2yuv -f 10 -I p -n 16 -v 0 -j abcx_1%06d.jpeg | yuv2lav -o z.avi" \r
- //\r
- iNbFPS=(int)myNbFPS;\r
- sprintf(aCmd, "%s -I p -v 0 -f %d -n %d -j %s%s | yuv2lav -o %s.avi",\r
- myNameAVIMaker, iNbFPS, myNbWrittenFrames, myName, fmt, myName);\r
- //\r
- myErrorStatus=system(aCmd);\r
+ myErrorStatus = 0;\r
+ std::ostringstream aStream;\r
+ aStream<<myNameAVIMaker<<\r
+ " -I p"<<\r
+ " -v 0"<<\r
+ //" -f "<<int(myNbFPS)<<" "<<\r
+ " -f "<<myNbFPS<<" "<<\r
+ " -n "<<myNbWrittenFrames<<" "<<\r
+ " -j "<<myName<<"_\%06d.jpeg "<<\r
+ "| yuv2lav"<<\r
+ " -o "<<myName<<".avi";\r
+ \r
+ std::string aString(aStream.str());\r
+ myErrorStatus = system(aString.c_str());\r
+\r
+ if(MYDEBUG) cout<<"VVTK_Recorder::MakeFileAVI - "<<aString<<endl;\r
\r
QFileInfo aFileInfo(myName);\r
QString aDirPath = aFileInfo.dirPath(TRUE);\r
" | egrep '" + aBaseName + "_[0-9]*.jpeg'" +\r
" | xargs rm " +\r
")";\r
+\r
+ if(MYDEBUG) cout<<"VVTK_Recorder::MakeFileAVI - "<<aCommand.latin1()<<endl;\r
system(aCommand.latin1());\r
}\r
-//===============================================\r
-// function: GetNameJPEG\r
-// purpose :\r
-//===============================================\r
-void GetNameJPEG(const char *pName, \r
- const int aIndex,\r
- char *pNameJPEG)\r
-{\r
- sprintf(pNameJPEG, "%s_%06d.jpeg", pName, aIndex);\r
-}\r
-\r
#define _VVTK_Recorder_Header_File_\r
\r
#include <list>\r
+#include <string>\r
+#include <vector>\r
+\r
#include <vtkObject.h>\r
\r
class vtkRenderWindow;\r
class vtkWindowToImageFilter;\r
class VVTK_ImageWriterMgr;\r
//\r
-class VVTK_Recorder : public vtkObject {\r
-\r
-protected:\r
+class VVTK_Recorder : public vtkObject \r
+{\r
+ protected:\r
enum State {\r
VVTK_Recorder_Unknown=0,\r
VVTK_Recorder_Record,\r
- VVTK_Recorder_Play,\r
VVTK_Recorder_Stop\r
};\r
-\r
-public:\r
+ \r
+ public:\r
static VVTK_Recorder *New();\r
vtkTypeRevisionMacro(VVTK_Recorder,vtkObject);\r
- //\r
- void SetRenderWindow(vtkRenderWindow* pW);\r
- vtkRenderWindow* RenderWindow();\r
- //\r
- void SetName(const char *theName);\r
- const char* Name()const;\r
- //\r
- void SetNbFPS(const double theNbFPS);\r
- double NbFPS()const;\r
- //\r
- void Record();\r
- void Play();\r
- void Pause();\r
- void Stop();\r
- //\r
- int State()const;\r
- int ErrorStatus()const;\r
-\r
- static void ProcessEvents(vtkObject* theObject, \r
- unsigned long theEvent,\r
- void* theClientData, \r
- void* theCallData);\r
-\r
- void CheckExistAVIMaker();\r
- //\r
+\r
+ void\r
+ SetRenderWindow(vtkRenderWindow* theRenderWindow);\r
+\r
+ vtkRenderWindow* \r
+ RenderWindow();\r
+\r
+ void \r
+ SetName(const char *theName);\r
+\r
+ const char* \r
+ Name() const;\r
+\r
+ void\r
+ SetNbFPS(const double theNbFPS);\r
+\r
+ double\r
+ NbFPS() const;\r
+\r
+ void\r
+ SetQuality(int theQuality);\r
+\r
+ int\r
+ GetQuality() const;\r
+\r
+ void\r
+ SetProgressiveMode(bool theProgressiveMode);\r
+\r
+ bool\r
+ GetProgressiveMode() const;\r
+\r
+ void\r
+ SetUseSkippedFrames(bool theUseSkippedFrames);\r
+\r
+ bool\r
+ UseSkippedFrames() const;\r
+\r
+ void\r
+ Record();\r
+\r
+ void\r
+ Pause();\r
+\r
+ void\r
+ Stop();\r
+\r
+ int\r
+ State() const;\r
+\r
+ int \r
+ ErrorStatus() const;\r
+\r
+ void\r
+ CheckExistAVIMaker();\r
+\r
protected :\r
VVTK_Recorder();\r
+\r
~VVTK_Recorder();\r
- void DoRecord();\r
- void DoPlay();\r
- void DoStop();\r
- void MakeFileAVI();\r
- void AddSkippedFrames();\r
- void PreWrite();\r
- //\r
+\r
+ void\r
+ DoRecord();\r
+\r
+ void\r
+ MakeFileAVI();\r
+\r
+ void\r
+ AddSkippedFrames();\r
+\r
+ void\r
+ PreWrite();\r
+\r
+ static\r
+ void\r
+ ProcessEvents(vtkObject* theObject, \r
+ unsigned long theEvent,\r
+ void* theClientData, \r
+ void* theCallData);\r
+\r
protected :\r
- int myState;\r
- int myPaused;\r
- double myNbFPS;\r
- int myErrorStatus;\r
- int myFrameIndex;\r
- int myNbWrittenFrames;\r
- float myPriority;\r
- double myTimeStart;\r
- char *myName;\r
-\r
- vtkCallbackCommand *myCommand;\r
- vtkRenderWindow *myRenderWindow;\r
+ int myState;\r
+ int myPaused;\r
+ int myErrorStatus;\r
+\r
+ float myPriority;\r
+ double myTimeStart;\r
+\r
+ int myFrameIndex;\r
+ int myNbWrittenFrames;\r
+\r
+ double myNbFPS;\r
+ int myQuality;\r
+ bool myProgressiveMode;\r
+\r
+ typedef std::vector<int> TFrameIndexes;\r
+ TFrameIndexes myFrameIndexes;\r
+ bool myUseSkippedFrames;\r
+\r
+ std::string myName;\r
+ std::string myNameAVIMaker;\r
+\r
+ vtkCallbackCommand *myCommand;\r
+ vtkRenderWindow *myRenderWindow;\r
vtkWindowToImageFilter *myFilter;\r
- VVTK_ImageWriterMgr *myWriterMgr;\r
+ VVTK_ImageWriterMgr *myWriterMgr;\r
\r
- char *myNameAVIMaker;\r
\r
private:\r
VVTK_Recorder(const VVTK_Recorder&); //Not implemented\r