# GetPolys() vertex indices weird order

**URL:** https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662
**Category:** Support
**Created:** [June 28, 2020, 6:51pm UTC](https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662 "2020-06-28T18:51:58Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![panicbuttonvfx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/panicbuttonvfx/32/1838_2.png) [@panicbuttonvfx](https://discourse.vtk.org/u/panicbuttonvfx)
#### Post date: [June 28, 2020, 6:51pm UTC](https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662/1 "2020-06-28T18:51:59Z")

</div>

Hi,

When I retrieve the polygon data from a mesh (the cube below as an example), I get something like this:

```
>>> vtk_to_numpy(mesh.GetPolys().GetData())
>>> [4 0 1 3 2 4 4 6 7 5 4 8 10 11 9 4 12 13 15 14 4 16 18 19 17 4 20 21 23 22]

```

The way I’m interpreting it is, each triangle is defined by its vertices indices, and looking at the output data and the cube, it looks like the first 3 values, `4 0 1`, make sense as in that they define a triangle, but the next 3 values, `3 2 4`, it appears to define a triangle that goes across the middle of the cube, which doesn’t seem right. Am I interpreting the data correctly of is there something else going on?

 ![Screen Shot 2020-06-28 at 11.45.32 AM](https://discourse.vtk.org/uploads/default/original/2X/2/2cac37bcc8d2666900f737c86873fd3092705c1c.png)

Thanks!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [June 28, 2020, 7:40pm UTC](https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662/2 "2020-06-28T19:40:28Z")

</div>

The first “4” is the number of points in the polygon, and “0 1 3 2” are the points. The next “4” is for the next polygon, with points “4 6 7 5”.

---

<div class="post-metadata">

### Author: ![panicbuttonvfx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/panicbuttonvfx/32/1838_2.png) [@panicbuttonvfx](https://discourse.vtk.org/u/panicbuttonvfx)
#### Post date: [June 28, 2020, 7:48pm UTC](https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662/3 "2020-06-28T19:48:07Z")

</div>

I see the light now, thanks!

---

<div class="post-metadata">

### Author: ![panicbuttonvfx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/panicbuttonvfx/32/1838_2.png) [@panicbuttonvfx](https://discourse.vtk.org/u/panicbuttonvfx)
#### Post date: [June 28, 2020, 10:13pm UTC](https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662/4 "2020-06-28T22:13:28Z")

</div>

Not directly a VTK question, but if for any of you guys a solution to this can come easier than it is for me at the moment, I would appreciate it.  
I’m having troubles to split that array. In this example, all polygons have 4 vertices so it’s easier if that assumption is made, but I’d like to handle situations where different polygons might have different number of vertices.  
So I’d like to split this (numpy) array:

`[4 0 1 3 2 4 4 6 7 5 4 8 10 11 9 4 12 13 15 14 4 16 18 19 17 4 20 21 23 22]`

into something like this:

`[[0 1 3 2] [4 6 7 5] [8 10 11 9] [12 13 15 14] [16 18 19 17] [20 21 23 22]]`

Basically leaving out the number that indicates the number of vertices the next polygons has, and group the indices of each polygon into a subarray.

Thanks!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [June 29, 2020, 2:00am UTC](https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662/5 "2020-06-29T02:00:14Z")

</div>

```python
def splitcells(cellarray):
    cells = []
    loc = 0
    while loc < len(cellarray):
        n = cellarray[loc]
        loc += n + 1
        cells.append(cellarray[loc-n:loc])
    return cells

```

```auto
>>> cellarray = [4,0,1,3,2,4,4,6,7,5,4,8,10,11,9,4,12,13,15,14,4,16,18,19,17,4,20,21,23,22]
>>> cells = splitcells(cellarray)
>>> cells
[[0, 1, 3, 2], [4, 6, 7, 5], [8, 10, 11, 9], [12, 13, 15, 14], [16, 18, 19, 17], [20, 21, 23, 22]]

```

---

<div class="post-metadata">

### Author: ![panicbuttonvfx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/panicbuttonvfx/32/1838_2.png) [@panicbuttonvfx](https://discourse.vtk.org/u/panicbuttonvfx)
#### Post date: [June 29, 2020, 2:30am UTC](https://discourse.vtk.org/t/getpolys-vertex-indices-weird-order/3662/6 "2020-06-29T02:30:03Z")

</div>

Thanks! Much appreciated
