[vtk-developers] vtkImplicitPlaneWidget2 and Qt
Henrici
mark.horn at ierustech.com
Mon Jan 23 15:17:48 EST 2012
Hello,
I have downloaded /compiled / run the example for vtkImplicitPlaneWidget2.
It works as advertised.
I have a VTK application that is built with Qt in which I am hosting the
QVTKWidget in a Qt Form, and I am having problems incorporating the
vtkImplicitPlaneWidget2. Essentially, the code as given by
vtkImplicitPlaneWidget2 will cause a secondary window to appear in which the
implicit plane graphics are shown, and I am able to interact with that
window. However, I want the implicit plane graphics to be within my
QVTKWidget viewing area on my main Qt form.
After looking around a bit, I think the main difference here is I should use
the prior established RenderWindow (and Renderer), and the interactor on my
QVTKWidget rather than creating a new interactor. When I do that, all I get
is the sphere in my QVTKWidget with no implicit plane interaction shown. I
have given a snippet of code below in which I change the baseline
vtkImplicitPlaneWidget2 example to use the QVTKWidget interactor and
pre-established render window instead. I specified my development platform
as well.
Can someone suggest modifications to the baseline vtkImplicitPlaneWidget2
example that would work when hosted in a standard Qt Form using the
QVTKWidget?
Thanks in advance!
PLATFORM:
Qt4
VTK 5.6.1
Ubuntu 11.04
SNIPPET :
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetRadius(10.0);
//vtkSmartPointer<vtkXMLPolyDataReader> reader =
// vtkSmartPointer<vtkXMLPolyDataReader>::New();
// Setup a visualization pipeline
vtkSmartPointer<vtkPlane> plane =
vtkSmartPointer<vtkPlane>::New();
vtkSmartPointer<vtkClipPolyData> clipper =
vtkSmartPointer<vtkClipPolyData>::New();
clipper->SetClipFunction(plane);
clipper->InsideOutOn();
clipper->SetInputConnection(sphereSource->GetOutputPort());
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(clipper->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkProperty> backFaces =
vtkSmartPointer<vtkProperty>::New();
backFaces->SetDiffuseColor(.8, .8, .4);
actor->SetBackfaceProperty(backFaces);
// A renderer and render window
//vtkSmartPointer<vtkRenderer> renderer =
// vtkSmartPointer<vtkRenderer>::New();
//vtkSmartPointer<vtkRenderWindow> renderWindow =
// vtkSmartPointer<vtkRenderWindow>::New();
//renderWindow->AddRenderer(renderer);
//renderer->AddActor(actor);
m_pRenderer->AddActor(actor);
// An interactor
//vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
// vtkSmartPointer<vtkRenderWindowInteractor>::New();
//renderWindowInteractor->SetRenderWindow(renderWindow);
//renderWindow->Render();
m_pQVTKWidget->GetRenderWindow()->Render();
// The callback will do the work
vtkSmartPointer<vtkIPWCallback> myCallback =
vtkSmartPointer<vtkIPWCallback>::New();
myCallback->Plane = plane;
myCallback->Actor = actor;
vtkSmartPointer<vtkImplicitPlaneRepresentation> rep =
vtkSmartPointer<vtkImplicitPlaneRepresentation>::New();
rep->SetPlaceFactor(1.25); // This must be set prior to placing the
widget
rep->PlaceWidget(actor->GetBounds());
rep->VisibilityOn();
rep->SetNormal(plane->GetNormal());
//rep->SetOrigin(0,0,50); //this doesn't seem to work?
vtkSmartPointer<vtkImplicitPlaneWidget2> planeWidget =
vtkSmartPointer<vtkImplicitPlaneWidget2>::New();
//planeWidget->SetInteractor(renderWindowInteractor);
//planeWidget->SetInteractor(m_pQVTKWidget->GetInteractor());
planeWidget->SetRepresentation(rep);
planeWidget->AddObserver(vtkCommand::InteractionEvent, myCallback);
// Render
//renderWindowInteractor->Initialize();
//renderWindow->Render();
//m_pQVTKWidget->GetInteractor()->Initialize();
m_pQVTKWidget->GetRendowWindow()->Render();
planeWidget->On();
// Begin mouse interaction
//renderWindowInteractor->Start();
m_pQVTKWidget->GetInteractor()->Start();
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkImplicitPlaneWidget2-and-Qt-tp5169621p5169621.html
Sent from the VTK - Dev mailing list archive at Nabble.com.
More information about the vtk-developers
mailing list