]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To imporve VISU_FPSActor
authorapo <apo@opencascade.com>
Thu, 29 Sep 2005 12:09:56 +0000 (12:09 +0000)
committerapo <apo@opencascade.com>
Thu, 29 Sep 2005 12:09:56 +0000 (12:09 +0000)
src/VVTK/VVTK_Renderer.cxx
src/VVTK/VVTK_Renderer.h

index 3c83b3c7e7e924f7ab4de38e27d69ab7ce4c4155..6b075ff5a04d40d094e5a95f09255c23e4591265 100644 (file)
 #include <vtkTextProperty.h>
 #include <vtkRenderer.h>
 
-#include "utilities.h"
-
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
 #include <vtkPropCollection.h>
 #include <vtkProp.h>
 #include <vtkActor.h>
@@ -69,59 +61,69 @@ static int MYDEBUG = 0;
 #include <vtkTextActor.h> 
 #include <vtkTextProperty.h>
 #include <vtkRenderer.h>
-//
-class VISU_FPSTextActor : public vtkTextActor {
+
+#include "utilities.h"
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+//======================================================================
+class VISU_FPSActor : public vtkTextActor 
+{
 public:
-  vtkTypeMacro( VISU_FPSTextActor, vtkTextActor);
-  static  VISU_FPSTextActor* New();
-  virtual int RenderOpaqueGeometry(vtkViewport *theViewport);
+  vtkTypeMacro( VISU_FPSActor, vtkTextActor);
+  static
+  VISU_FPSActor* 
+  New();
+
+  virtual
+  int
+  RenderOpaqueGeometry(vtkViewport *theViewport);
 };
-//
-vtkStandardNewMacro(VISU_FPSTextActor);
-//
+
+//======================================================================
+vtkStandardNewMacro(VISU_FPSActor);
+
 //======================================================================
 // 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;
+int
+VISU_FPSActor
+::RenderOpaqueGeometry(vtkViewport *theViewport) 
+{
+
+  if(vtkRenderer *aRenderer = dynamic_cast<vtkRenderer*>(theViewport)){
+    static float aTol = 1.e-6;
+    float aLastRenderTimeInSeconds = aRenderer->GetLastRenderTimeInSeconds();
+    if(aLastRenderTimeInSeconds > aTol){
+      size_t aNumberOfCells = 0;
+      if(vtkActorCollection *anActorCollection = aRenderer->GetActors()){
+       anActorCollection->InitTraversal();
+       while(vtkActor *anActor = anActorCollection->GetNextActor()){
+         if(anActor->GetVisibility()){
+           if(SALOME_Actor *aSActor = dynamic_cast<SALOME_Actor*>(anActor)){
+             if(vtkMapper *aMapper = aSActor->GetMapper()){
+               if(vtkDataSet *aDataSet = aMapper->GetInput()){
+                 aNumberOfCells += aDataSet->GetNumberOfCells();
+               }
+             }
            }
          }
        }
       }
-      float aTS1=1./aTS;
-      sprintf(buf, "\n FPS: %.2f \nNbCells: %d ", aTS1, iCount);
+      std::ostringstream aStr;
+      float aFPS = 1.0 / aLastRenderTimeInSeconds;
+      aStr<<"FPS: "<<aFPS<<"; NumberOfCells: "<<aNumberOfCells;
+      std::string anInput = aStr.str();
+      SetInput(anInput.c_str());
+      return Superclass::RenderOpaqueGeometry(theViewport);
     }
-    SetInput(buf);
   }
-  //
-  Superclass::RenderOpaqueGeometry(theViewport);
+  return 1;
 }
 
 //----------------------------------------------------------------------------
@@ -130,7 +132,8 @@ vtkStandardNewMacro(VVTK_Renderer1);
 //----------------------------------------------------------------------------
 VVTK_Renderer1
 ::VVTK_Renderer1():
-  myImplicitFunctionWidget(VISU_ImplicitFunctionWidget::New())
+  myImplicitFunctionWidget(VISU_ImplicitFunctionWidget::New()),
+  myTextActor(VISU_FPSActor::New())
 {
   if(MYDEBUG) INFOS("VVTK_Renderer1() - "<<this);
 
@@ -141,28 +144,22 @@ 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());
+
+  vtkTextMapper* aTextMapper = vtkTextMapper::New();
+  vtkTextProperty *aTextProperty = aTextMapper->GetTextProperty();
+  aTextProperty->SetJustificationToRight();
+  aTextProperty->SetVerticalJustificationToTop();
+  aTextProperty->SetFontSize(10);
+
   myTextActor->SetPickable(false); 
   myTextActor->ScaledTextOff();
   myTextActor->SetAlignmentPoint(8);
   myTextActor->SetPosition2 (1., 1.);
-  //
-  vtkRenderer* pRenderer=GetDevice();
-  pRenderer->AddActor2D(myTextActor.GetPointer());
+  myTextActor->SetMapper(aTextMapper);
+  aTextMapper->Delete();
+
+  GetDevice()->AddActor2D(myTextActor.GetPointer());
 }
 
 VVTK_Renderer1
index c48f7c1cfd1e83807eee46506de28c0ed8096c36..5b0bce8c86f17e6eef2c053f8f640fef58cae924 100644 (file)
 #include "SVTK_Renderer.h"
 
 class VISU_ImplicitFunctionWidget;
-class vtkImplicitFunction;
+class VISU_FPSActor;
 
-class vtkViewport;
-class VISU_FPSTextActor;
+class vtkImplicitFunction;
 
 //----------------------------------------------------------------------------
 class VVTK_EXPORT VVTK_Renderer1 : public SVTK_Renderer
@@ -70,7 +69,7 @@ class VVTK_EXPORT VVTK_Renderer1 : public SVTK_Renderer
   OnAdjustActors();
 
   vtkSmartPointer<VISU_ImplicitFunctionWidget> myImplicitFunctionWidget;
-  vtkSmartPointer<VISU_FPSTextActor> myTextActor;
+  vtkSmartPointer<VISU_FPSActor> myTextActor;
 };