是否可以使用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();
感谢您提供解决此问题的任何提示/建议。
答案 0 :(得分:2)
对于与单元格关联的数据,应使用vtkCellData。因此,在您的代码中尝试替换将向量设置为的行
uGrid->GetCellData()->SetVectors(vectors);
这些向量与细胞相关。您可以将它们解释为与单元质心相关联,尽管在.vtu
文件中可能找不到与单元质心的任何显式关联。
要将单元中心的字段映射到网格的点,请考虑探索vtkCellDataToPointData类。