[vtkusers] About drawing a cube

Rong Xu xurong1981 at gmail.com
Wed Apr 18 11:04:27 EDT 2012


Dear David Doria:

2012/4/18 David Doria <daviddoria at gmail.com>

> 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.
>

Thank you very much for your codes !

I have successfully realize to set the parameters of vtkCubeSource by 8
vertices based on your codes. But I encounter another problem, it seems the
order of 8 vertices should be arranged correctly, otherwise, the visualized
cube is not correct. About the order of vertices, do you have an easy idea
to set ? Otherwise, I need to check the coordinates of 8 vertices every
time and re-order them.

Greatly appreciate your help!


>
> David
>



-- 

---------------------
Best Regards!

===============================================
Rong Xu,  Ph.D Student
Ohya Lab
Graduate School of Global Information and Telecommunication
Studies (GITS), Waseda University
1-6-1 Nishi Waseda, Shinjuku-ku, Tokyo, Japan (¨“169-8050)

Tel:          +81-80-4208-1207
E-mail:     xurong1981 at gmail.com
               xurong at fuji.waseda.jp
===============================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120419/660a0b1f/attachment.htm>


More information about the vtkusers mailing list