1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-16 10:54:53 +03:00

0023065: This is desirable to add general DRAW command to estimate visualization performance

Added vfps command to estimate average frame rate of 3D Viewer
Simplified vdrawsphere command

Removed turnVbo and performance measurements from vdrawsphere.
Added vvbo command to control VBO usage flag.
This commit is contained in:
kgv 2012-04-06 12:33:47 +04:00
parent a28f034bfa
commit 208e6839be
5 changed files with 130 additions and 71 deletions

View File

@ -76,6 +76,10 @@ is
-- the Timer. -- the Timer.
---Level: Public ---Level: Public
ElapsedTime (me : in out) returns Real;
---Purpose: Returns elapsed time in seconds.
---Level: Public
fields fields
TimeStart : Real; TimeStart : Real;

View File

@ -131,6 +131,22 @@ void OSD_Timer::Show ()
Show (cout); Show (cout);
} }
//=======================================================================
//function : ElapsedTime
//purpose :
//=======================================================================
Standard_Real OSD_Timer::ElapsedTime()
{
if (!Stopped)
{
// update cumulative time
Stop();
Start();
}
return TimeCumul;
}
//======================================================================= //=======================================================================
//function : Show //function : Show

View File

@ -310,6 +310,12 @@ Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiStrin
aMap.UnBind2 (theName); aMap.UnBind2 (theName);
} }
if (theAISObj.IsNull())
{
// object with specified name already unbound
return Standard_True;
}
// unbind AIS object if was bound with another name // unbind AIS object if was bound with another name
aMap.UnBind1 (theAISObj); aMap.UnBind1 (theAISObj);

View File

@ -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 aCenterY = (argc > 5) ? atof (argv[4]) : 0.0;
Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0; Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0;
Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0; Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0;
Standard_Boolean isVBOEnabled = (argc > 7) ? atoi (argv[7]) : Standard_True; Standard_Boolean toShowEdges = (argc > 7) ? atoi (argv[7]) : Standard_False;
Standard_Integer aRedrawsNb = (argc > 8) ? atoi (argv[8]) : 1;
Standard_Boolean toShowEdges = (argc > 9) ? atoi (argv[9]) : Standard_False;
if (aRedrawsNb <= 0)
{
aRedrawsNb = 1;
}
// remove AIS object with given name from map // remove AIS object with given name from map
if (GetMapOfAIS().IsBound2 (aShapeName)) VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
{
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);
}
std::cout << "Compute Triangulation...\n"; std::cout << "Compute Triangulation...\n";
Handle(AIS_Triangulation) aShape 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 aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().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 // stupid initialization of Green color in RGBA space as integer
// probably wrong for big-endian CPUs // probably wrong for big-endian CPUs
Standard_Integer aRed = 0; Standard_Integer aRed = 0;
@ -2879,41 +2850,7 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char*
aShAsp->SetAspect (anAspect); aShAsp->SetAspect (anAspect);
aShape->Attributes()->SetShadingAspect (aShAsp); aShape->Attributes()->SetShadingAspect (aShAsp);
aContextAIS->Display (aShape, Standard_False); VDisplayAISObject (aShapeName, aShape);
// 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";
return 0; return 0;
} }
@ -4343,7 +4280,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
__FILE__,VDrawText,group); __FILE__,VDrawText,group);
theCommands.Add("vdrawsphere", 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); __FILE__,VDrawSphere,group);
theCommands.Add("vclipplane", theCommands.Add("vclipplane",

View File

@ -30,6 +30,7 @@
#endif #endif
#include <Graphic3d_AspectMarker3d.hxx> #include <Graphic3d_AspectMarker3d.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_ExportFormat.hxx> #include <Graphic3d_ExportFormat.hxx>
#include <ViewerTest.hxx> #include <ViewerTest.hxx>
#include <ViewerTest_EventManager.hxx> #include <ViewerTest_EventManager.hxx>
@ -45,6 +46,7 @@
#include <Draw_Appli.hxx> #include <Draw_Appli.hxx>
#include <Aspect_PrintAlgo.hxx> #include <Aspect_PrintAlgo.hxx>
#include <Image_PixMap.hxx> #include <Image_PixMap.hxx>
#include <OSD_Timer.hxx>
#include <TColStd_SequenceOfInteger.hxx> #include <TColStd_SequenceOfInteger.hxx>
#include <Visual3d_LayerItem.hxx> #include <Visual3d_LayerItem.hxx>
#include <V3d_LayerMgr.hxx> #include <V3d_LayerMgr.hxx>
@ -1885,7 +1887,7 @@ static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char
Standard_Real minRange = 0. , maxRange = 100. ; Standard_Real minRange = 0. , maxRange = 100. ;
Standard_Integer numIntervals = 10 ; Standard_Integer numIntervals = 10 ;
Standard_Real textHeight = 16. ; Standard_Integer textHeight = 16;
Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT; Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
Standard_Real X = 0., Y = 0. ; 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] ); numIntervals = atoi( argv[3] );
} }
if ( argc > 4 ) if ( argc > 4 )
textHeight = atof( argv[4] ); textHeight = atoi( argv[4] );
if ( argc > 5 ) if ( argc > 5 )
position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] ); position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
if ( argc > 7 ) if ( argc > 7 )
@ -2671,7 +2673,7 @@ static int VGrid (Draw_Interpretor& theDI,
if (aTail == 5) if (aTail == 5)
{ {
aRadiusStep = atof (theArgVec[anIter++]); aRadiusStep = atof (theArgVec[anIter++]);
aDivisionNumber = atof (theArgVec[anIter++]); aDivisionNumber = atoi (theArgVec[anIter++]);
aRotAngle = atof (theArgVec[anIter++]); aRotAngle = atof (theArgVec[anIter++]);
} }
@ -2682,6 +2684,94 @@ static int VGrid (Draw_Interpretor& theDI,
return 0; 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 //function : ViewerCommands
//purpose : //purpose :
@ -2783,4 +2873,10 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
" : Mode - rectangular or circular" " : Mode - rectangular or circular"
" : Type - lines or points", " : Type - lines or points",
__FILE__, VGrid, group); __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);
} }