[vtkusers] Trouble with QVTK
Joshua Pedrick
jpedrick at gmail.com
Mon May 11 11:37:45 EDT 2009
Hi, I'm attempting to embed a VTK render window into my At app, I'm
using the code below to display a cone in the window, but all I get is
the background. I included the popup from the QVTK events example and
I'm trying to display a cone. All I get is the background, the popup
menu works, but no cone. Any clues regarding what I am doing wrong? I
tried this same example without QVTK and it worked perfectly. I am using the
CVS version of VTK and qt-sdk-2009.02.
Regards,
-Joshua
void MainWindow::SetupScene()
{
QVTKWidget* qvtkwidget = ui.qvtkWidget;
{
vtkRenderWindow* renWin = vtkRenderWindow::New();
//renWin->StereoCapableWindowOn();
qvtkwidget->SetRenderWindow(renWin);
renWin->Delete();
}
//add a popup menu for the window and connect it to our slot
QMenu* popup1 = new QMenu(qvtkwidget);
popup1->addAction("Background White");
popup1->addAction("Background Black");
//popup1->addAction("Stereo Rendering");
connect(popup1, SIGNAL(triggered(QAction*)), this,
SLOT(color(QAction*)));
vtkEventQtSlotConnect* Connections = vtkEventQtSlotConnect::New();
Connections->Connect(qvtkwidget->GetRenderWindow()->GetInteractor(),
vtkCommand::RightButtonPressEvent,
this,
SLOT(popup( vtkObject*, unsigned long, void*,
void*, vtkCommand*)),
popup1, 1.0);
//Put cone in window
{
vtkConeSource *cone = vtkConeSource::New();
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
// 3
coneMapper->SetInputConnection(cone->GetOutputPort());
vtkActor *coneActor = vtkActor::New();
coneActor->SetMapper(coneMapper);
coneMapper->Delete();
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(coneActor);
coneActor->Delete();
ren->SetBackground(0.3, 0.3, 0.4);
ren->SetBackground2(0.9, 0.9, 1);
ren->AutomaticLightCreationOn();
ren->GradientBackgroundOn();
//ren->WorldToDisplay();
qvtkwidget->GetRenderWindow()->AddRenderer(ren);
qvtkwidget->GetRenderWindow()->BordersOn();
ren->Delete();
}
}
void MainWindow::popup(vtkObject * obj, unsigned long, void * client_data,
void *, vtkCommand * command)
{
// A note about context menus in Qt and the QVTKWidget
// You may find it easy to just do context menus on right button up,
// due to the event proxy mechanism in place.
// That usually works, except in some cases.
// One case is where you capture context menu events that
// child windows don't process. You could end up with a second
// context menu after the first one.
// See QVTKWidget::ContextMenuEvent enum which was added after the
// writing of this example.
// get interactor
vtkRenderWindowInteractor* iren =
vtkRenderWindowInteractor::SafeDownCast(
obj);
// consume event so the interactor style doesn't get it
command->AbortFlagOn();
// get popup menu
QMenu* popupMenu = static_cast<QMenu*> (client_data);
// get event location
int* sz = iren->GetSize();
int* position = iren->GetEventPosition();
// remember to flip y
QPoint pt = QPoint(position[0], sz[1] - position[1]);
// map to global
QPoint global_pt = popupMenu->parentWidget()->mapToGlobal(pt);
// show popup menu at global point
popupMenu->popup(global_pt);
}
void MainWindow::color(QAction* color)
{
QVTKWidget* qvtkwidget = ui.qvtkWidget;
vtkRenderer* ren =
qvtkwidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
if (color->text() == "Background White")
ren->SetBackground(1, 1, 1);
else if (color->text() == "Background Black")
ren->SetBackground(0, 0, 0);
else if (color->text() == "Stereo Rendering")
{
ren->GetRenderWindow()->SetStereoRender(
!ren->GetRenderWindow()->GetStereoRender());
}
qvtkwidget->update();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090511/edf265a4/attachment.htm>
More information about the vtkusers
mailing list