Code Search for Developers
 
 
  

vtk_marching_cubes.py from matplotlib at Krugle


Show vtk_marching_cubes.py syntax highlighted

#!/usr/local/bin/python
import os
import vtk
import colors


# Create the volume reader
reader = vtk.vtkVolume16Reader()
reader.SetDataDimensions(256,256)
reader.GetOutput().SetOrigin(0.0,0.0,0.0)
reader.SetFilePrefix('../data/images/r')
reader.SetFilePattern( '%s%d.ima')
reader.SetDataByteOrderToBigEndian()
reader.SetImageRange(1001,1060)
reader.SetDataSpacing(1.0,1.0,3.5)
reader.Update()

# Marching cubes generates iso-surfaces
iso = vtk.vtkMarchingCubes()
iso.SetInput(reader.GetOutput())

# We'll run it though the decimation filter to make it a little
# smaller.
decimate = vtk.vtkDecimate()
decimate.SetInput(iso.GetOutput())

# Some iso values
#   vessles : 120
#   cortex  : 100
#   face    :  20
iso.SetValue(0,100)
isoMapper = vtk.vtkPolyDataMapper()
isoMapper.SetInput(decimate.GetOutput())

# You can assign scalars to voxels, eg to map things onto the cortex
# Here we are just dislpaying the anatomy so we turn scalars off
isoMapper.ScalarVisibilityOff()

isoActor = vtk.vtkActor()
isoActor.SetMapper(isoMapper)
# this is the color of the surface
isoActor.GetProperty().SetColor(colors.antique_white)


# Let's save the data to a VTK file for external processing. The
# Update command is used to make sure the pipeline is up-to-date
# before writing

decimate.Update()
writer = vtk.vtkDataSetWriter()
writer.SetInput(decimate.GetOutput())
writer.SetFileName('../data/bighead.vtk')
writer.SetFileTypeToASCII()
writer.Write()

# Now visualize it; set up the renderer and add the actor
ren = vtk.vtkRenderer()
ren.AddActor(isoActor)
ren.SetBackground(0.2,0.3,0.4)

# Set up the render window and interactor
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.SetSize(450,450)

# Ready, set, go!
iren.Initialize()
iren.Start()




See more files for this project here

matplotlib

Matplotlib is a pure python plotting library with the goal of making\r\npublication quality plots using a syntax familiar to matlab users. \r\nThe library uses Numeric for handling large\r\ndata sets and supports a variety of output backends

Project homepage: http://sourceforge.net/projects/matplotlib
Programming language(s): C,C++,Python
License: other

  scipy/
    bessel.py
    example1.1
    example10.2.1
    example10.2.2
    example10.2.3
    example10.2.5
    example10.3.1
    example10.3.2
    example10.3.6
    example10.4.4
    example2.1
    example2.2
    example2.3
    example3.1
    example3.2
    example4.1
    example4.2
    example4.3
    example4.4
    example4.5
    example4.6
    example5.1
    example5.2
    example5.3
    example5.4
    example5.5
    example5.6
    example5.7
    example5.8
    example5.9
    example6.1
    example6.2
    example6.3
    example6.4
    least_squares_fit.py
    roots1d.py
  .matplotlibrc
  README
  WallisPi.py
  WindowLevelInterface.py
  __init__.py
  colors.py
  erathostenes.py
  ip_embed-short.py
  ip_embed.py
  ip_expensive_init.py
  ip_simple.py
  ip_simple2.py
  mayavi_bighead.py
  mpl_agg_oo.py
  mpl_image_ratner.py
  mpl_imshow.py
  mpl_pylab.py
  mpl_set_get.py
  mpl_subplot_demo.py
  parse_file.py
  runall.py
  vtk_hello.py
  vtk_marching_cubes.py
  vtk_slice_viewer.py
  weave_callback.py
  weave_cplx.py
  weave_examples.py
  wrap_f2py_setup.py
  wrap_weave.py