Kerim
Kerim

Reputation: 199

VTK C++ set points for vtkStructuredGrid from three XYZ vectors

VTK examples uses vtkPoints to set coordinates for the structured grid. Usually it works as points->InsertNextPoint(i, j, k); structuredGrid->SetPoints(points); But my XYZ coordinates are stored in three different vectors x, y, z and I don't want to copy them as it takes a lot of memory, how can I set coordinates for structured grid directly from XYZ vectors without copying?

Best regards, kerim

Upvotes: 0

Views: 526

Answers (1)

Nico Vuaille
Nico Vuaille

Reputation: 2488

VTK also supports Structure Of Arrays.

  vtkSOADataArrayTemplate<double>* pointArray = vtkSOADataArrayTemplate<double>::New();
  pointArray->SetNumberOfComponents(3);
  pointArray->SetNumberOfTuples(nbOfPoints);
  pointArray->SetArray(0, XArray, nbOfPoints, false, true);
  pointArray->SetArray(1, YArray, nbOfPoints, false, true);
  pointArray->SetArray(2, ZArray, nbOfPoints, false, true);

  vtkNew<vtkPoints> points;
  points->SetData(pointArray);
  pointArray->Delete();
  VTKGrid->SetPoints(points);

Upvotes: 2

Related Questions