From: pkv Date: Tue, 27 Sep 2005 14:31:46 +0000 (+0000) Subject: Add functionality to display the rendering performance (FPS) of the vtk viewer X-Git-Tag: BR-D5-38-2003_D2005-12-10~130 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=944f3e80de46db0d75a63177fe3bb1b9203ae556;p=modules%2Fvisu.git Add functionality to display the rendering performance (FPS) of the vtk viewer --- diff --git a/src/VVTK/VVTK_Renderer.cxx b/src/VVTK/VVTK_Renderer.cxx index 8060c0ec..625e2fbe 100644 --- a/src/VVTK/VVTK_Renderer.cxx +++ b/src/VVTK/VVTK_Renderer.cxx @@ -40,6 +40,17 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "utilities.h" #ifdef _DEBUG_ @@ -48,6 +59,70 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +class VISU_FPSTextActor : public vtkTextActor { +public: + vtkTypeMacro( VISU_FPSTextActor, vtkTextActor); + static VISU_FPSTextActor* New(); + virtual int RenderOpaqueGeometry(vtkViewport *theViewport); +}; +// +vtkStandardNewMacro(VISU_FPSTextActor); +// +//====================================================================== +// function: RenderOpaqueGeometry +// purpose : +//====================================================================== +int VISU_FPSTextActor::RenderOpaqueGeometry(vtkViewport *theViewport) { + + vtkRenderer *pRenderer= dynamic_cast (theViewport); + if (pRenderer){ + float aTS, aTol=1.e-6; + char buf[128]={"Divide by zero"}; + // + aTS =pRenderer->GetLastRenderTimeInSeconds (); + if (aTS>aTol) { + vtkProp *pProp; + int iCount=0; + // + vtkPropCollection *pProps=pRenderer->GetProps(); + pProps->InitTraversal(); + for (; 1; ) { + pProp=pProps->GetNextProp(); + if(!pProp) { + break; + } + vtkActor *pActor=dynamic_cast (pProp); + if (pActor){ + if (pProp->GetVisibility()) { + vtkMapper *pMapper=pActor->GetMapper(); + vtkPolyDataMapper *pPDMapper=dynamic_cast (pMapper); + if (pPDMapper){ + vtkPolyData *pPolyData=pPDMapper->GetInput(); + int aNbC=pPolyData->GetNumberOfCells(); + iCount+=aNbC; + } + } + } + } + float aTS1=1./aTS; + sprintf(buf, "\n FPS: %.2f \nNbCells: %d ", aTS1, iCount); + } + SetInput(buf); + } + // + Superclass::RenderOpaqueGeometry(theViewport); +} //---------------------------------------------------------------------------- vtkStandardNewMacro(VVTK_Renderer1); @@ -66,6 +141,28 @@ VVTK_Renderer1 //aPlaneProperty->SetOpacity(aSelectedPlaneProperty->GetOpacity()*1.5); myImplicitFunctionWidget->Delete(); + // + vtkSmartPointermyTextMapper; + myTextMapper=vtkTextMapper::New(); + myTextActor=VISU_FPSTextActor::New(); + // + myTextMapper->Delete(); + myTextActor->Delete(); + // + vtkTextProperty *pTextProperty=myTextMapper->GetTextProperty(); + pTextProperty->SetJustificationToRight(); + pTextProperty->SetVerticalJustificationToTop(); + pTextProperty->SetFontSize(10); + pTextProperty->SetOpacity (0.75); + // + myTextActor->SetMapper(myTextMapper.GetPointer()); + myTextActor->SetPickable(false); + myTextActor->ScaledTextOff(); + myTextActor->SetAlignmentPoint(8); + myTextActor->SetPosition2 (1., 1.); + // + vtkRenderer* pRenderer=GetDevice(); + pRenderer->AddActor2D(myTextActor.GetPointer()); } VVTK_Renderer1 diff --git a/src/VVTK/VVTK_Renderer.h b/src/VVTK/VVTK_Renderer.h index 543a919a..c48f7c1c 100644 --- a/src/VVTK/VVTK_Renderer.h +++ b/src/VVTK/VVTK_Renderer.h @@ -36,6 +36,9 @@ class VISU_ImplicitFunctionWidget; class vtkImplicitFunction; +class vtkViewport; +class VISU_FPSTextActor; + //---------------------------------------------------------------------------- class VVTK_EXPORT VVTK_Renderer1 : public SVTK_Renderer { @@ -67,6 +70,7 @@ class VVTK_EXPORT VVTK_Renderer1 : public SVTK_Renderer OnAdjustActors(); vtkSmartPointer myImplicitFunctionWidget; + vtkSmartPointer myTextActor; };