[vtkusers] Qt, QVTKWidget and Polydata

mryan mattryan232 at gmail.com
Tue Jan 13 08:09:38 EST 2015


Hi zackster,

Thanks, that helped. However, if I add another set of points, such that two
cubes have adjacent faces, then I see the clipping effect again, even with
BackfaceCullingOn().

Adjacent cubes, no QVTKWidget:
http://www.lightvesselautomatic.xyz/vtk/NormalVoxels_SharedFace_NoQVTKWidget.png

Adjacent Cubes in QVTKWidget:
http://www.lightvesselautomatic.xyz/vtk/ClippedVoxels_SharedFace_QVTKWidget.png

Below the modified RenderWindowUISingleInheritance.cxx with the additional
cube. I don't see any obvious candidtaes, but are there any properties to
set that would turn off this behaviour?

Essentially what I'm trying to do is to represent data that I receive in the
form of voxel vertices and scalar data i.e. 
      x0,y0,z0,scalar_value0
      x0,y0,z1,scalar_value1 etc.
vtkPolyData seems to me to be the best representation for these,
particularly for thresholding on the scalar data and annoyingly it works
well without QVTKWidget, but I need this to be part of a wider app.

Thanks again,

Matt

////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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"
#include "vtkProperty.h"
 
// Constructor
RenderWindowUISingleInheritance::RenderWindowUISingleInheritance() 
{
  this->ui = new Ui_RenderWindowUISingleInheritance;
  this->ui->setupUi(this);
 
  int i;
  static float x[24][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},
			 {1,0,0}, {2,0,0}, {2,1,0}, {1,1,0},
			 {1,0,1}, {2,0,1}, {2,1,1}, {1,1,1}};

  static vtkIdType pts[18][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},
			       {16,17,18,19}, {20,21,22,23}, {16,17,21,20},
			       {17,18,22,21}, {18,19,23,22}, {19,16,20,23}};

  // 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<24; i++) points->InsertPoint(i,x[i]);
  for (i=0; i<18; i++) polys->InsertNextCell(4,pts[i]);
  for (i=0; i<24; i++) scalars->InsertTuple1(i,i);
    
  // 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);
  voxels_mapper->Update();

  vtkSmartPointer<vtkActor> voxels_actor = 
      vtkSmartPointer<vtkActor>::New();
  voxels_actor->SetMapper(voxels_mapper);
  voxels_actor->GetProperty()->BackfaceCullingOn();
  
  // VTK Renderer
  vtkSmartPointer<vtkRenderer> renderer = 
      vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(voxels_actor);

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

  // Set up action signals and slots
  connect(this->ui->actionExit, SIGNAL(triggered()), this,
SLOT(slotExit()));
 
}
 
void RenderWindowUISingleInheritance::slotExit() 
{
  qApp->exit();
}



--
View this message in context: http://vtk.1045678.n5.nabble.com/Qt-QVTKWidget-and-Polydata-tp5730065p5730099.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list