VTK C++ 从三个 XYZ 向量为 vtkStructuredGrid 设置点

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

VTK 示例使用 vtkPoints 设置结构化网格的坐标。通常它作为 points->InsertNextPoint(i, j, k); structuredGrid->SetPoints(points); 但是我的 XYZ 坐标存储在三个不同的向量中 x, y, z 我不想复制它们,因为它占用大量内存,我如何直接从 XYZ 向量设置结构化网格的坐标而不复制?

此致, 克里姆

VTK 也支持数组结构。

  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);