單元綁定舊方法
//單元類型列表
vtkIdTypeArray* cellInfoList = vtkIdTypeArray::New();
cellInfoList->SetNumberOfValues((numCellPnts + 1) * numberCells);
vtkIdType* cellInforPtr = cellInfoList->GetPointer(0);
//單元列表
vtkUnsignedCharArray* cellTypeList = vtkUnsignedCharArray::New();
cellTypeList->SetNumberOfValues(numberCells);
unsigned char* cellTypesPtr = cellTypeList->GetPointer(0);
for (int c = 0; c < numberCells; c++)
{
//單元類型
*cellTypesPtr++ = VTK_CellType;
//單元點(diǎn)數(shù)
*cellInforPtr++ = numCellPnts;
for (int j = 0; j < numCellPnts; j++)
{
//點(diǎn)
//*cellInforPtr++ = pointID
}
}
cellInforPtr = nullptr;
cellTypesPtr = nullptr;
// 單元數(shù)組
vtkCellArray* theCellArray = vtkCellArray::New();
theCellArray->ImportLegacyFormat(cellInfoList);
cellInfoList->Delete();
cellInfoList = nullptr;
// 綁定單元
unstrctGrid->SetCells(cellTypeList, theCellArray);
theCellArray->Delete();
cellTypeList->Delete();
theCellArray = nullptr;
cellTypeList = nullptr;
vtk單元類型:https://blog.csdn.net/calmreason/article/details/124268501
新的填充方式相對(duì)于绑嘹,創(chuàng)建單元對(duì)象的方式效率更高痰娱,比綁定單元的方式更靈活。
vtk新的填充單元方式(非多面體)
vtkNew<vtkUnstructuredGrid> unstruct;
std::vector<std::vector>cells;//單元和點(diǎn)id
unstruct->Allocate(cells.size());//初始化單元大小
for (int i = 0 ;i< cells.size();i++)
{
vtkNew<vtkIdList> cellIDdList;//填充單元點(diǎn)id數(shù)據(jù)
for (int curri = 0; curri < cells[i].size(); curri++)
{
cellIDdList->InsertNextId(cells[i][curri]);
}
unstruct->InsertNextCell(VTK_POLYGON, cellIDdList->GetNumberOfIds(), cellIDdList->GetPointer(0));//填充單元芥被,1.單元類型,2.單元點(diǎn)數(shù)悬垃,3數(shù)據(jù)指針
}
vtk新的填充單元方式(多面體)
多面體單元數(shù)據(jù)需要面和點(diǎn)楣富,點(diǎn)構(gòu)成面撵幽,面構(gòu)成體是牢。
vtkNew<vtkUnstructuredGrid> unstruct;
std::vector<std::vector<vtkIdType>> cells;//每個(gè)單元的面id數(shù)據(jù)
std::vector<std::vector<vtkIdType>> faces;//每個(gè)面的點(diǎn)id數(shù)據(jù)
unstruct->Allocate(cells.size());//初始化單元大小
for (int i = 0; i < cells.size();i++)
{
const auto& cell = cells[i];
vtkNew<vtkIdList> polyhedron;
for (auto& aFaceIndex : cell )
{
const auto& aFace = faces[aFaceIndex];
const auto faceSize = static_cast<vtkIdType>(aFace.size());//每個(gè)面點(diǎn)數(shù)
polyhedron->InsertNextId(faceSize);
for (auto& aVertexIndex : aFace)
{
polyhedron->InsertNextId(aVertexIndex);//填充點(diǎn)id數(shù)據(jù)
}
}
unstruct->InsertNextCell(VTK_POLYHEDRON, cell .size(), polyhedron->GetPointer(0));//填充單元數(shù)據(jù)僵井,2.面的數(shù)量,單元數(shù)據(jù)指針驳棱。
}