如何在一个 .vtu 文件中写入多个 vtkUnstructuredGrid [英] how to write multiple vtkUnstructuredGrid in one .vtu file

查看:59
本文介绍了如何在一个 .vtu 文件中写入多个 vtkUnstructuredGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个 .vtu 文件中编写多个非结构化网格.

I want to write multiple unstructured grids in one .vtu file.

我在下面尝试过.MakeHexagonalPrism() 和 MakeHexahedron() 返回 vtkSmartPointer 类型.结果是输出文件中只有一个非结构化网格.

I tried below. MakeHexagonalPrism() and MakeHexahedron() return vtkSmartPointer type. The result is there was only one unstructured grid in the output file.

  vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
    vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
  writer->SetFileName(filename.c_str());
  writer->SetInputData(MakeHexagonalPrism());
  writer->SetInputData(MakeHexahedron());
  writer->Write();

我也在下面尝试过.cellArray1 和 cellArray2 的类型是 vtkSmartPointer.结果是输出文件中只有一种类型的非结构化网格.

I also tried below. The type of cellArray1 and cellArray2 is vtkSmartPointer. The result is there was only one type of unstructured grid in the output file.

  vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid =
    vtkSmartPointer<vtkUnstructuredGrid>::New();
  unstructuredGrid->SetPoints(points);
  unstructuredGrid->SetCells(VTK_TETRA, cellArray1);
  unstructuredGrid->SetCells(VTK_WEDGE, cellArray2);

我不知道如何在一个 .vtu 文件中编写多个非结构化网格.如有任何提示,我将不胜感激.

I do not know how to write multiple unstructured grids in one .vtu file. I'd be grateful for any hints.

推荐答案

如文档所述,vtkUnstructuredGrid 类非常通用.

As described by the documentation, the vtkUnstructuredGrid class is very versatile.

数据集代表所有可能的细胞类型的任意组合

dataset represents arbitrary combinations of all possible cell types

您可以使用 vtkAppendFilter 来附加不同的数据设置为一个,然后将输出作为 vtkUnstructuredGrid 结果写入 .vtu 文件.

You could use the vtkAppendFilter in order to append different data sets into one then write the output as a vtkUnstructuredGrid result in a .vtu file.

// create the append filter
vtkSmartPointer<vtkAppendFilter> append =
vtkSmartPointer<vtkAppendfilter>::New();

// add each data set
append->AddInputData(MakeHexagonalPrism());
append->AddInputData(MakeHexahedron());
append->Update();

// write the result
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName(filename.c_str());
writer->SetInputData(append->GetOutput());

EDIT:我按照 Amit Singh 的建议添加了缺少的 Update() 函数调用

EDIT: I added the missing Update() function call as suggested by Amit Singh

这篇关于如何在一个 .vtu 文件中写入多个 vtkUnstructuredGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆