[Paraview] Vectorized data assignment

Christian Gabriel cgabriel at matrix-solutions.com
Mon Nov 7 09:50:55 EST 2016


Thanks Dave.

That’s good to know. My background is actually in C++ programming, but the SDK I’m trying to link in is natively in C# and wrapped with Python. I could try mix-code programming (C++/C#), but trying to avoid that for now and use Python instead ….

Chris

From: David Lonie [mailto:david.lonie at kitware.com]
Sent: November-07-16 9:27 AM
To: Christian Gabriel
Cc: paraview at paraview.org
Subject: Re: [Paraview] Vectorized data assignment

On Mon, Nov 7, 2016 at 9:00 AM, Christian Gabriel <cgabriel at matrix-solutions.com<mailto:cgabriel at matrix-solutions.com>> wrote:
Good day.

I found this example code<http://www.paraview.org/Wiki/VTK/Examples/Python/GeometricObjects/Display/Cell3DDemonstration>:

    # Create the points
    points = vtk.vtkPoints()
    points.InsertNextPoint(0.0, 0.0, 0.0)
    points.InsertNextPoint(1.0, 0.0, 0.0)
    points.InsertNextPoint(1.0, 1.0, 0.0)
    points.InsertNextPoint(0.0, 1.0, 0.0)
    … … …

which had me wonder if there is a way to assign data in a vectorized fashion instead of point by point?

Let’s say I can read in 3 1D arrays (vectors) with X, Y, Z data or one 2D array (matrix, dataframe) with the same data in columns, is there a way to assign that data to the points all at once instead of iteratively?

    points = vtk.vtkPoints()
    points.InsertNextPoint(X, Y, Z)    - just saying; this is obviously not correct!

Obviously, any data could be combined and reshaped first to whatever format required ….

Given that ParaView/VTK was designed to work with (very) large data sets I’d be surprised if there were no vectorized operations implemented.

In C++, there are a number of ways to do this by modifying the data array directly (instead of going through the vtkPoints interface). You can extract the data array from the points by calling points.GetData(). You can also create a points array separately and assign it to the vtkPoints instance by calling points.SetData(myArray).

There are two types of arrays in VTK, AoS (Array-of-Structs, the default used for e.g. vtkFloatArray, etc), and SoA (Struct-of-Arrays, still somewhat experimental at this point):

These doxygen pages describe the specific APIs for them:

http://www.vtk.org/doc/nightly/html/classvtkAOSDataArrayTemplate.html
http://www.vtk.org/doc/nightly/html/classvtkSOADataArrayTemplate.html

There are several ways to do low-level copying of data using methods like AoS::SetArray, SoA::SetComponentArray, AoS::GetPointer, SoA::GetComponentArrayPointer, etc, which will allow you to set the array's memory buffer explicitly, or just get low-level access to it for for modifications.

However, I'm not sure how much of this is exposed in the python/numpy layers, so it might take some experimentation. Hopefully someone more familiar with the python bindings will chime in.

HTH,
Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20161107/e4976e00/attachment.html>


More information about the ParaView mailing list