#include "vtkConeSource.h"
#include "vtkCommand.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Button.H>
#include "vtkFLTKInstantiator.h"
class vtkRendererObserver : public vtkCommand
{
public:
static vtkRendererObserver* New (void) { return new vtkRendererObserver; }
void SetOutputWidget (Fl_Output* a) { this->OutputWidget = a; }
void Execute (vtkObject* aCaller, unsigned long aEID, void* aCallData)
{
vtkRenderer* renderer = static_cast<vtkRenderer*>(aCaller);
int n = renderer->GetNumberOfPropsRendered();
double t = renderer->GetLastRenderTimeInSeconds() * 1000.0;
(void) sprintf(this->Buffer, "%d props in %g ms.", n, t);
this->OutputWidget->value(this->Buffer);
if (!this->OutputWidget->window()->shown())
{
this->OutputWidget->window()->show();
}
}
protected:
vtkRendererObserver (void) : OutputWidget(0) { this->Buffer[0] = '\0'; }
Fl_Output* OutputWidget;
char Buffer[256];
private:
vtkRendererObserver (const vtkRendererObserver&);
void operator= (const vtkRendererObserver&);
};
VTK_FLTK_IMPLEMENT(void)
ShowCb (Fl_Widget*, void* aPtr)
{
vtkRenderWindow* renderWindow = reinterpret_cast<vtkRenderWindow*>(aPtr);
if (!renderWindow->GetMapped()) renderWindow->Render();
}
VTK_FLTK_IMPLEMENT(void)
QuitCb (Fl_Widget*, void*) { exit(0); }
int
main (int argc, char* argv[])
{
vtkActor* coneActor = vtkActor::New();
vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
vtkConeSource* coneSource = vtkConeSource::New();
coneMapper->SetInput(coneSource->GetOutput());
coneSource->Delete();
coneActor->SetMapper(coneMapper);
coneMapper->Delete();
vtkRenderer* renderer = vtkRenderer::New();
renderer->AddProp(coneActor);
coneActor->Delete();
vtkRenderWindow* renderWindow = vtkRenderWindow::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(300, 300);
renderWindow->SetPosition(30, 30);
vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();
interactor->SetRenderWindow(renderWindow);
renderWindow->SetWindowName(interactor->GetClassName());
int x = renderWindow->GetPosition()[0] + renderWindow->GetSize()[0] + 10;
int y = renderWindow->GetPosition()[1];
Fl_Window* mainWindow = new Fl_Window(x,y,240,95, "Simple2");
Fl_Box* titleBox = new Fl_Box(5,5,230,25, renderWindow->GetClassName());
Fl_Output* textOutput = new Fl_Output(5,35,230,25);
Fl_Button* showButton = new Fl_Button(55,65,60,25, "show");
Fl_Button* quitButton = new Fl_Button(125,65,60,25, "quit");
mainWindow->end();
showButton->callback(ShowCb, (void *) renderWindow);
quitButton->callback(QuitCb, NULL);
mainWindow->callback(QuitCb, NULL);
vtkRendererObserver* renObserver = vtkRendererObserver::New();
renObserver->SetOutputWidget(textOutput);
renderer->AddObserver(vtkCommand::EndEvent, renObserver);
renObserver->Delete();
interactor->Start();
interactor->Delete();
delete mainWindow;
return 0;
}