# Is there any zero-copy way to set the coordinates of a vtkStructuredGrid from separate X,Y and Z buffers?

**URL:** https://discourse.paraview.org/t/is-there-any-zero-copy-way-to-set-the-coordinates-of-a-vtkstructuredgrid-from-separate-x-y-and-z-buffers/438
**Category:** In Situ Support
**Created:** [August 16, 2018, 1:48pm UTC](https://discourse.paraview.org/t/is-there-any-zero-copy-way-to-set-the-coordinates-of-a-vtkstructuredgrid-from-separate-x-y-and-z-buffers/438 "2018-08-16T13:48:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hsalimi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/hsalimi/32/41_2.png) [@hsalimi](https://discourse.paraview.org/u/hsalimi)
#### Post date: [August 16, 2018, 1:48pm UTC](https://discourse.paraview.org/t/is-there-any-zero-copy-way-to-set-the-coordinates-of-a-vtkstructuredgrid-from-separate-x-y-and-z-buffers/438/1 "2018-08-16T13:48:47Z")

</div>

Hello Everyone,

I have a very large curvilinear grid in my simulation and I am using vtkStructuredGrid to this aim. For setting the coordinate points of the gird, it seems that I have to use a vtkPoints object and add the grid coordinates as (x,y,z) tuples to it.

Unfortunately, in my simulation, I have the coordinates as separate vectors, i.e X, Y and Z. Is it possible to use these vectors directly for grid coordinates without any memory copy? Or I have to reshape my coordinates to the ones needed by vtkPoints?

Regards,  
Hadi

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [August 16, 2018, 2:15pm UTC](https://discourse.paraview.org/t/is-there-any-zero-copy-way-to-set-the-coordinates-of-a-vtkstructuredgrid-from-separate-x-y-and-z-buffers/438/2 "2018-08-16T14:15:20Z")

</div>

You may want to look at the ‘vtkSOADataArrayTemplate’ class. It provides interface to do what you want.

I never used it directly, but as far as I know this class can handle your 3 arrays X, Y and Z without copy.  
Then you can add it to a vtkPoints thanks to the `SetData()` method, and use your vtkPoints as usual.

---

<div class="post-metadata">

### Author: ![hsalimi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/hsalimi/32/41_2.png) [@hsalimi](https://discourse.paraview.org/u/hsalimi)
#### Post date: [August 16, 2018, 2:28pm UTC](https://discourse.paraview.org/t/is-there-any-zero-copy-way-to-set-the-coordinates-of-a-vtkstructuredgrid-from-separate-x-y-and-z-buffers/438/3 "2018-08-16T14:28:36Z")

</div>

Hi Nicolas,

Actually, I checked the vtkPoints methods before posting here. The only interesting method for me was SetData that takes a vtkDataArray\* parameter. The description of this method notes that:

> This function must be implemented in a concrete subclass to check for consistency. (The tuple size must match the type of data. For example, 3-tuple data array can be assigned to a vector, normal, or points object, but not a tensor object, which has a tuple dimension of 9. Scalars, on the other hand, can have tuple dimension from 1-4, depending on the type of scalar.)

To me, this means that the input parameter is a buffer containing coordinate tuples(e.g. {(x1,y1,z1),(x2,y2,z2), …} ). Am I right?

Regards,  
Hadi

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [August 16, 2018, 3:02pm UTC](https://discourse.paraview.org/t/is-there-any-zero-copy-way-to-set-the-coordinates-of-a-vtkstructuredgrid-from-separate-x-y-and-z-buffers/438/4 "2018-08-16T15:02:31Z")

</div>

Indeed, in most subclass of vtkDataArray, the buffer is an array of tuple.  
But `vtkSOADataArrayTemplate` reimplements the vtkDataArray interface in order to handle your case, i.e. a structure of many (3 here) arrays.

As the internal buffer is accessed only from dataArray method, (and vtkPoints do so), it is not a problem.

See this example in ParaView sources: [https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Catalyst/CxxSOADataArrayExample/FEAdaptor.cxx#L28](https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Catalyst/CxxSOADataArrayExample/FEAdaptor.cxx#L28)

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [June 26, 2019, 5:36pm UTC](https://discourse.paraview.org/t/is-there-any-zero-copy-way-to-set-the-coordinates-of-a-vtkstructuredgrid-from-separate-x-y-and-z-buffers/438/5 "2019-06-26T17:36:24Z")

</div>

> [@hsalimi](#):
>
> I have a very large curvilinear grid in my simulation and I am using vtkStructuredGrid to this aim. For setting the coordinate points of the gird, it seems that I have to use a vtkPoints object and add the grid coordinates as (x,y,z) tuples to it.

Dear Hadi,  
this is exactly what I intend to do. Do you mind sharing your `FEAdaptor` code? There is none in the examples folder.  
Regards,  
Bastian
