[vtkusers] newbie question : vtkPlanes to represent a cube

Jean-Marie Normand normand at lina.univ-nantes.fr
Fri Oct 8 08:38:52 EDT 2004


Hi, I'm new to VTK and I try to represent a cube with vtkPlanes (because
I want to perform Bollean operation on this cube afterwards) and I can't
manage to have this working.

Here is the code I use, after these declarations, I create a sample
function, a contourfilter, a polydatamapper and an actor in order to
render the cube, but the window is always empty.

I wonder if there is a problem with the normals of my cube, which should
be centered in (0,0,0) in 3D, I'm also wondering if I use the right
coordinates system (I thought that X would be oriented on the right of
the screen, Y upwards and Z toward the user). I may be wrong on this
point but I haven't been able to find what the orientation of the axes
look like.

// Creating a cube by using vtkPlanes
vtkFloatArray *pcoords = vtkFloatArray::New();
pcoords->SetNumberOfComponents(3);
pcoords->SetNumberOfTuples(6);
  
// the array of normals
vtkFloatArray *pnormals = vtkFloatArray::New();
pnormals->SetNumberOfComponents(3);
pnormals->SetNumberOfTuples(6);
  
float size = 2.;
float half_size = size / 2.;
float pts[6][3] = { {0.0, 0.0, 0.}, {0., half_size, 0.0}, 
  		    {half_size, half_size, 0.0}, {-half_size, half_size,0.0}, 
		    {0.0, half_size, half_size}, {0.0, half_size, -half_size} };
 
  float nrmls[6][3] = { {0., 1., 0.},  {0., -1., 0.},
  			{1., 0., 0.},  {-1., 0., 0.},
			{0., 0., 1.},  {0., 0., -1.}  }; 
 
  for (int i=0; i<6; i++)
  {
    pcoords->SetTuple(i, pts[i]);
    pnormals->InsertTuple(i, nrmls[i]);
  }

  // Create vtkPoints and assign pcoords as the internal data array.
  vtkPoints* points = vtkPoints::New();
  points->SetData(pcoords);
  
  vtkPlanes *cube = vtkPlanes::New();
  cube->SetPoints( points );
  cube->SetNormals( pnormals );


Any help would be appreciated
Thanks 

Jim





More information about the vtkusers mailing list