VTK:从 c++ 中的 vtu 非结构化网格中提取单元格数据

VTK: Extracting Cell Data from vtu unstructured grids in c++

我需要从 .vtu(XML 非结构化网格)中提取所有单元格数据,以便在 C++ 程序中进行进一步操作。我对 VTK 很陌生...

      //read all the data from the file
      vtkSmartPointer<vtkXMLUnstructuredGridReader> reader =
      vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
      reader->SetFileName(filename.c_str());
      reader->Update();

      unsigned int cellNumber = reader->GetOutput()->GetNumberOfCells();
      cout << "There are " << cellNumber << " input cells." << endl;

这是正确的 - 单元格编号显示正确。现在如何访问存储在 .vtu 文件中的不同 CellArrays 属性的名称以及它们的实际数值?任何帮助表示赞赏! 干杯, 多马诺夫

//read all the data from the file
  vtkSmartPointer<vtkXMLUnstructuredGridReader> reader =
  vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
  reader->SetFileName(filename.c_str());
  reader->Update();

  unsigned int cellNumber = reader->GetOutput()->GetNumberOfCells();
  cout << "There are " << cellNumber << " input cells." << endl;

要访问非结构化网格的单元格数据,您可以按如下方式进行:

vtkUnstructuredGrid* ugrid = reader->GetOutput();
vtkCellData *cellData = ugrid->GetCellData();
for (int i = 0; i < cellData->GetNumberOfArrays(); i++)
{
    vtkDataArray* data = cellData->GetArray(j);
    cout << "name " << data->GetName() << endl;
    for (int j = 0; j < data->GetNumberOfTuples(); j++)
    {
        double value = data->GetTuple1(j);
        cout << "  value " << j << "th is " << value << endl;
    }
}