[vtkusers] How to create triangle strips?
Hugo Valdebenito
hugo at maptek.cl
Thu Nov 25 13:15:01 EST 2010
David
It works now, for some rare reason wen I did try to create a test with nx=3
and ny=3, it show strange lines, I don't know why. but with a larger mesh
(1000x1000) it works fine :S.
It could be useful to include that as a example.
Thanks a lot!!!
Hugo
Untitled Document [image: Maptek] Hugo Valdebenito H.
Ingeniero de Software, Sudamérica
2 Norte 465, Viña del Mar, Chile
Tel: +56-32 2690683 (Anexo 144) | Fax: +56-32 269 06 28
hugo at maptek.cl | *Skype:* hugo.maptek | www.maptek.cl
------------------------------
Recuerda revisar los cursos que Maptek tiene
disponible<http://www.maptek.cl/products/training_sa.html>
2010/11/25 David Gobbi <david.gobbi at gmail.com>
> Hugo,
>
> I can't see anything wrong with your code, but like Jim said, I don't know
> what kind of surface you are trying to create. Just try adding this:
>
> Actor.GetProperty().SetAmbient(1.0);
>
> Depending on the lighting, sometimes surfaces can be so dark you cannot see
> them. By setting ambient lighting to 1.0, you make all surfaces appear
> bright regardless of the light position or the surface orientation.
>
> David
>
>
> On Thu, Nov 25, 2010 at 9:05 AM, Jim Peterson <jimcp at cox.net> wrote:
>
>> //set ids
>>> for (int i = 0; i < nx - 1; i++)
>>> {
>>> *cells.InsertNextCell(ny * 2);*
>>> for (int j = 0; j < ny; j++)
>>> {
>>> *cells.InsertCellPoint(i + j * nx);*
>>> *cells.InsertCellPoint(i + j * nx + 1);*
>>> }
>>> }
>>>
>> I suggest you add a comment with the expected result and comment the
>> lines, Unless I am mistaken, you are created sets of overlapping cells, at a
>> minimum, I would expect the numbering to be i*nx instead of j*nx. that would
>> result in sequential cell definitions.
>>
>> Hope that helps,
>> Jim
>>
>> Hugo,
>>
>> What kind of topology are you expecting this loop to create?
>>
>>
>> Hugo Valdebenito wrote:
>>
>>> Hi David, thanks for your useful help!
>>>
>>> I tried with you suddestion, but didn't get it work :(. please, can you
>>> check my code?
>>>
>>> public void* GenerateTest*(int nx, int ny)
>>> {
>>>
>>> vtkPoints points = vtkPoints.New();
>>> vtkCellArray cells = new vtkCellArray();
>>> //vtkTriangleStrip triangleStrip;
>>>
>>> int index = 0;
>>> double z,zmax = 50.0;
>>> points.SetNumberOfPoints(nx * ny);
>>> 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++)
>>> {
>>> *cells.InsertNextCell(ny * 2);*
>>> for (int j = 0; j < ny; j++)
>>> {
>>> *cells.InsertCellPoint(i + j * nx);*
>>> *cells.InsertCellPoint(i + j * nx + 1);*
>>> }
>>> }
>>> 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/23 David Gobbi <david.gobbi at gmail.com <mailto:
>>> david.gobbi at gmail.com>>
>>>
>>>
>>> Hi Hugo,
>>>
>>> Go with my method. Remove the vtkTriangleStrip class from your
>>> code, it isn't needed and it just makes the code less efficient
>>> (and IMHO more confusing). The vtkCellArray has many
>>> InsertNextCell methods, and the one that takes a vtkCell object is
>>> the least efficient of all of them. For you, I think the best way
>>> to add cells is this:
>>>
>>> cells.InsertNextCell(number_of_ids_in_strip)
>>> cells.InsertCellPoint(first_id_in_strip)
>>> cells.InsertCellPoint(second_id_in_srip)
>>> (repeat InsertCellPoint for all IDs)
>>>
>>> Repeat all of the above for each strip that you want to add, then
>>> call SetStrips() to add the whole cell array to the
>>> polydata. Look at the example code that I linked to in my
>>> previous email for more info.
>>>
>>> David
>>>
>>>
>>> On Tue, Nov 23, 2010 at 4:30 AM, Hugo Valdebenito <hugo at maptek.cl
>>> <mailto:hugo at maptek.cl>> wrote:
>>>
>>> Hi David.
>>>
>>> Thanks for you help, I'm trying to undestand, I have some
>>> doubts yet, Which is the difference between both methods?
>>> Wich is better?.
>>>
>>> Hugo.
>>>
>>> 2010/11/22 David Gobbi <david.gobbi at gmail.com
>>> <mailto:david.gobbi at gmail.com>>
>>>
>>>
>>> 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 <mailto: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
>>> <mailto: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 <mailto: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
>>> <mailto:daviddoria at gmail.com>>
>>>
>>> >>
>>> >> On Fri, Nov 19, 2010 at 3:22 PM, Hugo
>>> Valdebenito <hugo at maptek.cl
>>> <mailto: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
>>>
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101125/f6f4aff4/attachment.htm>
More information about the vtkusers
mailing list