# [vtkusers] How to traverse lines of a polyline in reversed order?

kenichiro yoshimi rccm.kyoshimi at gmail.com
Fri Jul 20 05:01:31 EDT 2018

```Hi,

vtkReverseSense is exactly what you are searching for.

Regards
2018年7月18日(水) 18:50 normanius <juch at zhaw.ch>:
>
> Hi all How to nicely traverse the lines of a polyline in reversed order, from end to start? Is there an existing function that does this, or do I have to implement my own loop that does this? In the example below, I would like to get the line traversal AD -> DC -> CB -> BA, after initializing the cells to go from AB -> BC -> CD -> DA. Thanks!
>
>     points = vtk.vtkPoints()
>     points.InsertNextPoint([0,0,0]) # A
>     points.InsertNextPoint([1,0,0]) # B
>     points.InsertNextPoint([1,1,0]) # C
>     points.InsertNextPoint([0,1,0]) # D
>     lines = vtk.vtkCellArray()
>     for i in range(4):
>         line = vtk.vtkLine()
>         line.GetPointIds().SetId(0, i)
>         line.GetPointIds().SetId(1, (i+1)%4)
>         lines.InsertNextCell(line)
>     poly = vtk.vtkPolyData()
>     poly.SetPoints(points)
>     poly.SetLines(lines)
>
>     reversed = reverseLines(poly)
>
>     lines = reversed.GetLines()
>     points = reversed.GetPoints()
>     lines.InitTraversal()
>     idList = vtk.vtkIdList()
>     while lines.GetNextCell(idList):
>         p = []
>         for i in range(0, idList.GetNumberOfIds()):
>             p.append(points.GetPoint(idList.GetId(i)))
>         print(p)
>
>
> ________________________________
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________