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

Jean-Marie Normand normand at lina.univ-nantes.fr
Mon Oct 11 09:23:21 EDT 2004


Hi Goodwin 
thanks for your answer.
I succeed in creating a cube as a collection of VtkPlanes, but I failed
to associate a vtkImplicitDataSet to a cube generated by a
vtkCubeSource.
This is the source code I've written but seems to be wrong :

// Creation of a Cube
vtkCubeSource *cube = vtkCubeSource::New();
cube->SetCenter(0.,0.,0.);
cube->SetXLength(5.);
cube->SetYLength(5.);
cube->SetZLength(5.);
  
vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
cubeMapper->SetInput( cube->GetOutput() );
 
vtkActor *cubeActor = vtkActor::New();
cubeActor->SetMapper( cubeMapper );

// Declaration of an ImplicitDataSet
vtkImplicitDataSet *theCubeImplicit = vtkImplicitDataSet::New();
theCubeImplicit->SetDataSet((vtkDataSet*)cube->GetOutput());

Then I declare another cube created in the same way, and when I want to
perform a boolean op on them, I got the following error :

ERROR: In /home/jim/VTK/VTK/Filtering/vtkImplicitDataSet.cxx, line 78
vtkImplicitDataSet (0x829ae88): Can't evaluate dataset!


This is how I use the ImplicitBoolean function and which may be wrong:

vtkImplicitBoolean *theCutCube = vtkImplicitBoolean::New();
theCutCube->SetOperationTypeToIntersection();
theCutCube->AddFunction(theCubeImplicit);
theCutCube->AddFunction(theCubeImplicit2);

Afterwards, I declare a vtkSampleFunction, a vtkContourFilter, a
vtkPolyDataMapper and finally a vtkActor to display the result, but then
I get the error given above. But if I don't try to display the actor, I
don't get any error (which may be normal since I don't yet fully
understand how VTK works).

I'm sorry if my questions may seem dumb ones but I'm a total newbie with
VTK, thanks for the help.

Jim

Le ven 08/10/2004 à 15:08, Goodwin Lawlor a écrit :
> 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
> >
> 
> 
> 
> _______________________________________________
> 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