如何在单元格质心处存储vtkUnstructuredGrid的矢量字段

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

是否可以使用vtkStructuredGrid将矢量场存储在四面体网格的质心处?我尝试了下面的代码,但VTK(版本8.1)抱怨它,我猜这是因为这个矢量字段是在单元质心处定义的。

Warning: In c:\vtk\src\common\datamodel\vtkdataset.cxx, line 443
vtkUnstructuredGrid (0000020A4EC10D50): Point array  with 3 components, has 137 tuples but there are only 64 points

矢量场定义如下:

vtkSmartPointer<vtkUnstructuredGrid> uGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();

// ... I already populated uGrid with points and tetrahedral information
// numberOfPoints = 64
// numberOfTetrahedra = 103

// Add a vector field at the centroid of each tetrahedral
vtkSmartPointer<vtkDoubleArray> vectors = vtkSmartPointer<vtkDoubleArray>::New();
vectors->SetNumberOfTuples(numberOfTetrahedra);
vectors->SetNumberOfComponents(3);
for (vtkIdType ielement = 0; ielement < numberOfTetrahedra; ielement++)
{
    vectors->InsertNextValue(vec[3 * ielement]);
    vectors->InsertNextValue(vec[3 * ielement + 1]);
    vectors->InsertNextValue(vec[3 * ielement + 2]);
}
uGrid->GetPointData()->SetVectors(vectors);

// Write the data to file
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName("vtk_test_write_unstructured_grid.vtu");
writer->SetInputData(uGrid);
writer->Write();
  • VTK是否提供了在质心处保存矢量的工具?
  • VTK是否有过滤器将以单元格为中心的字段映射到网格点?

我很感激有任何提示/建议来解决这个问题。

c++ vtk paraview
1个回答
2
投票

对于与细胞相关的数据,您应该使用vtkCellData。因此,在您的代码中尝试替换您将vector设置为的行

uGrid->GetCellData()->SetVectors(vectors);

这些载体与细胞相关。您可以将它们解释为与细胞质心相关联,但在.vtu文件中,您可能找不到与细胞质心明显的关联。

要将以单元格为中心的字段映射到网格的点,请考虑探索vtkCellDataToPointData类。

© www.soinside.com 2019 - 2024. All rights reserved.