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

问题描述 投票:0回答:1

我需要从 .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 属性的名称及其实际数值?任何帮助表示赞赏! 干杯, 多马诺夫

c++ vtk
1个回答
5
投票
//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(i);
    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;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.