<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p></p>
<div class="post-text" itemprop="text">
<p>Hello,</p>
<p><br>
</p>
<p>I want to reduce the number of triangles in a mesh (STL file). Here is my code:</p>
<pre class="default prettyprint prettyprinted"><span class="kwd">import</span><span class="pln"> vtk

filename </span><span class="pun">=</span><span class="pln"> </span><span class="str">'E://stl_file.stl'</span><span class="pln">
reader </span><span class="pun">=</span><span class="pln"> vtk</span><span class="pun">.</span><span class="pln">vtkSTLReader</span><span class="pun">()</span><span class="pln">
reader</span><span class="pun">.</span><span class="typ">SetFileName</span><span class="pun">(</span><span class="str">'filename.stl'</span><span class="pun">)</span><span class="pln">

</span><span class="com">##convert polygonal mesh into triangle mesh</span><span class="pln">
tri </span><span class="pun">=</span><span class="pln"> vtk</span><span class="pun">.</span><span class="pln">vtkTriangleFilter</span><span class="pun">()</span><span class="pln">
tri</span><span class="pun">.</span><span class="typ">SetInputConnection</span><span class="pun">(</span><span class="pln">reader</span><span class="pun">.</span><span class="typ">GetOutputPort</span><span class="pun">());</span><span class="pln">

</span><span class="com">##decimate triangle</span><span class="pln">
deci </span><span class="pun">=</span><span class="pln"> vtk</span><span class="pun">.</span><span class="pln">vtkDecimatePro</span><span class="pun">()</span><span class="pln">
deci</span><span class="pun">.</span><span class="typ">SetInputConnection</span><span class="pun">(</span><span class="pln">tri</span><span class="pun">.</span><span class="typ">GetOutputPort</span><span class="pun">())</span><span class="pln">
deci</span><span class="pun">.</span><span class="typ">SetTargetReduction</span><span class="pun">(</span><span class="lit">0.9</span><span class="pun">)</span><span class="pln">
deci</span><span class="pun">.</span><span class="typ">PreserveTopologyOn</span><span class="pun">()</span></pre>
<p>it seems to work (at least it runs without errors). Now how can I extract points and triangles of the mesh? </p>
<p><br>
</p>
<p>Regards</p>
</div>
<br>
<p></p>
</div>
</body>
</html>