[vtkusers] Qt, QVTKWidget and Polydata

Matt Ryan mattryan232 at gmail.com
Sun Jan 11 07:02:21 EST 2015


Hi All,

I'm getting some odd behaviour when trying to render voxels from a polydata object in a QVTKWidget render window, specifically that each voxel appears to not have its full complement of polygon faces i.e. they appear clipped. To illustrate the problem I modified the RenderWindowUISingleInheritance.cxx example with the Cube.cxx DataManipulation (reproduced below).

This is the output from the Cube.cxx example - the cubes have all their faces using the original Cube.cxx example:

http://www.lightvesselautomatic.xyz/vtk/NormalVoxels_NoQVTKWidget.png

This is the output from the RenderWindowUISingleInheritance.cxx - when exactly the same code is used with QVTKWidget, they appear clipped:

http://www.lightvesselautomatic.xyz/vtk/ClippedVoxels_QVTKWidget.png

I’m running VTK 6.0.1 and Qt 5.3.2. I’ve checked the contents of the point arrays and cell arrays defining the polydata object and they seem fine. If anyone has any insights as to why this clipping effect happens and how to overcome it, I'd be very grateful.

Thanks very much for your time and help,

Matt





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Modified RenderWindowUISingleInheritance.cxx

#include "RenderWindowUISingleInheritance.h"

// This is included here because it is forward declared in
// RenderWindowUISingleInheritance.h
#include "ui_RenderWindowUISingleInheritance.h"

#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSphereSource.h>
#include <vtkSmartPointer.h>

//
#include <vtkPolyDataMapper.h>
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"

// Constructor
RenderWindowUISingleInheritance::RenderWindowUISingleInheritance()
{
 this->ui = new Ui_RenderWindowUISingleInheritance;
 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);

// Use Cube.cxx method
int i;
 static float x[16][3]={{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0},
            {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1},
            {1,1,1}, {2,1,1}, {2,2,1}, {1,2,1},
            {1,1,2}, {2,1,2}, {2,2,2}, {1,2,2}};
 static vtkIdType pts[12][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4},
                  {1,2,6,5}, {2,3,7,6}, {3,0,4,7},
                  {8,9,10,11}, {12,13,14,15}, {8,9,13,12},
                  {9,10,14,13}, {10,11,15,14}, {11,8,12,15}};

 // We'll create the building blocks of polydata including data attributes.
 vtkPolyData *cube = vtkPolyData::New();
 vtkPoints *points = vtkPoints::New();
 vtkCellArray *polys = vtkCellArray::New();
 vtkFloatArray *scalars = vtkFloatArray::New();

 // Load the point, cell, and data attributes.
 for (i=0; i<16; i++) points->InsertPoint(i,x[i]);
 for (i=0; i<12; i++) polys->InsertNextCell(4,pts[i]);
 for (i=0; i<16; i++) scalars->InsertTuple1(i,i);

 std::cout<<"NCells = " << polys->GetNumberOfCells() << "\n";

 // We now assign the pieces to the vtkPolyData.
 cube->SetPoints(points);
 points->Delete();
 cube->SetPolys(polys);
 polys->Delete();

 vtkSmartPointer<vtkPolyDataMapper> voxels_mapper =
     vtkSmartPointer<vtkPolyDataMapper>::New();
 voxels_mapper->SetInputData(cube);


 vtkSmartPointer<vtkActor> voxels_actor =
     vtkSmartPointer<vtkActor>::New();
 voxels_actor->SetMapper(voxels_mapper);

 // VTK Renderer
 vtkSmartPointer<vtkRenderer> renderer =
     vtkSmartPointer<vtkRenderer>::New();
 renderer->AddActor(voxels_actor);

 // VTK/Qt wedded
this->ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);

 // Set up action signals and slots
 connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(slotExit()));

}

void RenderWindowUISingleInheritance::slotExit()
{
 qApp->exit();
}


More information about the vtkusers mailing list