python中的网格抽取

Ana*_*ndJ 2 python vtk meshlab

我有一个高分辨率的三角形网格,大约有 200 万个三角形。我想将三角形​​和顶点的数量减少到大约 10000 个左右,同时尽可能地保留其一般形状。

我知道这可以在 Matlab 中使用 reducepatch 来完成。另一种选择是 qslim 包。在 VTK 中也有抽取功能,它有 python 接口,所以从技术上讲,它在 python 中也是可能的。Meshlab 也可能在 python 中可用(?)。

我怎样才能在 python 中进行这种网格抽取?示例将不胜感激。

Gio*_*ioR 5

这是从其 C++ 等效 vtk 示例(http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Decimation)翻译的最小 python 原型,正如MrPedru22所建议的那样。

from vtk import (vtkSphereSource, vtkPolyData, vtkDecimatePro)


def decimation():
    sphereS = vtkSphereSource()
    sphereS.Update()

    inputPoly = vtkPolyData()
    inputPoly.ShallowCopy(sphereS.GetOutput())

    print("Before decimation\n"
          "-----------------\n"
          "There are " + str(inputPoly.GetNumberOfPoints()) + "points.\n"
          "There are " + str(inputPoly.GetNumberOfPolys()) + "polygons.\n")

    decimate = vtkDecimatePro()
    decimate.SetInputData(inputPoly)
    decimate.SetTargetReduction(.10)
    decimate.Update()

    decimatedPoly = vtkPolyData()
    decimatedPoly.ShallowCopy(decimate.GetOutput())

    print("After decimation \n"
          "-----------------\n"
          "There are " + str(decimatedPoly.GetNumberOfPoints()) + "points.\n"
          "There are " + str(decimatedPoly.GetNumberOfPolys()) + "polygons.\n")


if __name__ == "__main__":
    decimation()
Run Code Online (Sandbox Code Playgroud)


小智 5

我建议您使用vtkQuadricDecimation,输出模型的质量在视觉上比使用vtkDecimatePro(没有适当设置)更好。

decimate = vtkQuadricDecimation()
decimate.SetInputData(inputPoly)
decimate.SetTargetReduction(0.9)
Run Code Online (Sandbox Code Playgroud)

最重要的事情之一是在保存STL时使用二进制表示:

stlWriter = vtkSTLWriter()
stlWriter.SetFileName(filename)
stlWriter.SetFileTypeToBinary()
stlWriter.SetInputConnection(decimate.GetOutputPort())
stlWriter.Write()
Run Code Online (Sandbox Code Playgroud)