[vtkusers] wxwindows-VTK in C++
Alberto Bert
abert at mauriziano.it
Wed Dec 4 04:46:24 EST 2002
Hi,
I'm trying to use VTK in wxWindows in order to build a cross-plattform
program, but I have some problems (I'm working in C++, no wxpython).
My first testing program was bilt in win-XP (VC++) and everything seems to work
fine, but when I've ran it on linux (debian woody, g++-2.95) something
strange happended. Together with the wxWindows' window, pop up a second
window, the VTK one. In XP, instead, VTK sends correctly its rendering
to the wxWindows' window. Furthermore, on linux thw VTK window has the
right size (also after resizing) but the interactor doesn't work.
Any one can help me? I append the interesting part of the code.
Nota:
wxWindows and VTK independent programs work in both systems on which I'm tryng to
work (linux debian woody and win-XP)
Thanks,
Alberto
bool myApp::OnInit()
{
// Create the main application window
mainFrame *frame = new mainFrame ("Hawk",wxPoint(50, 50), wxSize(800, 500));
// Show it and tell the application that it's our main window
frame->Show(TRUE);
frame->SetIcon(wxIcon("main"));
SetTopWindow(frame);
return TRUE;
}
mainFrame::mainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append(FILE_OPEN, "...");
// ...
wxMenu *menuView = new wxMenu;
menuViewView->Append(VIEW_VIEW_1x1,"1 Slice\tCtrl-1","Show only one slice");
// ...
menuView->Append(VIEW_VIEW,"View...",menuViewView,"Choose number of slices for showing");
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
menuBar->Append(menuView, "&View");
SetMenuBar(menuBar);
CreateStatusBar();
Init();
// for debug
SetRenderer();
}
// initialize all objects...
void mainFrame::Init()
{
int i;
for(i=0;i<maxViews;i++)
{
mapper[i] = vtkMapper2D::New();
actor[i] = vtkActor2D::New();
ren[i]= vtkRenderer::New();
}
renWin = vtkRenderWindow::New();
inter = vtkRenderWindowInteractor::New();
outPut = new wxPanel(this,PANEL);
renWin->SetParentId((void *)outPut->GetHandle());
}
//--------------------------------------------------------------------------------------
// M E N U V I E W
//--------------------------------------------------------------------------------------
void mainFrame::OnView_1x1(wxCommandEvent& WXUNUSED(event))
{
ren[0]->SetViewport(0,0,1,1);
for (int i=1;i<4;i++)
ren[i]->SetViewport(0,0,0,0);
numberOfViews = 1;
renWin->Render();
}
//--------------------------------------------------------------------------------------
void mainFrame::OnSize(wxSizeEvent& event)
{
if (outPut)
{
outPut->Move(100,0);
outPut->SetSize(GetClientSize().GetWidth()-100,GetClientSize().GetHeight());
renWin->SetSize(outPut->GetClientSize().GetWidth(),outPut->GetClientSize().GetHeight());
}
}
void mainFrame::SetRenderer()
{
cone = vtkConeSource::New();
cone->SetHeight( 3.0 );
cone->SetRadius( 1.0 );
cone->SetResolution( 10 );
coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInput( cone->GetOutput() );
coneActor = vtkActor::New();
coneActor->SetMapper( coneMapper );
for (int i=0;i<4;i++)
{
ren[i]->AddActor( coneActor );
ren[i]->SetBackground(i*0.1,i*0.2,i*0.4);
renWin->AddRenderer( ren[i]);
}
ren[0]->SetViewport(0,0,0.5,0.5);
ren[1]->SetViewport(0.5,0,1,0.5);
ren[2]->SetViewport(0,0.5,0.5,1);
ren[3]->SetViewport(0.5,0.5,1,1);
renWin->SetSize(300,300);
inter->SetRenderWindow(renWin);
renWin->Render();
}
BEGIN_EVENT_TABLE(mainFrame, wxFrame)
// menu FILE
EVT_MENU(FILE_OPEN, mainFrame::OnOpen)
EVT_MENU(FILE_EXIT, mainFrame::OnQuit)
//menu VIEW
EVT_MENU(VIEW_VIEW_1x1,mainFrame::OnView_1x1)
EVT_MENU(VIEW_VIEW_2x2,mainFrame::OnView_2x2)
// other
EVT_SIZE(mainFrame::OnSize)
END_EVENT_TABLE()
More information about the vtkusers
mailing list