[vtkusers] How to create triangle strips?
David Gobbi
david.gobbi at gmail.com
Mon Nov 22 13:31:07 EST 2010
Hi Hugo,
Your code is a mix of the method that I suggested and the method that David
Doria suggested. The SetStrips() method is a low-level method for building
a vtkPolyData (as per my suggestion). The InsertNextCell() method is a
high-level method for building a vtkDataSet (as per David Doria's
suggestion). You have to use one method or the other, not both. I
apologize for the confusion.
David
On Mon, Nov 22, 2010 at 11:10 AM, Hugo Valdebenito <hugo at maptek.cl> wrote:
> Hi David.
>
> It works with one strip, but that doesn't work with 2 o more strips. that
> is my implementation (sorry, is C#, I translated the c++ example)
>
> public void GenerateSurface(int nx, int ny)
> {
>
> vtkPoints points = vtkPoints.New();
> vtkCellArray cells = new vtkCellArray();
> vtkTriangleStrip triangleStrip;
>
>
> double z,zmax = 50.0;
> points.SetNumberOfPoints(nx * ny);
> //se points
> int index = 0;
> for (int j = 0; j < ny; j++)
> {
> for (int i = 0; i < nx; i++)
> {
> z = zmax * Math.Sin(4 * 3.1 * i / (float)nx) + 4 * j /
> (float)(ny);
> //insert point and increment index
> *points.SetPoint(index++,(double)i, (double)j, (double)z);
> *
>
>
> }
> }
> //set ids
> for (int i = 0; i < nx - 1; i++)
> {
> index = 0;
> triangleStrip = new vtkTriangleStrip();
> triangleStrip.GetPointIds().SetNumberOfIds(ny*2);
>
> for (int j = 0; j < ny; j++)
> {
> triangleStrip.GetPointIds().SetId(index++, i + j * nx);
> triangleStrip.GetPointIds().SetId(index++, i + j * nx + 1);
> }
> *cells.InsertNextCell(triangleStrip);*
> }
> vtkPolyData polydata = new vtkPolyData();
> polydata.SetPoints(points);
> *polydata.SetStrips(cells);*
>
> // Create an actor and mapper
> vtkDataSetMapper mapper = new vtkDataSetMapper();
> mapper.SetInput(polydata);
> vtkActor Actor = new vtkActor();
>
> Actor.SetMapper(mapper);
> Actor.GetProperty().SetRepresentationToWireframe();
> //Add the actors to the scene
> _renderer.AddActor(Actor);
> }
>
>
> Hugo
>
>
>
> 2010/11/22 David Gobbi <david.gobbi at gmail.com>
>
> Hi Hugo,
>>
>> The vtkPolyData stores the strips in an array called "Strips", that is
>> how it knows what cells are strips. And all vtkDataSet objects have a
>> GetCellType(i) method that VTK can use to check the type of cell "i".
>> I have some code here that generates several shapes with triangle
>> strips:
>>
>> https://github.com/dgobbi/ToolCursor/blob/master/vtkGeometricCursorShapes.cxx
>>
>> David
>>
>>
>> On Mon, Nov 22, 2010 at 5:55 AM, Hugo Valdebenito <hugo at maptek.cl> wrote:
>> >
>> > You should to see the triangles, maybe it's wrong. with 4 ids you define
>> 2
>> > triagles, with 5 --> 3 and so on (that structure saves memory). How does
>> you
>> > said to vtk that you are using Strips? I don't know how to define that
>> on
>> > VTK.
>> >
>> >
>> > Thanks!
>> >
>> >
>> >
>> > 2010/11/19 David Doria <daviddoria at gmail.com>
>> >>
>> >> On Fri, Nov 19, 2010 at 3:22 PM, Hugo Valdebenito <hugo at maptek.cl>
>> wrote:
>> >> > Thanks david!!
>> >> >
>> >> > vtkCellArray object is defined, but never used....
>> >> >
>> >> > Anyone can suggest a fix?, I'm beginner on VTK
>> >> > Hugo
>> >>
>> >> Try it now. It doesn't show the line through the middle of the square
>> >> (the center edge of the triangles), but maybe that is expected with a
>> >> triangle strip?
>> >>
>> >>
>> >>
>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Broken/GeometricObjects/TriangleStrip
>> >>
>> >> David
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101122/d434ba4f/attachment.htm>
More information about the vtkusers
mailing list