[vtkusers] Re: Adding fps-info to renderer
Martin Baumann
mailsgetlost at web.de
Mon Nov 27 03:15:26 EST 2006
Hi,
thanks for your hint! This could help me a lot!
As I need the frame per second information (that is not 1/render_time!)
I used vtkTimerLog to
do the fps calculations. I think for my case this will work:
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*)
{
static vtkTimerLog* timer = vtkTimerLog::New();
timer->StopTimer();
double fps = 1.0/timer->GetElapsedTime();
timer->StartTimer();
// output to caller object
vtkRenderer *ren = reinterpret_cast<vtkRenderer *>(caller);
float render_time = ren->GetLastRenderTimeInSeconds();
sprintf(this->TextBuff,"fps %.1f\nrender-time %.4f sec", fps, render_time);
this->TextActor->SetInput(this->TextBuff);
// output to console
static int i=0;
++i;
cout << "Frame " << i << "\t" << "Render-Time = " << render_time << " sec"
<< "\t" << "Frame-Rate = " << fps << " 1/sec" << endl;
}
protected:
vtkTextActor *TextActor;
char TextBuff[128];
};
Regards, Martin
Goodwin Lawlor wrote:
> > 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