[vtkusers] About drawing a cube

David Doria daviddoria at gmail.com
Wed Apr 18 10:03:08 EDT 2012


2012/4/18 Rong Xu <xurong1981 at gmail.com>

> I use the following codes.
>
> int v1,v2, v3;  //* are the vertices of the n cubes i want to draw.
> v1 = v2 = v3 = 0;
> float x[8][3] = { {v1,v2,v3},  {v1+1,v2,v3}, {v1+1,v2+1,v3},
> {v1,v2+1,v3}, {v1,v2,v3+1},  {v1+1,v2,v3+1},  {v1+1,v2+1,v3+1},
> {v1,v2+1,v3+1} };
>
> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
>
> for (int i = 0; i < pointCloud.size(); i++)
> {
>     points->InsertNextPoint(x[i]);
> }
>
> vtkSmartPointer<vtkCubeSource> cubeSource =
> vtkSmartPointer<vtkCubeSource>::New();
> cubeSource->GetOutput()->SetPoints(points);
> //cubeSource->GetOutput()->Update();
> cubeSource->Update();
>

You'll need to do something like this:

http://codepad.org/2ySABKkh

Note the use of the vtkCleanPolyDataFilter. The reason is that the
vtkCubeSource actually creates 24 points (1 for each corner of each face).
This is not what you want here (or ever really...), so the clean filter
merges these points so it has 8 points as you'd expect. Then you can get a
pointer to the points and change one of them and see the result (the demo
code I posted). Of course you can change all 8 in the same manner to get
the effect you're looking for.

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120418/8a70190f/attachment.htm>


More information about the vtkusers mailing list