[vtkusers] Re: Adding fps-info to renderer

Goodwin Lawlor goodwin.lawlor at ucd.ie
Thu Nov 23 05:23:46 EST 2006


Martin Baumann wrote:
> Hi,
> 
> can you give me an idea of how to updated the string that contains
> the framerate automatically with every new frame?

Something like:

class vtkFPSCallback : public vtkCommand
{
public:
   static vtkFPSCallback *New()
     { return new vtkFPSCallback; }

   void SetTextActor(vtkTextActor *txt)
     {
     this->TextActor = txt;
     }

   virtual void Execute(vtkObject *caller, unsigned long, void*)
     {
     vtkRenderer *ren = reinterpret_cast<vtkRenderer *>(caller);
     float fps = 1.0/ren->GetLastRenderTimeInSeconds();
     sprintf(this->TextBuff,"%.1f", fps);
     this->TextActor->SetInput(this->TextBuff);
     }
protected:
   vtkTextActor *TextActor;
   char TextBuff[128];
};

//...
//...


   vtkFPSCallback *UpdateFPS = vtkFPSCallback::New();
     UpdateFPS->SetTextActor(txt);
     ren1->AddObserver(vtkCommand::EndEvent,UpdateFPS);



hth

Goodwin




More information about the vtkusers mailing list