python中的网格抽取 [英] mesh decimation in python

查看:27
本文介绍了python中的网格抽取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a high resolution triangular mesh with about 2 million triangles. I want to reduce the number of triangles and vertices to about ~10000 each, while preserving its general shape as much as possible.

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

I know this can be done in Matlab using reducepatch. Another alternative is qslim package. Also there is decimation functionality in VTK which has python interface, so technically it is possible in python as well. Meshlab is probably available in python as well (?).

如何在 python 中进行这种网格抽取?示例将不胜感激.

How can I do this kind of mesh decimation in python? Examples would be greatly appreciated.

推荐答案

这里是一个最小的 Python 原型,从它的 C++ 等效 vtk 示例(http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Decimation),如 MrPedru22 很好的建议.

Here is a minimal python prototype translated from its c++ equivalent vtk example (http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Decimation), as MrPedru22 well suggested.

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()

这篇关于python中的网格抽取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆