From e6de10000c68da7bf03f6c2641022c8a5295de1f Mon Sep 17 00:00:00 2001 From: apo Date: Thu, 29 Sep 2005 12:09:56 +0000 Subject: [PATCH] To imporve VISU_FPSActor --- src/VVTK/VVTK_Renderer.cxx | 131 ++++++++++++++++++------------------- src/VVTK/VVTK_Renderer.h | 7 +- 2 files changed, 67 insertions(+), 71 deletions(-) diff --git a/src/VVTK/VVTK_Renderer.cxx b/src/VVTK/VVTK_Renderer.cxx index 3c83b3c7..6b075ff5 100644 --- a/src/VVTK/VVTK_Renderer.cxx +++ b/src/VVTK/VVTK_Renderer.cxx @@ -51,14 +51,6 @@ #include #include -#include "utilities.h" - -#ifdef _DEBUG_ -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; -#endif - #include #include #include @@ -69,59 +61,69 @@ static int MYDEBUG = 0; #include #include #include -// -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 (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; +int +VISU_FPSActor +::RenderOpaqueGeometry(vtkViewport *theViewport) +{ + + if(vtkRenderer *aRenderer = dynamic_cast(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(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: "<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()); + + 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 diff --git a/src/VVTK/VVTK_Renderer.h b/src/VVTK/VVTK_Renderer.h index c48f7c1c..5b0bce8c 100644 --- a/src/VVTK/VVTK_Renderer.h +++ b/src/VVTK/VVTK_Renderer.h @@ -34,10 +34,9 @@ #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 myImplicitFunctionWidget; - vtkSmartPointer myTextActor; + vtkSmartPointer myTextActor; }; -- 2.39.2