[vtkusers] Re: newbie question : vtkPlanes to represent a cube

Goodwin Lawlor goodwin.lawlor at ucd.ie
Fri Oct 8 09:08:08 EDT 2004


Hi Jim,

Have you had a look at vtkCubeSource to create your cube for you? If you
want to do some boolean operations then implicit functions are best.
Unfortunately, there's no implicit fuction for a cube but you could try to
use vtkCubeSource with vtkImplicitDataSet.

hth

Goodwin

"Jean-Marie Normand" <normand at lina.univ-nantes.fr> wrote in message
news:1097239132.11002.36.camel at pago.irin.sciences.univ-nantes.prive...
> 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
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>






More information about the vtkusers mailing list