[vtkusers] RE: vtk and fltk problem

Dai Chong ascdai at yahoo.com
Sat Sep 16 01:59:03 EDT 2000


Dear Robert,

Currently I am working on both Windows NT and UNIX.
In order to use FLTK on NT, you must include both
fltk.lib and wsock32.lib. 

The following is a sample program I have made for you.
After running the program, a small FLTK window will
appear, just press "show" button and a VTK window will
appear and a low resolution Cone will be shown. Press
"test" button, the Cone will be changed to high
resolution. "close" will close the VTK window. and
"exit" will cause the program to quit.

Note I have commented the " iren->start()",because I
found that I could do the mouse interaction even
without this command. The only bug is that you cannot
close the VTK window using "X" button on the upper
right corner of the window. 

But if you use "iren->start()",there will be another
question, that is the press state of FLTK button will
not show correctly.For example, if you press "show",
then press "test" the visual effect of pressing down
the "test" button will not be shown, but you still can
change the resolution of the Cone.In this case you can
close the VTK window using the "X" button, this will
not close the whole program as it does in UNIX.  
 
cheers,
Dai Chong

/*------------------------fltkvtk_nt.cxx
2000.09.16----------------------------*/
/* In this program, a combination of FLTK and VTK  on
Windows NT4.0 is tested,
   writen by Dai Chong 
*/

#include <stdlib.h>
#include <stdio.h>

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>

#include "vtkRenderer.h"


#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"

#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"

class pub1 {
public:
	int count;
};//class for store some local public var

class pub1 mypub1;

// create a rendering window and renderer
  vtkRenderer *ren;// = vtkRenderer::New();
  
  vtkRenderWindow *renWindow;// =
vtkRenderWindow::New();
  vtkRenderWindowInteractor *iren;// =
vtkRenderWindowInteractor::New();


// create an actor and give it cone geometry
  vtkConeSource *cone = vtkConeSource::New();
  vtkPolyDataMapper *coneMapper =
vtkPolyDataMapper::New();
  vtkActor *coneActor = vtkActor::New();
    


 void showcb(Fl_Widget *, void *) {

  //to open a single window in multiple press
  //static int mypub1.count=0;
  if(mypub1.count!=0){
    return;
  }
  
  ren = vtkRenderer::New();
  
  renWindow = vtkRenderWindow::New();
  iren = vtkRenderWindowInteractor::New();
  mypub1.count=1;

  renWindow->SetWindowName("testme.cxx");
  renWindow->AddRenderer(ren);
  iren->SetRenderWindow(renWindow);

  renWindow->SetSize( 300, 300 );
  
  // assign our actor to the renderer
  ren->AddActor(coneActor);	

  
  // draw the resulting scene
  //renWindow->Render();
  iren->Render();

  //vtkInteractorStyle *istyle=
vtkInteractorStyle::New();
  //istyle->SetInteractor(iren);

  
  printf("\nmypub1.count before iren->Start is
%d",mypub1.count);//test

  //  Begin mouse interaction
  //iren->Start(); //you can uncommnent this part to
see the difference.
 
  printf("\nmypub1.count after iren->Start is
%d\n",mypub1.count);//test

  
}

void testcb(Fl_Widget *, void *){
  printf("\nTest button is pressed");
  cone->SetResolution(100);
  coneMapper->SetInput(cone->GetOutput());
  coneActor->SetMapper(coneMapper);
  iren->Render();
}

void closecb(Fl_Widget *, void *) {
  // Clean up
  if(renWindow!=NULL){
  ren->Delete();
  renWindow->Delete();
  iren->Delete();
  renWindow=NULL;//indicate the object has been
distoried
  mypub1.count=0;
  }
}

void exitcb(Fl_Widget *, void *) {
  // Clean up
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  exit(0);
}

int main(int argc, char ** argv) {
 
  cone->SetResolution(8);
  coneMapper->SetInput(cone->GetOutput());
  coneActor->SetMapper(coneMapper);
  //initialze
   
  Fl_Window *window = new Fl_Window(420,65);
  Fl_Button *b1 = new Fl_Button(20, 20, 80, 25,
"&Show");
  b1->callback(showcb,0);
  Fl_Button *b2 = new Fl_Button(120,20, 80, 25,
"&Test");
  b2->callback(testcb,0);
  Fl_Button *b3 = new Fl_Button(220,20, 80, 25,
"Cl&ose");
  b3->callback(closecb,0);
  Fl_Button *b4 = new Fl_Button(320,20, 80, 25,
"E&xit");
  b4->callback(exitcb,0);
  window->end();
  window->show(argc,argv);

  return Fl::run();
}

-----Original Message-----
From: Robert Yu [mailto:robertyu_2000 at yahoo.com]
Sent: Thursday, September 14, 2000 10:13 PM
To: ascdai at yahoo.com
Subject: vtk and fltk problem 


Dear Dai Chong: 

  Sorry to ask you this question though the email.
I am trying to develop the vtk application under 
fltk in PC window system.  But don't know how to 
get started.  I saw you post the question in the 
vtk mailing list, I wonder whether you got your 
questions solved?  Would that be possible to 
have any of your sample codes to learn the vtk + fltk
? (PC window would be the best).  Thanks for help. 

 Robert Yu

__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/




More information about the vtkusers mailing list