diff --git a/src/OSD/OSD_Timer.cdl b/src/OSD/OSD_Timer.cdl index b28961b013..9d52986436 100755 --- a/src/OSD/OSD_Timer.cdl +++ b/src/OSD/OSD_Timer.cdl @@ -66,7 +66,7 @@ is ---Purpose: returns both the elapsed time(seconds,minutes,hours) -- and CPU time. ---Level: Public - + Stop (me : in out) is redefined; ---Purpose: Stops the Timer. ---Level: Public @@ -76,6 +76,10 @@ is -- the Timer. ---Level: Public + ElapsedTime (me : in out) returns Real; + ---Purpose: Returns elapsed time in seconds. + ---Level: Public + fields TimeStart : Real; diff --git a/src/OSD/OSD_Timer.cxx b/src/OSD/OSD_Timer.cxx index 905191f830..48a14f4968 100755 --- a/src/OSD/OSD_Timer.cxx +++ b/src/OSD/OSD_Timer.cxx @@ -131,6 +131,22 @@ void OSD_Timer::Show () Show (cout); } +//======================================================================= +//function : ElapsedTime +//purpose : +//======================================================================= + +Standard_Real OSD_Timer::ElapsedTime() +{ + if (!Stopped) + { + // update cumulative time + Stop(); + Start(); + } + + return TimeCumul; +} //======================================================================= //function : Show diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index bfcfaa354c..6daf9236d4 100755 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -310,6 +310,12 @@ Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiStrin aMap.UnBind2 (theName); } + if (theAISObj.IsNull()) + { + // object with specified name already unbound + return Standard_True; + } + // unbind AIS object if was bound with another name aMap.UnBind1 (theAISObj); diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 7aea03504f..37334eb04b 100755 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -2775,36 +2775,10 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char* Standard_Real aCenterY = (argc > 5) ? atof (argv[4]) : 0.0; Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0; Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0; - Standard_Boolean isVBOEnabled = (argc > 7) ? atoi (argv[7]) : Standard_True; - Standard_Integer aRedrawsNb = (argc > 8) ? atoi (argv[8]) : 1; - Standard_Boolean toShowEdges = (argc > 9) ? atoi (argv[9]) : Standard_False; - - if (aRedrawsNb <= 0) - { - aRedrawsNb = 1; - } + Standard_Boolean toShowEdges = (argc > 7) ? atoi (argv[7]) : Standard_False; // remove AIS object with given name from map - if (GetMapOfAIS().IsBound2 (aShapeName)) - { - Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aShapeName); - Handle(AIS_InteractiveObject) anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj); - if (anInterObj.IsNull()) - { - std::cout << "Shape name was used for non AIS viewer\n!"; - return 1; - } - aContextAIS->Remove (anInterObj, Standard_False); - GetMapOfAIS().UnBind2 (aShapeName); - } - - // enable/disable VBO - Handle(Graphic3d_GraphicDriver) aDriver = - Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver()); - if (!aDriver.IsNull()) - { - aDriver->EnableVBO (isVBOEnabled); - } + VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)()); std::cout << "Compute Triangulation...\n"; Handle(AIS_Triangulation) aShape @@ -2814,9 +2788,6 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char* Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); - // register the object in map - GetMapOfAIS().Bind (aShape, aShapeName); - // stupid initialization of Green color in RGBA space as integer // probably wrong for big-endian CPUs Standard_Integer aRed = 0; @@ -2879,41 +2850,7 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char* aShAsp->SetAspect (anAspect); aShape->Attributes()->SetShadingAspect (aShAsp); - aContextAIS->Display (aShape, Standard_False); - - // Two viewer updates are needed in order to measure time spent on - // loading triangulation to graphic card memory + redrawing (1st update) and - // time spent on redrawing itself (2nd and all further updates) - OSD_Chronometer aTimer; - Standard_Real aUserSeconds, aSystemSeconds; - aTimer.Start(); - const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); - for (Standard_Integer anInteration = 0; anInteration < aRedrawsNb; ++anInteration) - { - for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) - { - if (anInteration == 0) - { - aViewer->ActiveView()->Update(); - } - else - { - aViewer->ActiveView()->Redraw(); - } - } - } - aTimer.Show (aUserSeconds, aSystemSeconds); - aTimer.Stop(); - std::cout << "Number of scene redrawings: " << aRedrawsNb << "\n" - << "CPU user time: " - << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aUserSeconds - << " msec\n" - << "CPU system time: " - << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aSystemSeconds - << " msec\n" - << "CPU average time of scene redrawing: " - << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * (aUserSeconds / (Standard_Real )aRedrawsNb) - << " msec\n"; + VDisplayAISObject (aShapeName, aShape); return 0; } @@ -4343,7 +4280,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) __FILE__,VDrawText,group); theCommands.Add("vdrawsphere", - "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n", + "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n", __FILE__,VDrawSphere,group); theCommands.Add("vclipplane", diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 111453fac1..7a536c47ac 100755 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -30,6 +30,7 @@ #endif #include +#include #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -1885,7 +1887,7 @@ static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char Standard_Real minRange = 0. , maxRange = 100. ; Standard_Integer numIntervals = 10 ; - Standard_Real textHeight = 16. ; + Standard_Integer textHeight = 16; Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT; Standard_Real X = 0., Y = 0. ; @@ -1898,7 +1900,7 @@ static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char numIntervals = atoi( argv[3] ); } if ( argc > 4 ) - textHeight = atof( argv[4] ); + textHeight = atoi( argv[4] ); if ( argc > 5 ) position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] ); if ( argc > 7 ) @@ -2671,7 +2673,7 @@ static int VGrid (Draw_Interpretor& theDI, if (aTail == 5) { aRadiusStep = atof (theArgVec[anIter++]); - aDivisionNumber = atof (theArgVec[anIter++]); + aDivisionNumber = atoi (theArgVec[anIter++]); aRotAngle = atof (theArgVec[anIter++]); } @@ -2682,6 +2684,94 @@ static int VGrid (Draw_Interpretor& theDI, return 0; } +//============================================================================== +//function : VFps +//purpose : +//============================================================================== + +static int VFps (Draw_Interpretor& theDI, + Standard_Integer theArgNb, + const char** theArgVec) +{ + // get the active view + Handle(V3d_View) aView = ViewerTest::CurrentView(); + if (aView.IsNull()) + { + std::cerr << "No active view. Please call vinit.\n"; + return 1; + } + + Standard_Integer aFramesNb = (theArgNb > 1) ? atoi(theArgVec[1]) : 100; + if (aFramesNb <= 0) + { + std::cerr << "Incorrect arguments!\n"; + return 1; + } + + // the time is meaningless for first call + // due to async OpenGl rendering + aView->Redraw(); + + // redraw view in loop to estimate average values + OSD_Timer aTimer; + aTimer.Start(); + for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) + { + aView->Redraw(); + } + aTimer.Stop(); + Standard_Real aCpu; + const Standard_Real aTime = aTimer.ElapsedTime(); + aTimer.OSD_Chronometer::Show (aCpu); + + const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; + const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); + + // return statistics + theDI << "FPS: " << aFpsAver << "\n" + << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; + + return 0; +} + + +//============================================================================== +//function : VVbo +//purpose : +//============================================================================== + +static int VVbo (Draw_Interpretor& theDI, + Standard_Integer theArgNb, + const char** theArgVec) +{ + // get the context + Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); + if (aContextAIS.IsNull()) + { + std::cerr << "No active view. Please call vinit.\n"; + return 1; + } + + Handle(Graphic3d_GraphicDriver) aDriver = + Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver()); + if (aDriver.IsNull()) + { + std::cerr << "Graphic driver not available.\n"; + return 1; + } + + if (theArgNb < 2) + { + //theDI << "VBO: " << aDriver->ToUseVBO() << "\n"; + //return 0; + std::cerr << "Wrong number of arguments.\n"; + return 1; + } + + aDriver->EnableVBO (atoi(theArgVec[1]) != 0); + return 0; +} + //======================================================================= //function : ViewerCommands //purpose : @@ -2783,4 +2873,10 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) " : Mode - rectangular or circular" " : Type - lines or points", __FILE__, VGrid, group); + theCommands.Add ("vfps", + "vfps [framesNb=100] : estimate average frame rate for active view", + __FILE__, VFps, group); + theCommands.Add ("vvbo", + "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects", + __FILE__, VVbo, group); }