#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include "Fl_VTK_Window.H"
VTK_FLTK_IMPLEMENT(void)
TimerCb (void* a)
{
Fl_VTK_Window* window = reinterpret_cast<Fl_VTK_Window*>(a);
vtkCamera* camera = window->GetDefaultCamera();
camera->Roll(0.2);
window->Update();
Fl::repeat_timeout(1.0 / 30.0, TimerCb, a);
}
VTK_FLTK_IMPLEMENT(void)
ShowCb (Fl_Widget* aButton, void* aPtr)
{
if ((static_cast<Fl_Button*>(aButton))->value())
{
aButton->label("hide");
reinterpret_cast<Fl_Window*>(aPtr)->show();
}
else
{
aButton->label("show");
reinterpret_cast<Fl_Window*>(aPtr)->hide();
}
}
VTK_FLTK_IMPLEMENT(void)
AnimateCb (Fl_Widget* aButton, void* aPtr)
{
if ((static_cast<Fl_Button*>(aButton))->value())
{
aButton->label("stop");
Fl::add_timeout(0, TimerCb, aPtr);
}
else
{
aButton->label("animate");
Fl::remove_timeout(TimerCb, aPtr);
}
}
VTK_FLTK_IMPLEMENT(void)
PrintCb (Fl_Widget*, void* aPtr)
{
Fl_VTK_Window* w;
if ((w = reinterpret_cast<Fl_VTK_Window*>(aPtr)) != 0)
{
w->GetInteractor()->Print(cerr);
w->GetRenderWindow()->Print(cerr);
}
}
VTK_FLTK_IMPLEMENT(void)
ViewCb (Fl_Widget* aWindow, void* aPtr)
{
reinterpret_cast<Fl_Button*>(aPtr)->label("show");
reinterpret_cast<Fl_Button*>(aPtr)->value(0);
static_cast<Fl_Window*>(aWindow)->hide();
}
VTK_FLTK_IMPLEMENT(void)
QuitCb (Fl_Widget*, void*) { exit(0); }
int
main (int argc, char* argv[])
{
const char* instructions =
"<key>: <action>\n"
" 3: toggle stereo mode\n"
" j|t: toggle joystick | trackball modes\n"
" w|s: toggle wireframe | surface modes\n"
" c|a: toggle camera | actor modes\n"
" p: pick\n"
" r: reset";
Fl_Window* mainWindow = new Fl_Window(300, 140, "Cone4: main");
Fl_Box* box = new Fl_Box(5, 5, 290, 100, instructions);
{
box->labelsize(12);
box->labelfont(FL_COURIER);
box->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
}
Fl_Button* showButton = new Fl_Button( 5, 110, 70, 25, "show");
Fl_Button* animateButton = new Fl_Button( 80, 110, 70, 25, "animate");
Fl_Button* printButton = new Fl_Button(155, 110, 70, 25, "print");
Fl_Button* quitButton = new Fl_Button(235, 110, 60, 25, "quit");
mainWindow->end();
showButton->type(FL_TOGGLE_BUTTON);
animateButton->type(FL_TOGGLE_BUTTON);
Fl_Window* coneWindow = new Fl_Window(400,100, 216,216, "Cone4: cone");
{
Fl_VTK_Window* coneView = new Fl_VTK_Window(12,12, 192,192);
{
coneWindow->resizable(coneView);
coneWindow->end();
vtkActor* coneActor = vtkActor::New();
{
vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
{
vtkConeSource* coneSource = vtkConeSource::New();
{
coneSource->SetResolution(12);
}
coneMapper->SetInput(coneSource->GetOutput());
coneSource->Delete();
}
coneActor->SetMapper(coneMapper);
coneMapper->Delete();
}
coneView->AddProp(coneActor);
animateButton->callback(AnimateCb, (void *) coneView);
printButton->callback(PrintCb, (void *) coneView);
coneWindow->callback(ViewCb, (void *) showButton);
coneActor->Delete();
}
showButton->callback(ShowCb, (void *) coneWindow);
quitButton->callback(QuitCb, NULL);
mainWindow->callback(QuitCb, NULL);
coneWindow->hide();
}
mainWindow->show(argc, argv);
int fl_ret = Fl::run();
delete mainWindow;
delete coneWindow;
return fl_ret;
}