是否可以使用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();
我很感激有任何提示/建议来解决这个问题。
对于与细胞相关的数据,您应该使用vtkCellData。因此,在您的代码中尝试替换您将vector设置为的行
uGrid->GetCellData()->SetVectors(vectors);
这些载体与细胞相关。您可以将它们解释为与细胞质心相关联,但在.vtu
文件中,您可能找不到与细胞质心明显的关联。
要将以单元格为中心的字段映射到网格的点,请考虑探索vtkCellDataToPointData类。