本文主要是介绍读入模型并转换vtk 的渲染模型,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
vtkNew<vtkPolyData> ConvertVCGToVTK(const std::shared_ptr<Mesh>&ptrMesh) {
vtkNew<vtkPoints> points;
vtkNew<vtkCellArray> polys;
int dataSize = ptrMesh->numVertex();
// 插入顶点
for (size_t index = 0; index < dataSize; ++index) {
core::TVertex* ptrVert = ptrMesh->getVertex(index);
points->InsertNextPoint(ptrVert->P().X(), ptrVert->P().Y(), ptrVert->P().Z());
}
dataSize = ptrMesh->numFace();
// 插入面片
for (size_t index = 0; index < dataSize; ++index) {
core::TFace* ptrFace = ptrMesh->getFace(index);
vtkNew<vtkTriangle> triangle;
int vertIndex0 = -1;
int vertIndex1 = -1;
int vertIndex2 = -1;
ptrMesh->getVertIndex(index, vertIndex0, vertIndex1, vertIndex2);
triangle->GetPointIds()->SetId(0, vertIndex0);
triangle->GetPointIds()->SetId(1, vertIndex1);
triangle->GetPointIds()->SetId(2, vertIndex2);
polys->InsertNextCell(triangle);
}
vtkNew<vtkPolyData> polyData;
polyData->SetPoints(points);
polyData->SetPolys(polys);
return polyData;
}
这篇关于读入模型并转换vtk 的渲染模型的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!