# Instantiating a lot of quads for an unstructured grid

**URL:** https://discourse.paraview.org/t/instantiating-a-lot-of-quads-for-an-unstructured-grid/3368
**Category:** Development
**Tags:** python
**Created:** [January 20, 2020, 8:59am UTC](https://discourse.paraview.org/t/instantiating-a-lot-of-quads-for-an-unstructured-grid/3368 "2020-01-20T08:59:19Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![vbuck](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/v/45deac/32.png) [@vbuck](https://discourse.paraview.org/u/vbuck)
#### Post date: [January 20, 2020, 8:59am UTC](https://discourse.paraview.org/t/instantiating-a-lot-of-quads-for-an-unstructured-grid/3368/1 "2020-01-20T08:59:19Z")

</div>

Hi everyone!

For a plugin I am trying to write, I need to create a surface consisting of about 300k quads. These quads are regularly spaced on the x & y axes, but have varying z levels.  
The surface is also not rectangular, but has irregular edges, like this:

 ![test](https://discourse.paraview.org/uploads/default/original/2X/9/9a95c4e5533cf5d393fb725b224671a8f93cb3b2.png)  
(the outer black border indicates NODATA, the inner grey fields are height data)

I have a native module that generates two numpy arrays for me,

```auto
Positions
==========
x y z
....

```

and

```auto
Quads
============
id id id id
....

```

where the rows of ids from the quads array indicate rows from the positions array to use as vertex coordinates.

Currently I am generating a vtkUnstructuredGrid by first creating vtkPoints:

```auto
coordinates = algs.make_vector(positions[:,0], positions[:,1],positions[:,2])
points = vtkPoints()
points.SetData(dsa.numpyTovtkDataArray(coordinates, 'Points'))
output.SetPoints(points)

```

and then individually inserting vtkIdLists to create the quads

```auto
 for i in range(quads.shape[0]):
            pids = vtkIdList()
            pids.InsertId(0,quads[i,0])    
            pids.InsertId(1,quads[i,1])
            pids.InsertId(2,quads[i,2])
            pids.InsertId(3,quads[i,3])
            output.InsertNextCell(VTK_QUAD, pointIds)

```

This is of course really slow and manages to fill up my RAM rather quickly.  
Is there a faster way to do this?

Is a vtkUnstructuredGrid even the correct data structure for this task?

Thanks in advance!
