[vtkusers] Qt, QVTKWidget gridActor always in front
zackster
zafer.leylek at gmail.com
Sun Jan 11 19:08:21 EST 2015
Hi,
Below is a modified version of the SidebySideRenderWindowsQT example. I have
added a structured/image actor to the renderwindow that contains the sphere.
My problem is that the structured grid is always in front of the sphere.
This is not the case when not using QVTKWidget. Any ideas??
#include "SideBySideRenderWindowsQt.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 <vtkSmartPointer.h>
#include <vtkProperty.h>
#include <vtkDataSetMapper.h>
#include <vtkVersion.h>
#include <vtkImageData.h>
#include <vtkPoints.h>
#include <vtkImageDataToPointSet.h>
#include <vtkStructuredGrid.h>
// Constructor
SideBySideRenderWindowsQt::SideBySideRenderWindowsQt()
{
this->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);
/*
* Modification 1
*/
sphereActor->GetProperty()->BackfaceCullingOn();
sphereActor->GetProperty()->SetColor(1,0,1);
/*
* Modification 2
*/
vtkSmartPointer<vtkImageData> image =vtkSmartPointer<vtkImageData>::New();
image->SetDimensions(3,3,1);
image->SetSpacing(1.0, 1.0, 0.0);
image->SetOrigin(-1.5, -1.5, -2);
vtkSmartPointer<vtkImageDataToPointSet> imageDataToPointSet
=vtkSmartPointer<vtkImageDataToPointSet>::New();
#if VTK_MAJOR_VERSION <= 5
imageDataToPointSet->SetInputConnection(image->GetProducerPort());
#else
imageDataToPointSet->SetInputData(image);
#endif
imageDataToPointSet->Update();
vtkSmartPointer<vtkDataSetMapper> imageGridMapper =
vtkSmartPointer<vtkDataSetMapper>::New();
vtkSmartPointer<vtkActor> imageGridActor =
vtkSmartPointer<vtkActor>::New();
imageGridMapper->SetInputConnection(imageDataToPointSet->GetOutputPort());
imageGridActor->SetMapper(imageGridMapper);
imageGridActor->GetProperty()->SetColor(0,0,1);
leftRenderer->AddActor(imageGridActor);
// VTK/Qt wedded
this->qvtkWidgetLeft->GetRenderWindow()->AddRenderer(leftRenderer);
this->qvtkWidgetRight->GetRenderWindow()->AddRenderer(rightRenderer);
// Set up action signals and slots
connect(this->actionExit, SIGNAL(triggered()), this, SLOT(slotExit()));
}
void SideBySideRenderWindowsQt::slotExit()
{
qApp->exit();
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/Qt-QVTKWidget-gridActor-always-in-front-tp5730071.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list