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


(Hadi Salimi) #1

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


(Nicolas Vuaille) #2

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.


(Hadi Salimi) #3

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


(Nicolas Vuaille) #4

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