35 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
56 #include <Wt/WHBoxLayout>
57 #include <Wt/WApplication>
64 void G4OpenGLWtViewer::CreateMainWindow (
65 Wt::WGLWidget* glWidget
71 #ifdef G4DEBUG_VIS_OGL
72 printf(
"G4OpenGLWtViewer::CreateMainWindow \n");
84 if (UI == NULL)
return;
93 bool isTabbedView =
false;
99 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
101 isTabbedView = fUiWt->AddTabWidget(fWindow->parent(),
name,getWinWidth(),getWinHeight());
103 fWindow->parent()->decorationStyle().setBackgroundColor (Wt::WColor(
"blue"));
106 #ifdef G4DEBUG_VIS_OGL
107 printf(
"G4OpenGLWtViewer::CreateMainWindow :: resize :%d %d\n",getWinWidth(),getWinHeight());
109 fWindow->resize(getWinWidth(),getWinHeight());
111 fUISceneTreeComponentsTBWidget = fUiWt->GetSceneTreeComponentsTBWidget();
112 fWindow->resize(fWindow->parent()->width(),fWindow->parent()->height());
117 #ifdef G4DEBUG_VIS_OGL
119 printf(
"G4OpenGLWtViewer::CreateMainWindow :: UIWt NOt found \n");
166 #ifdef _A_FINIR_FIXME
180 G4OpenGLWtViewer::G4OpenGLWtViewer (
181 G4OpenGLSceneHandler& scene
184 ,G4OpenGLViewer (scene)
186 ,fRecordFrameNumber(0)
188 ,fMouseAction(STYLE1)
190 ,fDeltaSceneTranslation(0.01)
194 ,fHoldKeyEvent(false)
195 ,fHoldMoveEvent(false)
196 ,fHoldRotateEvent(false)
200 ,fMovieTempFolderPath(
"")
202 ,fParameterFileName(
"mpeg_encode_parameter_file.par")
203 ,fMovieParametersDialog(NULL)
204 ,fRecordingStep(WAIT)
206 ,fNbMaxFramesPerSec(100)
207 ,fNbMaxAnglePerSec(360)
208 ,fLaunchSpinDelay(100)
213 ,fControlKeyPress(false)
214 ,fShiftKeyPress(false)
220 G4Wt::getInstance ();
225 #ifdef G4DEBUG_VIS_OGL
226 printf(
"G4OpenGLWtViewer::Create \n");
228 fLastPos3 = Wt::WPoint(-1,-1);
229 fLastPos2 = Wt::WPoint(-1,-1);
230 fLastPos1 = Wt::WPoint(-1,-1);
232 mMatrix.setToIdentity();
234 #ifdef _A_FINIR_FIXME
235 initMovieParameters();
238 fLastEventTime =
new Wt::WTime();
240 #ifdef G4DEBUG_VIS_OGL
241 printf(
"G4OpenGLWtViewer::G4OpenGLWtViewer END\n");
250 void G4OpenGLWtViewer::resizeGL(
int width,
int height)
252 #ifdef G4DEBUG_VIS_OGL
253 printf(
"G4OpenGLWtViewer resizeGL %d %d\n",width,height);
262 G4OpenGLWtViewer::~G4OpenGLWtViewer (
267 #ifdef _A_FINIR_FIXME
276 #ifdef _A_FINIR_FIXME
280 void G4OpenGLWtViewer::createPopupMenu() {
282 fContextMenu =
new WMenu(
"All");
284 WMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
286 fRotateAction = mMouseAction->addAction(
"Rotate");
287 fMoveAction = mMouseAction->addAction(
"Move");
288 fPickAction = mMouseAction->addAction(
"Pick");
289 WAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
291 fRotateAction->setCheckable(
true);
292 fMoveAction->setCheckable(
false);
293 fPickAction->setCheckable(
false);
294 shortcutsAction->setCheckable(
false);
296 fRotateAction->setChecked(
true);
297 fMoveAction->setChecked(
false);
298 fPickAction->setChecked(
false);
299 shortcutsAction->setChecked(
false);
301 WObject ::connect(fRotateAction,
302 SIGNAL(triggered(
bool)),
304 SLOT(actionMouseRotate()));
306 WObject ::connect(fMoveAction,
307 SIGNAL(triggered(
bool)),
309 SLOT(actionMouseMove()));
311 WObject ::connect(fPickAction,
312 SIGNAL(triggered(
bool)),
314 SLOT(actionMousePick()));
316 WObject ::connect(shortcutsAction,
317 SIGNAL(triggered(
bool)),
319 SLOT(showShortcuts()));
322 WMenu *mStyle = fContextMenu->addMenu(
"&Style");
324 WMenu *mRepresentation = mStyle->addMenu(
"&Representation");
325 WMenu *mProjection = mStyle->addMenu(
"&Projection");
326 WAction *polyhedron = mRepresentation->addAction(
"Polyhedron");
327 WAction *nurbs = mRepresentation->addAction(
"NURBS");
329 WAction *ortho = mProjection->addAction(
"Orthographic");
330 WAction *perspective = mProjection->addAction(
"Persepective");
333 G4ViewParameters::RepStyle style;
334 style = fVP.GetRepStyle();
335 if (style == G4ViewParameters::polyhedron) {
336 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(
bool)),1);
337 }
else if (style == G4ViewParameters::nurbs) {
338 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(
bool)),2);
340 mRepresentation->clear();
344 if (fVP.GetFieldHalfAngle() == 0) {
345 createRadioAction(ortho, perspective,SLOT(toggleProjection(
bool)),1);
347 createRadioAction(ortho, perspective,SLOT(toggleProjection(
bool)),2);
351 WMenu *mDrawing = mStyle->addMenu(
"&Drawing");
353 fDrawingWireframe = mDrawing->addAction(
"Wireframe");
354 fDrawingWireframe->setCheckable(
true);
356 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal");
357 fDrawingLineRemoval->setCheckable(
true);
359 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal");
360 fDrawingSurfaceRemoval->setCheckable(
true);
362 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal");
363 fDrawingLineSurfaceRemoval->setCheckable(
true);
367 d_style = fVP.GetDrawingStyle();
370 fDrawingWireframe->setChecked(
true);
372 fDrawingLineRemoval->setChecked(
true);
374 fDrawingSurfaceRemoval->setChecked(
true);
376 fDrawingLineSurfaceRemoval->setChecked(
true);
380 WObject ::connect(fDrawingWireframe,
381 SIGNAL(triggered(
bool)),
383 SLOT(actionDrawingWireframe()));
384 WObject ::connect(fDrawingLineRemoval,
385 SIGNAL(triggered(
bool)),
387 SLOT(actionDrawingLineRemoval()));
388 WObject ::connect(fDrawingSurfaceRemoval,
389 SIGNAL(triggered(
bool)),
391 SLOT(actionDrawingSurfaceRemoval()));
392 WObject ::connect(fDrawingLineSurfaceRemoval,
393 SIGNAL(triggered(
bool)),
395 SLOT(actionDrawingLineSurfaceRemoval()));
399 WAction *backgroundColorChooser ;
402 backgroundColorChooser = mStyle->addAction(
"Background color");
403 WObject ::connect(backgroundColorChooser,
406 SLOT(actionChangeBackgroundColor()));
410 WAction *textColorChooser ;
412 textColorChooser = mStyle->addAction(
"Text color");
413 WObject ::connect(textColorChooser,
416 SLOT(actionChangeTextColor()));
420 WAction *defaultColorChooser ;
422 defaultColorChooser = mStyle->addAction(
"Default color");
423 WObject ::connect(defaultColorChooser,
426 SLOT(actionChangeDefaultColor()));
430 WMenu *mActions = fContextMenu->addMenu(
"&Actions");
431 WAction *createEPS = mActions->addAction(
"Save as ...");
432 WObject ::connect(createEPS,
435 SLOT(actionSaveImage()));
438 WAction *movieParameters = mActions->addAction(
"Movie parameters...");
439 WObject ::connect(movieParameters,
442 SLOT(actionMovieParameters()));
448 WMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
449 WMenu *mTransparency = mSpecial->addMenu(
"Transparency");
450 WAction *transparencyOn = mTransparency->addAction(
"On");
451 WAction *transparencyOff = mTransparency->addAction(
"Off");
453 if (transparency_enabled ==
false) {
454 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
455 }
else if (transparency_enabled ==
true) {
456 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
462 WMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
463 WAction *antialiasingOn = mAntialiasing->addAction(
"On");
464 WAction *antialiasingOff = mAntialiasing->addAction(
"Off");
466 if (antialiasing_enabled ==
false) {
467 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
468 }
else if (antialiasing_enabled ==
true) {
469 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
471 mAntialiasing->clear();
474 WMenu *mHaloing = mSpecial->addMenu(
"Haloing");
475 WAction *haloingOn = mHaloing->addAction(
"On");
476 WAction *haloingOff = mHaloing->addAction(
"Off");
478 if (haloing_enabled ==
false) {
479 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
480 }
else if (haloing_enabled ==
true) {
481 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
486 WMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
487 WAction *auxOn = mAux->addAction(
"On");
488 WAction *auxOff = mAux->addAction(
"Off");
489 if (!fVP.IsAuxEdgeVisible()) {
490 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
492 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
497 WMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
498 fFullScreenOn = mFullScreen->addAction(
"On");
499 fFullScreenOff = mFullScreen->addAction(
"Off");
500 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
505 void G4OpenGLWtViewer::G4manageContextMenuEvent(WContextMenuEvent *
e)
508 G4cerr <<
"Visualization window not defined, please choose one before" <<
G4endl;
515 if ( fContextMenu ) {
516 fContextMenu->exec( e->globalPos() );
532 void G4OpenGLWtViewer::createRadioAction(WAction *action1,WAction *action2,
const std::string& method,
unsigned int nCheck) {
534 action1->setCheckable(
true);
535 action2->setCheckable(
true);
538 action1->setChecked (
true);
540 action2->setChecked (
true);
542 WObject ::connect(action1, SIGNAL(triggered(
bool)),action2, SLOT(toggle()));
543 WObject ::connect(action2, SIGNAL(triggered(
bool)),action1, SLOT(toggle()));
545 WObject ::connect(action1, SIGNAL(toggled(
bool)),
this, method.c_str());
552 void G4OpenGLWtViewer::actionMouseRotate() {
553 emit toggleMouseAction(STYLE1);
560 void G4OpenGLWtViewer::actionMouseMove() {
561 emit toggleMouseAction(STYLE2);
568 void G4OpenGLWtViewer::actionMousePick() {
569 emit toggleMouseAction(STYLE3);
576 void G4OpenGLWtViewer::actionDrawingWireframe() {
577 emit toggleDrawingAction(1);
583 void G4OpenGLWtViewer::actionDrawingLineRemoval() {
584 emit toggleDrawingAction(2);
590 void G4OpenGLWtViewer::actionDrawingSurfaceRemoval() {
591 emit toggleDrawingAction(3);
597 void G4OpenGLWtViewer::actionDrawingLineSurfaceRemoval() {
598 emit toggleDrawingAction(4);
606 void G4OpenGLWtViewer::toggleMouseAction(mouseActions aAction) {
608 if ((aAction == STYLE1) ||
609 (aAction == STYLE2) ||
610 (aAction == STYLE3)) {
611 fRotateAction->setChecked (
false);
612 fMoveAction->setChecked (
false);
613 fPickAction->setChecked (
false);
614 fVP.SetPicking(
false);
615 fMouseAction = aAction;
618 if (aAction == STYLE1) {
620 fRotateAction->setChecked (
true);
621 }
else if (aAction == STYLE2) {
622 fMoveAction->setChecked (
true);
623 }
else if (aAction == STYLE3) {
624 fPickAction->setChecked (
true);
625 fVP.SetPicking(
true);
633 void G4OpenGLWtViewer::showShortcuts() {
634 G4cout <<
"========= Mouse Shortcuts =========" <<
G4endl;
635 if (fMouseAction == STYLE1) {
636 G4cout <<
"Click and move mouse to rotate volume " <<
G4endl;
637 G4cout <<
"ALT + Click and move mouse to rotate volume (View Direction)" <<
G4endl;
638 G4cout <<
"CTRL + Click and zoom mouse to zoom in/out" <<
G4endl;
639 G4cout <<
"SHIFT + Click and zoommove camera point of view" <<
G4endl;
640 }
else if (fMouseAction == STYLE2) {
641 G4cout <<
"Move camera point of view with mouse" <<
G4endl;
642 }
else if (fMouseAction == STYLE3) {
645 G4cout <<
"========= Move Shortcuts =========" <<
G4endl;
646 G4cout <<
"Press left/right arrows to move volume left/right" <<
G4endl;
647 G4cout <<
"Press up/down arrows to move volume up/down" <<
G4endl;
648 G4cout <<
"Press '+'/'-' to move volume toward/forward" <<
G4endl;
650 G4cout <<
"========= Rotation (Theta/Phi) Shortcuts =========" <<
G4endl;
651 G4cout <<
"Press SHIFT + left/right arrows to rotate volume left/right" <<
G4endl;
652 G4cout <<
"Press SHIFT + up/down arrows to rotate volume up/down" <<
G4endl;
654 G4cout <<
"========= Rotation (View Direction) Shortcuts =========" <<
G4endl;
655 G4cout <<
"Press ALT + left/right to rotate volume around vertical direction" <<
G4endl;
656 G4cout <<
"Press ALT + up/down to rotate volume around horizontal direction" <<
G4endl;
659 G4cout <<
"Press CTRL + '+'/'-' to zoom into volume" <<
G4endl;
662 G4cout <<
"Press ALT +/- to slow/speed rotation/move" <<
G4endl;
668 G4cout <<
" Press SPACE to Start/Pause video recording " <<
G4endl;
669 G4cout <<
" Press RETURN to Stop video recording " <<
G4endl;
675 #ifdef _A_FINIR_FIXME
687 void G4OpenGLWtViewer::toggleDrawingAction(
int aAction) {
693 if ((aAction >0) && (aAction <5)) {
694 fDrawingWireframe->setChecked (
false);
695 fDrawingLineRemoval->setChecked (
false);
696 fDrawingSurfaceRemoval->setChecked (
false);
697 fDrawingLineSurfaceRemoval->setChecked (
false);
700 fDrawingWireframe->setChecked (
true);
704 }
else if (aAction ==2) {
705 fDrawingLineRemoval->setChecked (
true);
709 }
else if (aAction ==3) {
710 fDrawingSurfaceRemoval->setChecked (
true);
714 }
else if (aAction ==4) {
715 fDrawingLineSurfaceRemoval->setChecked (
true);
718 fVP.SetDrawingStyle(d_style);
734 void G4OpenGLWtViewer::toggleRepresentation(
bool check) {
736 G4ViewParameters::RepStyle style;
738 style = G4ViewParameters::polyhedron;
740 style = G4ViewParameters::nurbs;
742 fVP.SetRepStyle (style);
757 void G4OpenGLWtViewer::toggleProjection(
bool check) {
772 void G4OpenGLWtViewer::toggleTransparency(
bool check) {
775 transparency_enabled =
false;
777 transparency_enabled =
true;
779 SetNeedKernelVisit (
true);
787 void G4OpenGLWtViewer::toggleAntialiasing(
bool check) {
790 antialiasing_enabled =
false;
791 glDisable (GL_LINE_SMOOTH);
792 glDisable (GL_POLYGON_SMOOTH);
794 antialiasing_enabled =
true;
795 glEnable (GL_LINE_SMOOTH);
796 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
797 glEnable (GL_POLYGON_SMOOTH);
798 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
809 void G4OpenGLWtViewer::toggleHaloing(
bool check) {
811 haloing_enabled =
false;
813 haloing_enabled =
true;
824 void G4OpenGLWtViewer::toggleAux(
bool check) {
826 fVP.SetAuxEdgeVisible(
true);
828 fVP.SetAuxEdgeVisible(
false);
830 SetNeedKernelVisit (
true);
837 void G4OpenGLWtViewer::toggleFullScreen(
bool check) {
838 if (check != fGLWindow->isFullScreen()) {
839 fGLWindow->setWindowState(fGLWindow->windowState() ^ Wt::WindowFullScreen);
840 G4cerr <<
"This version of Wt could not do fullScreen. Resizing the widget is the only solution available." <<
G4endl;
845 #ifdef _A_FINIR_FIXME
846 void G4OpenGLWtViewer::savePPMToTemp() {
847 if (fMovieTempFolderPath ==
"") {
850 Wt::WString fileName =
"Test"+Wt::WString::number(fRecordFrameNumber)+
".ppm";
851 Wt::WString filePath =fMovieTempFolderPath+fileName;
854 image = fWindow->grabFrameBuffer();
857 res = image.save(filePath,0);
860 setRecordingInfos(
"Can't save tmp file "+filePath);
864 setRecordingInfos(
"File "+fileName+
" saved");
865 fRecordFrameNumber++;
870 void G4OpenGLWtViewer::actionSaveImage() {
872 WList<WByteArray> formats = WImageWriter::supportedImageFormats ();
873 for (
int i = 0; i < formats.size(); ++i) {
874 filters +=formats.at(i) +
";;";
879 Wt::WString* selectedFormat =
new Wt::WString();
881 name = WFileDialog::getSaveFileName ( fGLWindow,
885 selectedFormat ).toUTF8().c_str();
890 name +=
"." + selectedFormat->toUTF8();
891 Wt::WString format = selectedFormat->toLower();
892 setPrintFilename(name.c_str(),0);
893 G4OpenGLWtExportDialog* exportDialog=
new G4OpenGLWtExportDialog(fGLWindow,format,fWindow->height(),fWindow->width());
894 if( exportDialog->exec()) {
898 if ((exportDialog->getWidth() !=fWindow->width()) ||
899 (exportDialog->getHeight() !=fWindow->height())) {
900 setPrintSize(exportDialog->getWidth(),exportDialog->getHeight());
901 if ((format != Wt::WString(
"eps")) && (format != Wt::WString(
"ps"))) {
902 G4cerr <<
"Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need" <<
G4endl;
921 image = fWindow->grabFrameBuffer();
923 if (format == Wt::WString(
"eps")) {
924 fVectoredPs = exportDialog->getVectorEPS();
926 }
else if (format ==
"ps") {
929 }
else if (format ==
"pdf") {
931 res = printPDF(name,exportDialog->getNbColor(),image);
933 }
else if ((format ==
"tif") ||
934 (format ==
"tiff") ||
936 (format ==
"jpeg") ||
944 res = image.save(Wt::WString(name.c_str()),0,exportDialog->getSliderValue());
946 G4cerr <<
"This version of G4UI Could not generate the selected format" <<
G4endl;
948 if ((format == Wt::WString(
"eps")) && (format == Wt::WString(
"ps"))) {
950 G4cerr <<
"Error while saving file... "<<name.c_str()<<
G4endl;
952 G4cout <<
"File "<<name.c_str()<<
" has been saved " <<
G4endl;
964 #ifdef _A_FINIR_FIXME
965 void G4OpenGLWtViewer::actionChangeBackgroundColor() {
974 color = WColorDialog::getColor(Wt::black, fGLWindow);
975 if (color.isValid()) {
976 Wt::WString com =
"/vis/viewer/set/background ";
978 com += num.setNum(((
float)color.red())/256)+
" ";
979 com += num.setNum(((
float)color.green())/256)+
" ";
980 com += num.setNum(((
float)color.blue())/256)+
" ";
986 void G4OpenGLWtViewer::actionChangeTextColor() {
989 color = WColorDialog::getColor(
Wt::yellow, fGLWindow);
990 if (color.isValid()) {
991 Wt::WString com =
"/vis/viewer/set/defaultTextColour ";
993 com += num.setNum(((
float)color.red())/256)+
" ";
994 com += num.setNum(((
float)color.green())/256)+
" ";
995 com += num.setNum(((
float)color.blue())/256)+
" ";
1001 void G4OpenGLWtViewer::actionChangeDefaultColor() {
1004 color = WColorDialog::getColor(Wt::white, fGLWindow);
1005 printf(
"actionChangeDefaultColor\n");
1006 if (color.isValid()) {
1007 Wt::WString com =
"/vis/viewer/set/defaultColour ";
1009 com += num.setNum(((
float)color.red())/256)+
" ";
1010 com += num.setNum(((
float)color.green())/256)+
" ";
1011 com += num.setNum(((
float)color.blue())/256)+
" ";
1018 void G4OpenGLWtViewer::actionMovieParameters() {
1019 showMovieParametersDialog();
1023 void G4OpenGLWtViewer::showMovieParametersDialog() {
1024 if (!fMovieParametersDialog) {
1025 fMovieParametersDialog=
new G4OpenGLWtMovieDialog(
this,fGLWindow);
1026 displayRecordingStatus();
1027 fMovieParametersDialog->checkEncoderSwParameters();
1028 fMovieParametersDialog->checkSaveFileNameParameters();
1029 fMovieParametersDialog->checkTempFolderParameters();
1030 if (getEncoderPath() ==
"") {
1031 setRecordingInfos(
"mpeg_encode is needed to encode in video format. It is available here: http://bmrc.berkeley.edu/frame/research/mpeg/");
1034 fMovieParametersDialog->show();
1060 void G4OpenGLWtViewer::G4MousePressEvent(Wt::WMouseEvent *event)
1062 if (event->button() & Wt::WMouseEvent::LeftButton) {
1063 #ifdef _A_FINIR_FIXME
1064 fWindow->setMouseTracking(
true);
1067 fLastPos1 = Wt::WPoint(event->widget().x,
event->widget().y);
1068 fLastPos2 = fLastPos1;
1069 fLastPos3 = fLastPos2;
1071 if (fMouseAction == STYLE3){
1072 Pick(event->widget().x,
event->widget().y);
1079 void G4OpenGLWtViewer::G4MouseReleaseEvent()
1082 Wt::WPoint delta = Wt::WPoint(fLastPos3.x()-fLastPos1.x(),fLastPos3.y()-fLastPos1.y());
1083 if ((delta.x() == 0) && (delta.y() == 0)) {
1086 if (fSpinningDelay < fLaunchSpinDelay ) {
1088 Wt::WTime lastMoveTime;
1091 float correctionFactor = 5;
1094 if ( 1 >= (
int)(1000/fNbMaxFramesPerSec)) {
1095 float lTime = 1000/((float)1);
1096 if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1097 ((((
float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1098 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
1099 if (delta.x() <0 ) {
1100 correctionFactor = -correctionFactor;
1103 if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1104 ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1105 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
1106 if (delta.y() <0 ) {
1107 correctionFactor = -correctionFactor;
1118 if (fMouseAction == STYLE1) {
1120 rotateWtScene(((
float)delta.x())/correctionFactor,((
float)delta.
y())/correctionFactor);
1121 }
else if (fAltKeyPress) {
1122 rotateWtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.
y())/correctionFactor);
1125 }
else if (fMouseAction == STYLE2) {
1126 moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.
y())/correctionFactor,0,true);
1130 #ifdef _A_FINIR_FIXME
1131 ((Wt::WApplication*)G4Wt::getInstance ())->processEvents();
1135 #ifdef _A_FINIR_FIXME
1136 fWindow->setMouseTracking(
false);
1141 void G4OpenGLWtViewer::G4MouseDoubleClickEvent()
1143 #ifdef _A_FINIR_FIXME
1144 fWindow->setMouseTracking(
true);
1156 void G4OpenGLWtViewer::G4MouseMoveEvent(Wt::WMouseEvent *event)
1159 Wt::WMouseEvent::Button mButtons =
event->button();
1161 #ifdef _A_FINIR_FIXME
1162 updateKeyModifierState(event->modifiers());
1169 fLastPos3 = fLastPos2;
1170 fLastPos2 = fLastPos1;
1171 fLastPos1 = Wt::WPoint(event->widget().x,
event->widget().y);
1173 printf(
"G4OpenGLWtViewer move :%d %d\n",event->widget().x,
event->widget().y);
1174 int deltaX = fLastPos2.x()-fLastPos1.x();
1175 int deltaY = fLastPos2.y()-fLastPos1.y();
1177 if (fMouseAction == STYLE1) {
1178 if (mButtons & Wt::WMouseEvent::LeftButton) {
1180 rotateWtScene(((
float)deltaX),((
float)deltaY));
1181 }
else if (fAltKeyPress) {
1182 rotateWtSceneToggle(((
float)deltaX),((
float)deltaY));
1183 }
else if (fShiftKeyPress) {
1184 unsigned int sizeWin;
1185 sizeWin = getWinWidth();
1186 if (getWinHeight() < getWinWidth()) {
1187 sizeWin = getWinHeight();
1191 float factor = ((float)100/(
float)sizeWin) ;
1192 moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
1193 }
else if (fControlKeyPress) {
1194 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((float)deltaY)));
1197 }
else if (fMouseAction == STYLE2) {
1198 if (mButtons & Wt::WMouseEvent::LeftButton) {
1199 moveScene(-deltaX,-deltaY,0,
true);
1214 void G4OpenGLWtViewer::moveScene(
float dx,
float dy,
float dz,
bool mouseMove)
1218 fHoldMoveEvent =
true;
1221 GLdouble coefDepth = 0;
1224 if (getWinHeight() <getWinWidth()) {
1228 coefTrans = getSceneNearWidth()*fDeltaSceneTranslation;
1229 coefDepth = getSceneDepth()*fDeltaDepth;
1231 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1234 #ifdef _A_FINIR_FIXME
1235 ((WApplication*)G4Wt::getInstance ())->processEvents();
1238 fHoldMoveEvent =
false;
1247 void G4OpenGLWtViewer::rotateWtScene(
float dx,
float dy)
1249 if (fHoldRotateEvent)
1251 fHoldRotateEvent =
true;
1261 fHoldRotateEvent =
false;
1269 void G4OpenGLWtViewer::rotateWtSceneToggle(
float dx,
float dy)
1271 if (fHoldRotateEvent)
1273 fHoldRotateEvent =
true;
1275 rotateSceneToggle(dx,dy);
1279 fHoldRotateEvent =
false;
1294 void G4OpenGLWtViewer::rescaleImage(
1313 #ifdef _A_FINIR_FIXME
1320 bool G4OpenGLWtViewer::printPDF (
1321 const std::string aFilename
1333 if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1334 aImage = aImage.convertToFormat ( aImage.format(), Wt::MonoOnly);
1338 if (aFilename.substr(aFilename.size()-3) ==
".ps") {
1339 #if WT_VERSION > 0x040200
1340 printer.setOutputFormat(WPrinter::PostScriptFormat);
1343 #if WT_VERSION > 0x040100
1344 printer.setOutputFormat(WPrinter::PdfFormat);
1347 #if WT_VERSION > 0x040100
1348 printer.setOutputFileName(Wt::WString(aFilename.c_str()));
1351 WPainter paint(&printer);
1352 paint.drawImage (0,0,aImage);
1359 void G4OpenGLWtViewer::G4wheelEvent (Wt::WWheelEvent * event)
1361 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(
event->delta())/1200));
1366 void G4OpenGLWtViewer::G4keyPressEvent (Wt::WKeyEvent * event)
1371 fHoldKeyEvent =
true;
1375 #ifdef _A_FINIR_FIXME
1376 updateKeyModifierState(event->modifiers());
1378 if ((fNoKeyPress)) {
1379 if (event->key() == Wt::Key_Down) {
1380 moveScene(0,1,0,
false);
1382 else if (event->key() == Wt::Key_Up) {
1383 moveScene(0,-1,0,
false);
1385 if (event->key() == Wt::Key_Left) {
1386 moveScene(-1,0,0,
false);
1388 else if (event->key() == Wt::Key_Right) {
1389 moveScene(1,0,0,
false);
1391 if (event->text() == Wt::WString(
"-") ) {
1392 moveScene(0,0,1,
false);
1394 else if (event->text() == Wt::WString(
"+")) {
1395 moveScene(0,0,-1,
false);
1399 if (event->key() == Wt::Key_Escape) {
1400 #ifdef _A_FINIR_FIXME
1401 toggleFullScreen(
false);
1411 #ifdef _A_FINIR_FIXME
1412 if ( (event->key() == Wt::Key_Enter)){
1415 if (event->key() == Wt::Key_Space){
1421 if (event->key() == Wt::Key_H){
1423 fDeltaSceneTranslation = 0.01;
1428 fVP.SetZoomFactor(1.);
1430 fVP.SetViewAndLights (
G4Vector3D (0., 0., 1.));
1436 if (fShiftKeyPress) {
1437 if (event->key() == Wt::Key_Down) {
1438 rotateWtScene(0,-fDeltaRotation);
1440 else if (event->key() == Wt::Key_Up) {
1441 rotateWtScene(0,fDeltaRotation);
1443 if (event->key() == Wt::Key_Left) {
1444 rotateWtScene(fDeltaRotation,0);
1446 else if (event->key() == Wt::Key_Right) {
1447 rotateWtScene(-fDeltaRotation,0);
1452 if ((fAltKeyPress)) {
1453 if (event->key() == Wt::Key_Down) {
1454 rotateWtSceneToggle(0,-fDeltaRotation);
1456 else if (event->key() == Wt::Key_Up) {
1457 rotateWtSceneToggle(0,fDeltaRotation);
1459 if (event->key() == Wt::Key_Left) {
1460 rotateWtSceneToggle(fDeltaRotation,0);
1462 else if (event->key() == Wt::Key_Right) {
1463 rotateWtSceneToggle(-fDeltaRotation,0);
1467 if (event->text() == Wt::WString(
"+")) {
1468 fDeltaRotation = fDeltaRotation/0.7;
1469 G4cout <<
"Auto-rotation set to : " << fDeltaRotation <<
G4endl;
1471 else if (event->text() == Wt::WString(
"-")) {
1472 fDeltaRotation = fDeltaRotation*0.7;
1473 G4cout <<
"Auto-rotation set to : " << fDeltaRotation <<
G4endl;
1478 if ((fControlKeyPress)) {
1479 if (event->text() == Wt::WString(
"+")) {
1480 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
1483 else if (event->text() == Wt::WString(
"-")) {
1484 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
1489 fHoldKeyEvent =
false;
1493 #ifdef _A_FINIR_FIXME
1494 void G4OpenGLWtViewer::updateKeyModifierState(Wt::KeyboardModifiers modifier) {
1498 fAltKeyPress =
false;
1499 fShiftKeyPress =
false;
1500 fControlKeyPress =
false;
1502 if (modifier & Wt::AltModifier ) {
1503 fAltKeyPress =
true;
1504 fNoKeyPress =
false;
1506 if (modifier & Wt::ShiftModifier ) {
1507 fShiftKeyPress =
true;
1508 fNoKeyPress =
false;
1510 if (modifier & Wt::ControlModifier ) {
1511 fControlKeyPress =
true;
1512 fNoKeyPress =
false;
1518 void G4OpenGLWtViewer::stopVideo() {
1521 if (!fMovieParametersDialog) {
1522 showMovieParametersDialog();
1524 setRecordingStatus(STOP);
1526 if (fRecordFrameNumber >0) {
1528 if (!(fMovieParametersDialog->checkEncoderSwParameters())) {
1529 setRecordingStatus(BAD_ENCODER);
1530 }
else if (!(fMovieParametersDialog->checkSaveFileNameParameters())) {
1531 setRecordingStatus(BAD_OUTPUT);
1535 setRecordingInfos(
"No frame to encode.");
1541 void G4OpenGLWtViewer::saveVideo() {
1544 if (!fMovieParametersDialog) {
1545 showMovieParametersDialog();
1548 fMovieParametersDialog->checkEncoderSwParameters();
1549 fMovieParametersDialog->checkSaveFileNameParameters();
1551 if (fRecordingStep == STOP) {
1552 setRecordingStatus(SAVE);
1553 generateMpegEncoderParameters();
1561 void G4OpenGLWtViewer::startPauseVideo() {
1565 if (( fRecordingStep == WAIT)) {
1566 if ( fRecordFrameNumber == 0) {
1567 if (getTempFolderPath() ==
"") {
1568 showMovieParametersDialog();
1569 setRecordingInfos(
"You should specified the temp folder in order to make movie");
1573 Wt::WString
tmp = removeTempFolder();
1575 setRecordingInfos(tmp);
1578 tmp = createTempFolder();
1580 setRecordingInfos(
"Can't create temp folder."+tmp);
1586 if ((fRecordingStep == WAIT)) {
1587 setRecordingStatus(
START);
1588 }
else if (fRecordingStep ==
START) {
1589 setRecordingStatus(PAUSE);
1590 }
else if (fRecordingStep == PAUSE) {
1591 setRecordingStatus(CONTINUE);
1592 }
else if (fRecordingStep == CONTINUE) {
1593 setRecordingStatus(PAUSE);
1597 void G4OpenGLWtViewer::setRecordingStatus(RECORDING_STEP step) {
1599 fRecordingStep = step;
1600 displayRecordingStatus();
1604 void G4OpenGLWtViewer::displayRecordingStatus() {
1606 Wt::WString txtStatus =
"";
1607 if (fRecordingStep == WAIT) {
1608 txtStatus =
"Waiting to start...";
1609 fRecordFrameNumber = 0;
1610 }
else if (fRecordingStep ==
START) {
1611 txtStatus =
"Start Recording...";
1612 }
else if (fRecordingStep == PAUSE) {
1613 txtStatus =
"Pause Recording...";
1614 }
else if (fRecordingStep == CONTINUE) {
1615 txtStatus =
"Continue Recording...";
1616 }
else if (fRecordingStep == STOP) {
1617 txtStatus =
"Stop Recording...";
1618 }
else if (fRecordingStep == READY_TO_ENCODE) {
1619 txtStatus =
"Ready to Encode...";
1620 }
else if (fRecordingStep ==
ENCODING) {
1621 txtStatus =
"Encoding...";
1622 }
else if (fRecordingStep == FAILED) {
1623 txtStatus =
"Failed to encode...";
1624 }
else if ((fRecordingStep == BAD_ENCODER)
1625 || (fRecordingStep == BAD_OUTPUT)
1626 || (fRecordingStep == BAD_TMP)) {
1627 txtStatus =
"Correct above errors first";
1628 }
else if (fRecordingStep == SUCCESS) {
1629 txtStatus =
"File encoded successfully";
1633 if (fMovieParametersDialog) {
1634 fMovieParametersDialog->setRecordingStatus(txtStatus);
1638 setRecordingInfos(
"");
1642 void G4OpenGLWtViewer::setRecordingInfos(Wt::WString txt) {
1643 if (fMovieParametersDialog) {
1644 fMovieParametersDialog->setRecordingInfos(txt);
1652 void G4OpenGLWtViewer::initMovieParameters() {
1656 fProcess =
new WProcess();
1658 WObject ::connect(fProcess,SIGNAL(finished (
int)),
1659 this,SLOT(processLookForFinished()));
1660 fProcess->setReadChannelMode(WProcess::MergedChannels);
1661 fProcess->start (
"which mpeg_encode");
1667 Wt::WString G4OpenGLWtViewer::getEncoderPath() {
1668 return fEncoderPath;
1676 Wt::WString G4OpenGLWtViewer::setEncoderPath(Wt::WString path) {
1678 return "File does not exist";
1681 path = WDir::cleanPath(path);
1682 WFileInfo *
f =
new WFileInfo(path);
1684 return "File does not exist";
1685 }
else if (f->isDir()) {
1686 return "This is a directory";
1687 }
else if (!f->isExecutable()) {
1688 return "File exist but is not executable";
1689 }
else if (!f->isFile()) {
1690 return "This is not a file";
1692 fEncoderPath = path;
1694 if ((fRecordingStep == BAD_ENCODER)) {
1695 setRecordingStatus(STOP);
1701 bool G4OpenGLWtViewer::isRecording(){
1702 if ((fRecordingStep ==
START) || (fRecordingStep == CONTINUE)) {
1708 bool G4OpenGLWtViewer::isPaused(){
1709 if (fRecordingStep == PAUSE) {
1715 bool G4OpenGLWtViewer::isEncoding(){
1722 bool G4OpenGLWtViewer::isWaiting(){
1723 if (fRecordingStep == WAIT) {
1729 bool G4OpenGLWtViewer::isStopped(){
1730 if (fRecordingStep == STOP) {
1736 bool G4OpenGLWtViewer::isFailed(){
1737 if (fRecordingStep == FAILED) {
1743 bool G4OpenGLWtViewer::isSuccess(){
1744 if (fRecordingStep == SUCCESS) {
1750 bool G4OpenGLWtViewer::isBadEncoder(){
1751 if (fRecordingStep == BAD_ENCODER) {
1756 bool G4OpenGLWtViewer::isBadTmp(){
1757 if (fRecordingStep == BAD_TMP) {
1762 bool G4OpenGLWtViewer::isBadOutput(){
1763 if (fRecordingStep == BAD_OUTPUT) {
1769 void G4OpenGLWtViewer::setBadEncoder(){
1770 fRecordingStep = BAD_ENCODER;
1771 displayRecordingStatus();
1773 void G4OpenGLWtViewer::setBadTmp(){
1774 fRecordingStep = BAD_TMP;
1775 displayRecordingStatus();
1777 void G4OpenGLWtViewer::setBadOutput(){
1778 fRecordingStep = BAD_OUTPUT;
1779 displayRecordingStatus();
1782 void G4OpenGLWtViewer::setWaiting(){
1783 fRecordingStep = WAIT;
1784 displayRecordingStatus();
1788 bool G4OpenGLWtViewer::isReadyToEncode(){
1789 if (fRecordingStep == READY_TO_ENCODE) {
1795 void G4OpenGLWtViewer::resetRecording() {
1796 setRecordingStatus(WAIT);
1803 Wt::WString G4OpenGLWtViewer::setTempFolderPath(Wt::WString path) {
1806 return "Path does not exist";
1808 path = WDir::cleanPath(path);
1809 WFileInfo *
d =
new WFileInfo(path);
1811 return "Path does not exist";
1812 }
else if (!d->isDir()) {
1813 return "This is not a directory";
1814 }
else if (!d->isReadable()) {
1815 return path +
" is read protected";
1816 }
else if (!d->isWritable()) {
1817 return path +
" is write protected";
1820 if ((fRecordingStep == BAD_TMP)) {
1821 setRecordingStatus(WAIT);
1823 fTempFolderPath = path;
1829 Wt::WString G4OpenGLWtViewer::getTempFolderPath() {
1830 return fTempFolderPath;
1837 Wt::WString G4OpenGLWtViewer::setSaveFileName(Wt::WString path) {
1840 return "Path does not exist";
1843 WFileInfo *
file =
new WFileInfo(path);
1844 WDir
dir = file->dir();
1845 path = WDir::cleanPath(path);
1846 if (file->exists()) {
1847 return "File already exist, please choose a new one";
1848 }
else if (!dir.exists()) {
1849 return "Dir does not exist";
1850 }
else if (!dir.isReadable()) {
1851 return path +
" is read protected";
1854 if ((fRecordingStep == BAD_OUTPUT)) {
1855 setRecordingStatus(STOP);
1857 fSaveFileName = path;
1863 Wt::WString G4OpenGLWtViewer::getSaveFileName() {
1864 return fSaveFileName ;
1871 Wt::WString G4OpenGLWtViewer::createTempFolder() {
1872 fMovieTempFolderPath =
"";
1874 Wt::WString
tmp = setTempFolderPath(fTempFolderPath);
1878 Wt::WString sep = Wt::WString(WDir::separator());
1879 Wt::WString path = sep+
"WtMovie_"+WDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep;
1880 WDir *d =
new WDir(WDir::cleanPath(fTempFolderPath));
1882 if (d->exists(path)) {
1883 return "Folder "+path+
" already exists.Please remove it first";
1885 if (d->mkdir(fTempFolderPath+path)) {
1886 fMovieTempFolderPath = fTempFolderPath+path;
1889 return "Can't create "+fTempFolderPath+path;
1896 Wt::WString G4OpenGLWtViewer::removeTempFolder() {
1898 if (fMovieTempFolderPath ==
"") {
1901 WDir *d =
new WDir(WDir::cleanPath(fMovieTempFolderPath));
1906 d->setFilter( WDir::Files );
1907 Wt::WStringList subDirList = d->entryList();
1909 Wt::WString
error =
"";
1910 for (Wt::WStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
1911 const Wt::WString currentFile = *it;
1912 if (!d->remove(currentFile)) {
1914 Wt::WString file = fMovieTempFolderPath+currentFile;
1915 error +=
"Removing file failed : "+
file;
1920 if (d->rmdir(fMovieTempFolderPath)) {
1921 fMovieTempFolderPath =
"";
1924 return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
1928 return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+
error;
1933 bool G4OpenGLWtViewer::hasPendingEvents () {
1934 #ifdef _A_FINIR_FIXME
1935 return ((WApplication*)G4Wt::getInstance ())->hasPendingEvents ();
1940 bool G4OpenGLWtViewer::generateMpegEncoderParameters () {
1944 fp = fopen (Wt::WString(fMovieTempFolderPath+fParameterFileName).toUTF8().c_str(),
"w");
1947 setRecordingInfos(
"Generation of parameter file failed");
1951 fprintf (fp,
"# parameter file template with lots of comments to assist you\n");
1953 fprintf (fp,
"# you can use this as a template, copying it to a separate file then modifying\n");
1954 fprintf (fp,
"# the copy\n");
1957 fprintf (fp,
"# any line beginning with '#' is a comment\n");
1959 fprintf (fp,
"# no line should be longer than 255 characters\n");
1962 fprintf (fp,
"# general format of each line is:\n");
1963 fprintf (fp,
"# \n");
1965 fprintf (fp,
"# lines can generally be in any order\n");
1967 fprintf (fp,
"# an exception is the option 'INPUT' which must be followed by input\n");
1968 fprintf (fp,
"# files in the order in which they must appear, followed by 'END_INPUT'\n");
1970 fprintf (fp,
"# Also, if you use the `command` method of generating input file names,\n");
1971 fprintf (fp,
"# the command will only be executed in the INPUT_DIR if INPUT_DIR preceeds\n");
1972 fprintf (fp,
"# the INPUT parameter.\n");
1974 fprintf (fp,
"# MUST be in UPPER CASE\n");
1977 fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
1978 fprintf (fp,
"# for more info.\n");
1980 fprintf (fp,
"PATTERN IBBPBBPBBPBBPBBP\n");
1981 fprintf (fp,
"OUTPUT %s\n",getSaveFileName().toUTF8().c_str());
1983 fprintf (fp,
"# mpeg_encode really only accepts 3 different file formats, but using a\n");
1984 fprintf (fp,
"# conversion statement it can effectively handle ANY file format\n");
1986 fprintf (fp,
"# You must specify the type of the input files. The choices are:\n");
1987 fprintf (fp,
"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
1988 fprintf (fp,
"# (must be upper case)\n");
1990 fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
1993 fprintf (fp,
"# if YUV format (or using parallel version), must provide width and height\n");
1994 fprintf (fp,
"# YUV_SIZE widthxheight\n");
1995 fprintf (fp,
"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
1996 fprintf (fp,
"# on just one machine\n");
1998 fprintf (fp,
"YUV_SIZE 352x240\n");
2000 fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
2001 fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
2002 fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2003 fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
2004 fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
2005 fprintf (fp,
"# to specify the file order.\n");
2007 fprintf (fp,
"INPUT_FORMAT UCB\n");
2009 fprintf (fp,
"# the conversion statement\n");
2011 fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
2013 fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
2014 fprintf (fp,
"# INPUT_CONVERT giftoppm *\n");
2016 fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2017 fprintf (fp,
"# INPUT_CONVERT cat *.Y *.U *.V\n");
2019 fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
2020 fprintf (fp,
"# INPUT_CONVERT goto frame *; grabppm\n");
2021 fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2023 fprintf (fp,
"INPUT_CONVERT * \n");
2025 fprintf (fp,
"# number of frames in a GOP.\n");
2027 fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
2028 fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2030 fprintf (fp,
"# later, will add more flexible GOP signalling\n");
2032 fprintf (fp,
"GOP_SIZE 16\n");
2034 fprintf (fp,
"# number of slices in a frame\n");
2036 fprintf (fp,
"# 1 is a good number. another possibility is the number of macroblock rows\n");
2037 fprintf (fp,
"# (which is the height divided by 16)\n");
2039 fprintf (fp,
"SLICES_PER_FRAME 1\n");
2041 fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
2042 fprintf (fp,
"INPUT_DIR %s\n",fMovieTempFolderPath.toUTF8().c_str());
2044 fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
2045 fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
2046 fprintf (fp,
"# way of numbering them. See the manual for more information.\n");
2047 fprintf (fp,
"INPUT\n");
2048 fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2049 fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2050 fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2051 fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2052 fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
2053 fprintf (fp,
"# if you do, too bad!!!\n");
2056 fprintf (fp,
"Test*.ppm [0-%d]\n",fRecordFrameNumber-1);
2057 fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
2058 fprintf (fp,
"# of files\n");
2059 fprintf (fp,
"END_INPUT\n");
2063 fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
2065 fprintf (fp,
"# FULL or HALF -- must be upper case\n");
2066 fprintf (fp,
"# Should be FULL for computer generated images\n");
2067 fprintf (fp,
"PIXEL FULL\n");
2069 fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
2070 fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
2071 fprintf (fp,
"RANGE 10\n");
2073 fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
2074 fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
2076 fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2077 fprintf (fp,
"PSEARCH_ALG LOGARITHMIC\n");
2079 fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2081 fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
2083 fprintf (fp,
"BSEARCH_ALG SIMPLE\n");
2086 fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
2087 fprintf (fp,
"# (values must be between 1 and 31)\n");
2088 fprintf (fp,
"# These are the Wscale values for the entire frame in variable bit-rate\n");
2089 fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
2092 fprintf (fp,
"# Wscale (Wuantization scale) affects quality and compression,\n");
2093 fprintf (fp,
"# but has very little effect on speed.\n");
2095 fprintf (fp,
"IWSCALE 4\n");
2096 fprintf (fp,
"PWSCALE 5\n");
2097 fprintf (fp,
"BWSCALE 12\n");
2099 fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
2100 fprintf (fp,
"REFERENCE_FRAME ORIGINAL\n");
2102 fprintf (fp,
"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
2104 fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2105 fprintf (fp,
"#BIT_RATE 1000000\n");
2107 fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2108 fprintf (fp,
"BUFFER_SIZE 327680\n");
2110 fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
2111 fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2112 fprintf (fp,
"FRAME_RATE 30\n");
2114 fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
2115 fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IWTABLE, etc.\n");
2120 setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
2121 setRecordingStatus(READY_TO_ENCODE);
2125 void G4OpenGLWtViewer::encodeVideo()
2127 if ((getEncoderPath() !=
"") && (getSaveFileName() !=
"")) {
2130 fProcess =
new WProcess();
2131 WObject ::connect(fProcess,SIGNAL(finished (
int)),
2132 this,SLOT(processEncodeFinished()));
2133 WObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2134 this,SLOT(processEncodeStdout()));
2135 fProcess->setReadChannelMode(WProcess::MergedChannels);
2136 fProcess->start (fEncoderPath, Wt::WStringList(fMovieTempFolderPath+fParameterFileName));
2142 void G4OpenGLWtViewer::processEncodeStdout()
2144 Wt::WString tmp = fProcess->readStdout ().data();
2145 int start = tmp.findRev(
"ESTIMATED TIME");
2146 tmp = tmp.mid(start,tmp.find(
"\n",start)-start);
2147 setRecordingInfos(tmp);
2151 void G4OpenGLWtViewer::processEncodeFinished()
2154 Wt::WString txt =
"";
2155 txt = getProcessErrorMsg();
2157 setRecordingStatus(SUCCESS);
2159 setRecordingStatus(FAILED);
2165 void G4OpenGLWtViewer::processLookForFinished()
2168 Wt::WString txt = getProcessErrorMsg();
2172 fEncoderPath = Wt::WString(fProcess->readAllStandardOutput ().data()).trimmed();
2174 if (fEncoderPath.contains(
" ")) {
2176 }
else if (!fEncoderPath.contains(
"mpeg_encode")) {
2179 setEncoderPath(fEncoderPath);
2182 setTempFolderPath(WDir::temp ().absolutePath ());
2186 Wt::WString G4OpenGLWtViewer::getProcessErrorMsg()
2188 Wt::WString txt =
"";
2189 if (fProcess->exitCode() != 0) {
2190 switch (fProcess->error()) {
2191 case WProcess::FailedToStart:
2192 txt =
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
2194 case WProcess::Crashed:
2195 txt =
"The process crashed some time after starting successfully.\n";
2197 case WProcess::Timedout:
2198 txt =
"The last waitFor...() function timed out. The state of WProcess is unchanged, and you can try calling waitFor...() again.\n";
2200 case WProcess::WriteError:
2201 txt =
"An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.\n";
2203 case WProcess::ReadError:
2204 txt =
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
2206 case WProcess::UnknownError:
2207 txt =
"An unknown error occurred. This is the default return value of error().\n";
G4int ApplyCommand(const char *aCommand)
G4UIsession * GetG4UIWindow() const
static G4UImanager * GetUIpointer()
printf("%d Experimental points found\n", nlines)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static PROLOG_HANDLER error