]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Add functionality to display the rendering performance (FPS) of the vtk viewer
authorpkv <pkv@opencascade.com>
Tue, 27 Sep 2005 14:31:46 +0000 (14:31 +0000)
committerpkv <pkv@opencascade.com>
Tue, 27 Sep 2005 14:31:46 +0000 (14:31 +0000)
src/VVTK/VVTK_Renderer.cxx
src/VVTK/VVTK_Renderer.h

index 8060c0ec7dee891b5f9b1d775e29cee1b0b49631..625e2fbe880366f5c3e7153d6ce484e7a818b62c 100644 (file)
 #include <vtkCommand.h>
 #include <vtkPlane.h>
 
+#include <vtkPropCollection.h>
+#include <vtkProp.h>
+#include <vtkActor.h>
+#include <vtkMapper.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkPolyData.h>
+#include <vtkTextMapper.h>
+#include <vtkTextActor.h> 
+#include <vtkTextProperty.h>
+#include <vtkRenderer.h>
+
 #include "utilities.h"
 
 #ifdef _DEBUG_
@@ -48,6 +59,70 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
+#include <vtkPropCollection.h>
+#include <vtkProp.h>
+#include <vtkActor.h>
+#include <vtkMapper.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkPolyData.h>
+#include <vtkTextMapper.h>
+#include <vtkTextActor.h> 
+#include <vtkTextProperty.h>
+#include <vtkRenderer.h>
+//
+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 <vtkRenderer*>(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 <vtkActor*>(pProp);
+       if (pActor){
+         if (pProp->GetVisibility()) {
+           vtkMapper *pMapper=pActor->GetMapper();
+           vtkPolyDataMapper *pPDMapper=dynamic_cast <vtkPolyDataMapper*>(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();
+  //
+  vtkSmartPointer<vtkTextMapper>myTextMapper;
+  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
index 543a919afcdf911a81abcb84631776be1c8cc93a..c48f7c1cfd1e83807eee46506de28c0ed8096c36 100644 (file)
@@ -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<VISU_ImplicitFunctionWidget> myImplicitFunctionWidget;
+  vtkSmartPointer<VISU_FPSTextActor> myTextActor;
 };