Exemplo n.º 1
0
def img_to_stl(img):
    # Pad black to the boundaries of the image
    pad = [5, 5, 5]
    img = sitk.ConstantPad(img, pad, pad)
    vtkimg = sitk2vtk.sitk2vtk(img)
    isovalue = 0
    mesh = vtkutils.extractSurface(vtkimg, isovalue)
    connectivityFilter = False
    mesh = vtkutils.cleanMesh(mesh, connectivityFilter)
    smoothIterations = 25
    mesh = vtkutils.smoothMesh(mesh, smoothIterations)
    quad = .90
    mesh = vtkutils.reduceMesh(mesh, quad)

    vtkutils.writeMesh(mesh, "result.stl")
Exemplo n.º 2
0
import traceback, vtk

if debug:
    print "\nVTK version: ", vtk.vtkVersion.GetVTKVersion()
    print "VTK: ", vtk, "\n"

import vtkutils

mesh = vtkutils.extractSurface(vtkimg, isovalue)
vtkimg = None
gc.collect()
mesh2 = vtkutils.cleanMesh(mesh, connectivityFilter)
mesh = None
gc.collect()
mesh3 = vtkutils.smoothMesh(mesh2, smoothIterations)
mesh2 = None
gc.collect()
mesh4 = vtkutils.reduceMesh(mesh3, quad)
mesh3 = None
gc.collect()

if rotFlag:
    mesh5 = vtkutils.rotateMesh(mesh4, rotAxis, rotAngle)
else:
    mesh5 = mesh4
vtkutils.writeMesh(mesh5, outname)
mesh4 = None
gc.collect()

Exemplo n.º 3
0
import vtkutils

if debug:
  print "Extracting surface"
mesh = vtkutils.extractSurface(vtkimg, isovalue)
vtkimg = None
gc.collect()
if debug:
  print "Cleaning mesh"
mesh2 = vtkutils.cleanMesh(mesh, connectivityFilter)
mesh = None
gc.collect()
if debug:
  print "Smoothing mesh"
mesh3 = vtkutils.smoothMesh(mesh2, smoothIterations)
mesh2 = None
gc.collect()
if debug:
  print "Simplifying mesh"
mesh4 = vtkutils.reduceMesh(mesh3, quad)
mesh3 = None
gc.collect()

if rotFlag:
    mesh5 = vtkutils.rotateMesh(mesh4, rotAxis, rotAngle)
else:
    mesh5 = mesh4
vtkutils.writeMesh(mesh5, outname)
mesh4 = None
gc.collect()