#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>
#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;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
VVTK_Renderer1
::VVTK_Renderer1():
- myImplicitFunctionWidget(VISU_ImplicitFunctionWidget::New())
+ myImplicitFunctionWidget(VISU_ImplicitFunctionWidget::New()),
+ myTextActor(VISU_FPSActor::New())
{
if(MYDEBUG) INFOS("VVTK_Renderer1() - "<<this);
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