<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I'm working on adding user interface on my VTK
application, is using the famous "vtkFlRenderWindowInteractor (0.9)". However,
there is problems in saving the image correctly, the saved imaged is always
deformed seriously. Following is the Cone3.cpp code. A "save" button is added,
everything else is the same as before. The libraries I used are VTK
4.4 and FLTK 1.1.5. The application is running under RedHat 9.0 shrike. One
odd thing is if run exactly same code under RH 8.0, everything work
fine.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Can anyone help me out? Thanks a lot.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>chuang</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>// Cone3.cxx adapted to illustrate the use of
vtkFlRenderWindowInteractor<BR>// $Id: Cone3.cxx,v 1.7 2002/12/30 14:51:26
cpbotha Exp $<BR>// Study this example carefully. Study it again.
Repeat.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>// here we have all the usual VTK stuff that we
need for our pipeline<BR>#include <vtkRenderer.h><BR>#include
<vtkRenderWindow.h><BR>#include <vtkConeSource.h><BR>#include
<vtkPolyDataMapper.h><BR>#include <vtkActor.h><BR>#include
<vtkWindowToImageFilter.h><BR>#include <vtkJPEGWriter.h><BR>#include
<vtkPNGWriter.h><BR>#include <vtkTIFFWriter.h><BR>#include
<vtkBMPWriter.h><BR>#include <vtkRendererCollection.h><BR>#include
<vtkRendererSource.h></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>// and here we have the famous
vtkFlRenderWindowInteractor class<BR>#include
<vtkFlRenderWindowInteractor.h></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// and of course some fltk stuff<BR>#include
<Fl/Fl_Box.h><BR>#include <Fl/Fl_Button.h></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// this is a callback for the quit button<BR>void
quit_cb(Fl_Widget*, void*)<BR>{<BR> exit(0);<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// this callback gets called when the main window
is closed<BR>// remember that one should NEVER delete() a
vtkFlRenderWindowInteractor,<BR>// since it's a vtk object. instead, its
Delete() method should be used.<BR>// so, in the callback of the containing
window, you should either terminate<BR>// your application (if that's
applicable) or if you have a multi-window <BR>// application, call ->Delete()
on the vtkFlRWI and then take care of the<BR>// surrounding logic.<BR>void
main_window_callback(Fl_Widget *w, void
*fl_vtk_window)<BR>{<BR> exit(0);<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>void save_callback(Fl_Widget *w, void
*fl_vtk_window)<BR>{<BR> vtkFlRenderWindowInteractor *fw =
(vtkFlRenderWindowInteractor *)fl_vtk_window;<BR> vtkRenderWindow *rw =
fw->GetRenderWindow();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> vtkRendererCollection *rc =
rw->GetRenderers();<BR> rc->InitTraversal();<BR> vtkRenderer *rr
= rc->GetNextItem();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> vtkRendererSource *rsrc =
vtkRendererSource::New();<BR> rsrc->SetInput(rr);<BR> rsrc->WholeWindowOn();<BR> rsrc->RenderFlagOn();<BR> rsrc->DepthValuesOff(); <BR> rsrc->DepthValuesInScalarsOff();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> //vtkWindowToImageFilter *w2i =
vtkWindowToImageFilter::New();<BR> //w2i->SetInput(rsrc->GetOutput());
</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> //vtkPNGWriter *writer =
vtkPNGWriter::New();<BR> vtkJPEGWriter *writer =
vtkJPEGWriter::New();<BR> //vtkTIFFWriter *writer =
vtkTIFFWriter::New();<BR> //vtkBMPWriter *writer =
vtkBMPWriter::New();<BR> writer->SetInput(rsrc->GetOutput());<BR> //writer->SetFileName("cones.png");<BR> writer->SetFileName("cones.jpg");<BR> writer->Write();
<BR> writer->Delete();<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>int main( int argc, char *argv[]
)<BR>{<BR> // set up main FLTK window<BR> Fl_Window*
main_window = new Fl_Window(300,330,"Cone3.cxx");<BR>
<BR> // and instantiate vtkFlRenderWindowInteractor (here it acts
like a FLTK window,<BR> // i.e. you could also instantiate it as
child of a Fl_Group in a window)<BR> vtkFlRenderWindowInteractor*
fl_vtk_window = new
vtkFlRenderWindowInteractor(5,5,290,260,NULL);<BR>
<BR> main_window->callback(main_window_callback,
fl_vtk_window);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> // this will result in a little
message under the rendering<BR> 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");<BR>
box->labelsize(10);<BR>
box->align(FL_ALIGN_WRAP);<BR> <BR> // we want a
button with which the user can quit the application<BR> Fl_Button*
quit_button = new Fl_Button(30,300,100,25,"quit");<BR>
quit_button->callback(quit_cb, NULL);<BR> <BR>
Fl_Button* save_button = new Fl_Button(160,300,100,25,"save");<BR>
save_button->callback(save_callback, (void *) fl_vtk_window);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> // we're done populating the
main_window<BR> main_window->end();<BR> // if the
main window gets resized, the vtk window should resize with it<BR>
main_window->resizable(fl_vtk_window);<BR> <BR> //
these two steps are VERY IMPORTANT, you have to show() the fltk
window<BR> // containing the vtkFlRenderWindowInteractor, and then
the<BR> // vtkFlRenderWindowInteractor itself<BR>
main_window->show();<BR>
fl_vtk_window->show();<BR> <BR> // now we get to
setup our VTK rendering pipeline<BR> <BR> // create a
rendering window and renderer<BR> vtkRenderer *ren =
vtkRenderer::New();<BR> vtkRenderWindow *renWindow =
vtkRenderWindow::New();<BR>
renWindow->AddRenderer(ren);<BR> // uncomment the statement below
if things aren't rendering 100% on your<BR> // configuration; the
debug output could give you clues as to why<BR>
//renWindow->DebugOn();<BR> <BR> // NB: here we treat
the vtkFlRenderWindowInteractor just like any other<BR> // old
vtkRenderWindowInteractor<BR>
fl_vtk_window->SetRenderWindow(renWindow);<BR> // just like with
any other vtkRenderWindowInteractor(), you HAVE to call<BR> //
Initialize() before the interactor will function. See the docs
in<BR> // vtkRenderWindowInteractor.h<BR>
fl_vtk_window->Initialize();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> // create an actor and give it cone
geometry<BR> vtkConeSource *cone =
vtkConeSource::New();<BR> cone->SetResolution(8);<BR>
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();<BR>
coneMapper->SetInput(cone->GetOutput());<BR> vtkActor
*coneActor = vtkActor::New();<BR>
coneActor->SetMapper(coneMapper);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> // assign our actor to the
renderer<BR> ren->AddActor(coneActor);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> // We can now delete all our
references to the VTK pipeline (except for<BR> // our reference to
the vtkFlRenderWindowInteractor) as the objects<BR> // themselves
will stick around until we dereference fl_vtk_window<BR>
ren->Delete();<BR> renWindow->Delete();<BR>
cone->Delete();<BR> coneMapper->Delete();<BR>
coneActor->Delete();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> // this is the standard way of
"starting" a fltk application<BR> int fl_ret =
Fl::run();<BR> //fl_vtk_window->Start();<BR>
<BR> // very huge NB: note that we ->Delete() the
vtkFlRenderWindowInteractor<BR> // once we do this, the rest of the
vtk pipeline will really disappear<BR>
fl_vtk_window->Delete();<BR> // and after we've done that, we can
delete the main_window<BR> delete main_window;<BR>
<BR> return 1;<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>