[vtkusers] Help! problem about vtkFLRenderWindowInteractor...
Yingcai Wu
wycken at msn.com
Sat Jan 15 04:02:58 EST 2005
Hi, all
I have a problem that I cannot fix in my following codes, would you please
help me?
In the following section, I wrote a program that can redraw the windows
using the famous vtkFlRenderWindowInteractor class.
My problem is :
The first drawing of the volume is ok,and then if I move the volume a
little, after i push the redraw button of my program, I cannot operate or
move the volume,otherwise there will be a pop window showing an error, such
that
'con3.exe has encountered a problem and needs to close. We are sorry for
the inconvenience'.
If I do nothing with the first drawing, and immediatly push the redraw
button, there is another error, such that "R6025--runtime error, pure
virtual function call"
By the way, the dataset I used is in the directory of data in vtk source
code, namely
'data/headsq/quarter'.
Looking forward to your help!
Thanks.
Regards,
Ken
Here is my code:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// here we have all the usual VTK stuff that we need for our pipeline
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.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>
#include "vtkVolume16Reader.h"
#include "vtkPolyDataNormals.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkContourFilter.h"
//viewport
vtkFlRenderWindowInteractor *fl_vtk_window = NULL;
//main FLTK window
Fl_Window *main_window = NULL;
// this callback gets called when the main window is closed
// remember that one should NEVER delete() a vtkFlRenderWindowInteractor,
// since it's a vtk object. instead, its Delete() method should be used.
// so, in the callback of the containing window, you should either terminate
// your application (if that's applicable) or if you have a multi-window
// application, call ->Delete() on the vtkfl_vtk_window and then take care
of the
// surrounding logic.
void main_window_callback(Fl_Widget *, void *)
{
exit(0);
}
//
void MarchingCubes();
// this is a callback for the Redraw button
void Redraw(Fl_Widget*, void*)
{
MarchingCubes();
fl_vtk_window->draw();
fl_vtk_window->show();
//error occurs when I click the left-button of mouse on the window.
}
/**
* This will create a Fl_Window with an embedded vtkFlRWI, a label
* with some explanation and a quit button. The pointers that are
* passed are set correctly on return so that they can be used for
* further processing; in our case that means actually building and
* adding a VTK pipeline.
*/
void create_window_with_rwi(vtkFlRenderWindowInteractor *&fl_vtk_window,
Fl_Window *&flw,
char *title)
{
// set up main FLTK window
flw = new Fl_Window(820,820,title);
// 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)
fl_vtk_window = new vtkFlRenderWindowInteractor(5,5,820,780,NULL);
flw->callback(main_window_callback, fl_vtk_window);
// this will result in a little message under the rendering
Fl_Box* box = new Fl_Box(5,800,815,820,
"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(400,790,70,35,"Redraw");
quit_button->callback(Redraw,NULL);
// we're done populating the flw
flw->end();
// if the main window gets resized, the vtk window should resize with it
flw->resizable(fl_vtk_window);
}
int main( int argc, char *argv[] )
{
// let's create the FIRST window with a Cone thingy ===========
// ============================================================
create_window_with_rwi(fl_vtk_window, main_window,
"MarchingCube");
// 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
//if I replace VolumeRendering() with MarchingCubes(), a running occurs will
occur.
// VolumeRendering();
MarchingCubes();
// 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;
}
//set the pipeline of vtk using marchingcubes algorithm
void MarchingCubes()
{
char *p="headsq/quarter";
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRenderer);
vtkRenderWindowInteractor *iren = fl_vtk_window;
iren->SetRenderWindow(renWin);
vtkVolume16Reader *p_reader = vtkVolume16Reader::New();
p_reader->SetDataDimensions (64,64);
p_reader->SetImageRange (1,93);
p_reader->SetDataByteOrderToLittleEndian();
p_reader->SetFilePrefix (p);
p_reader->SetDataSpacing (3.2, 3.2, 1.5);
// An isosurface, or contour value of 500 is known to correspond to the
// skin of the patient. Once generated, a vtkPolyDataNormals filter is
// is used to create normals for smooth surface shading during rendering.
vtkContourFilter *skinExtractor = vtkContourFilter::New();
skinExtractor->SetInput(( vtkDataSet *) p_reader->GetOutput());
skinExtractor->SetValue(0, 500);
vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
skinNormals->SetInput(skinExtractor->GetOutput());
skinNormals->SetFeatureAngle(60.0);
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
skinMapper->SetInput(skinNormals->GetOutput());
skinMapper->ScalarVisibilityOff();
vtkActor *skin = vtkActor::New();
skin->SetMapper(skinMapper);
aRenderer->AddActor(skin);
aRenderer->SetBackground(1,1,1);
iren->Initialize();
skinExtractor->Delete();
skinNormals->Delete();
skinMapper->Delete();
skin->Delete();
renWin->Delete();
aRenderer->Delete();
p_reader->Delete();
}
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
More information about the vtkusers
mailing list