[vtkusers] QVTKWidget and Axis Display (using vtkOrientationMarkerWidget)
Hamid G
listboss at gmail.com
Mon Nov 28 00:55:01 EST 2011
Hi
I am trying to add a simple axis display to the Qt/VTK example from the wiki:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/SideBySideRenderWindows
Following the sample from http://goo.gl/sRnv5 which uses
vtkOrientationMarkerWidget to display
axes, I only modified the code in SimpleView.cxx by creating a vtkAxesActor and
vtkOrientationMarkerWidget objects (see below)
The program crashes and I am suspecting that I am not setting
vtkOrientationMarkerWidget's interactor
properly. How do I get/set proper vtkRenderWindowInteractor for QVTKWidget?
==========
Modified SimpleView.cxx
==========
#include "ui_SimpleView.h"
#include "SimpleView.h"
#include <vtkDataObjectToTable.h>
#include <vtkElevationFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkQtTableView.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSphereSource.h>
#include <vtkCubeSource.h>
#include "vtkAxesActor.h"
#include "vtkOrientationMarkerWidget.h"
#include <vtkPropAssembly.h>
#include "vtkSmartPointer.h"
// Constructor
SimpleView::SimpleView()
{
this->ui = new Ui_SimpleView;
this->ui->setupUi(this);
// sphere
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->Update();
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor =
vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
// cube
vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
cubeSource->Update();
vtkSmartPointer<vtkPolyDataMapper> cubeMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cubeMapper->SetInputConnection(cubeSource->GetOutputPort());
vtkSmartPointer<vtkActor> cubeActor =
vtkSmartPointer<vtkActor>::New();
cubeActor->SetMapper(cubeMapper);
// VTK Renderer
vtkSmartPointer<vtkRenderer> leftRenderer =
vtkSmartPointer<vtkRenderer>::New();
leftRenderer->AddActor(sphereActor);
vtkSmartPointer<vtkRenderer> rightRenderer =
vtkSmartPointer<vtkRenderer>::New();
// Add Actor to renderer
rightRenderer->AddActor(cubeActor);
// VTK/Qt wedded
this->ui->qvtkWidgetLeft->GetRenderWindow()->AddRenderer(leftRenderer);
this->ui->qvtkWidgetRight->GetRenderWindow()->AddRenderer(rightRenderer);
// Modification starts -->
vtkRenderWindowInteractor *iren =
ui->qvtkWidgetLeft->GetRenderWindow()->GetInteractor();
vtkSmartPointer<vtkAxesActor> axes =
vtkSmartPointer<vtkAxesActor>::New();
vtkSmartPointer<vtkOrientationMarkerWidget> widget =
vtkSmartPointer<vtkOrientationMarkerWidget>::New();
widget->SetOutlineColor( 0.9300, 0.5700, 0.1300 );
widget->SetOrientationMarker( axes );
widget->SetInteractor( iren );
widget->SetViewport( 0.0, 0.0, 0.4, 0.4 );
widget->SetEnabled( 1 );
widget->InteractiveOn();
leftRenderer->ResetCamera();
rightRenderer->ResetCamera();
// Modification ends <--
// Set up action signals and slots
connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(slotExit()));
}
void SimpleView::slotExit()
{
qApp->exit();
}
==========
Crash report (Max OSX 10.6.8, vtk 5.9)
==========
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x000000004d5555c8
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libvtkRendering.5.9.dylib 0x0000000100e75e23
vtkRenderer::GetActiveCamera() + 19
1 libvtkWidgets.5.9.dylib 0x00000001003b60e0
vtkOrientationMarkerWidget::ExecuteCameraUpdateEvent(vtkObject*,
unsigned long, void*) + 32
2 libvtkCommon.5.9.dylib 0x00000001025f4067
vtkSubjectHelper::InvokeEvent(unsigned long, void*, vtkObject*) + 1303
3 libvtkRendering.5.9.dylib 0x0000000100e76f00 vtkRenderer::Render() + 96
4 libvtkRendering.5.9.dylib 0x0000000100e73551
vtkRendererCollection::Render() + 129
5 libvtkRendering.5.9.dylib 0x0000000100e7da35
vtkRenderWindow::DoStereoRender() + 181
6 libvtkRendering.5.9.dylib 0x0000000100e7d821
vtkRenderWindow::DoFDRender() + 881
7 libvtkRendering.5.9.dylib 0x0000000100e7dfa2
vtkRenderWindow::DoAARender() + 1186
8 libvtkRendering.5.9.dylib 0x0000000100e7b99b
vtkRenderWindow::Render() + 267
9 libvtkRendering.5.9.dylib 0x0000000100e7fef9
vtkRenderWindowInteractor::Render() + 89
10 libQVTK.5.9.dylib 0x000000010002812d
QVTKWidget::paintEvent(QPaintEvent*) + 141
11 QtGui 0x0000000103092ae6
QWidget::event(QEvent*) + 2294
12 libQVTK.5.9.dylib 0x00000001000285e9
QVTKWidget::event(QEvent*) + 89
13 QtGui 0x0000000103038d9d
QApplicationPrivate::notify_helper(QObject*, QEvent*) + 189
14 QtGui 0x000000010303ebfd
QApplication::notify(QObject*, QEvent*) + 349
15 QtCore 0x0000000103e645fc
QCoreApplication::notifyInternal(QObject*, QEvent*) + 124
16 QtGui 0x0000000103038f5c
qt_sendSpontaneousEvent(QObject*, QEvent*) + 44
17 QtGui 0x0000000102fe218d -[QCocoaView
drawRect:] + 1213
18 com.apple.AppKit 0x00007fff82629cc5 -[NSView
_drawRect:clip:] + 3390
Any input/hint is appreciated.
thanks in advance,
Hamid G
More information about the vtkusers
mailing list