[vtkusers] VTK with FLTK

dolivier at unina.it dolivier at unina.it
Mon Oct 13 06:39:42 EDT 2003


Dear Vtk User,
I'm trying to implement FLTK in a VTK project.
I'm not able to use neither the example files, somebody can help me?
I use Microsoft Visual Studio c++ like compilator, but I don't know which are 
the settings to give to the project.
Down is reported the code about the example files.
Best Regards and tahnks to alla of you.
Dario

// Cone3.cxx adapted to illustrate the use of vtkFlRenderWindowInteractor
// $Id: Cone3.cxx,v 1.6 2002/06/24 13:20:30 cpbotha Exp $
// Study this example carefully.  Study it again.  Repeat.

// here we have all the usual VTK stuff that we need for our pipeline
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>

// and here we have the famous vtkFlRenderWindowInteractor class
#include <vtkFlRenderWindowInteractor.h>

// and of course some fltk stuff
#include <Fl/Fl_Box.h>
#include <Fl/Fl_Button.h>

// this is a callback for the quit button
void quit_cb(Fl_Widget*, void*)
{
   exit(0);
}

int main( int argc, char *argv[] )
{
   // set up main FLTK window
   Fl_Window* main_window = new Fl_Window(300,330,"Cone3.cxx");
   
   // and instantiate vtkFlRenderWindowInteractor (here it acts like a FLTK 
window,
   // i.e. you could also instantiate it as child of a Fl_Group in a window)
   vtkFlRenderWindowInteractor* fl_vtk_window = new vtkFlRenderWindowInteractor
(5,5,290,260,NULL);

   // this will result in a little message under the rendering
   Fl_Box* box = new Fl_Box(5,261,290,34,"3 = stereo, j = joystick, t = 
trackball, w = wireframe, s = surface, p = pick; you can also resize the 
window");
   box->labelsize(10);
   box->align(FL_ALIGN_WRAP);
   
   // we want a button with which the user can quit the application
   Fl_Button* quit_button = new Fl_Button(100,300,100,25,"quit");
   quit_button->callback(quit_cb,NULL);
   
   // we're done populating the main_window
   main_window->end();
   // if the main window gets resized, the vtk window should resize with it
   main_window->resizable(fl_vtk_window);
   
   // these two steps are VERY IMPORTANT, you have to show() the fltk window
   // containing the vtkFlRenderWindowInteractor, and then the
   // vtkFlRenderWindowInteractor itself
   main_window->show();
   fl_vtk_window->show();
   
   // now we get to setup our VTK rendering pipeline
   
   // create a rendering window and renderer
   vtkRenderer *ren = vtkRenderer::New();
   vtkRenderWindow *renWindow = vtkRenderWindow::New();
   renWindow->AddRenderer(ren);
   // uncomment the statement below if things aren't rendering 100% on your
   // configuration; the debug output could give you clues as to why
   //renWindow->DebugOn();
   
   // NB: here we treat the vtkFlRenderWindowInteractor just like any other
   // old vtkRenderWindowInteractor
   fl_vtk_window->SetRenderWindow(renWindow);
   // just like with any other vtkRenderWindowInteractor(), you HAVE to call
   // Initialize() before the interactor will function.  See the docs in
   // vtkRenderWindowInteractor.h
   fl_vtk_window->Initialize();

   // create an actor and give it cone geometry
   vtkConeSource *cone = vtkConeSource::New();
   cone->SetResolution(8);
   vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
   coneMapper->SetInput(cone->GetOutput());
   vtkActor *coneActor = vtkActor::New();
   coneActor->SetMapper(coneMapper);

   // assign our actor to the renderer
   ren->AddActor(coneActor);

   // We can now delete all our references to the VTK pipeline (except for
   // our reference to the vtkFlRenderWindowInteractor) as the objects
   // themselves will stick around until we dereference fl_vtk_window
   ren->Delete();
   renWindow->Delete();
   cone->Delete();
   coneMapper->Delete();
   coneActor->Delete();

   // this is the standard way of "starting" a fltk application
   int fl_ret = Fl::run();
   
   // very huge NB: note that we ->Delete() the vtkFlRenderWindowInteractor
   // once we do this, the rest of the vtk pipeline will really disappear
   fl_vtk_window->Delete();
   // and after we've done that, we can delete the main_window
   delete main_window;
   
   return fl_ret;
}

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/




More information about the vtkusers mailing list