vtk非結(jié)構(gòu)網(wǎng)格填充單元

單元綁定舊方法

     //單元類型列表
    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
新的填充方式相對于,創(chuàng)建單元對象的方式效率更高,比綁定單元的方式更靈活。
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;//每個單元的面id數(shù)據(jù)
    std::vector<std::vector<vtkIdType>> faces;//每個面的點(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());//每個面點(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ù)指針。
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容