Produce VTK unstuctured grid output without copying data into VTK

We’ve been using VTK/ParaView for a couple of years now as an output format for our simulations for a-posteriori visualization an analysis. The current solution is to copy all of the relevant simulation data out of our std::vector struct-of-array data into the equivalent VTK structures.

This works fine, but roughly doubles our memory requirements and is needlessly slow.

Is there any infrastructure for producing .vtu outputs directly from application user code, without this intermediate copy?

See vtkSOADataArrayTemplate and the SetArray() method especially the “save” argument.

Oh, cool. So where I have

auto scalars = vtkSmartPointer<vtkDoubleArray>::New();
scalars->SetName(name.c_str());
scalars->SetNumberOfComponents(1);
scalars->SetSize(size);
// copy data
vtu->GetPointData()->AddArray(scalars);

I can use a

auto scalars = vtkSmartPointer<vtkSOADataArrayTemplate<double>>::New();
scalars->SetName(name.c_str());
scalars->SetNumberOfComponents(1);
scalars->SetArray(0, data, size, true, true);
vtu->GetPointData()->AddArray(scalars);

instead?

I’ll give that a try, thank you.

Other than VTK’s trouble with const-correctness forcing me to const_cast (can’t SetArray(double const*) or vtkSOADataArrayTemplate<double const>), this seems to be working. Thank you.

1 Like