Menu

[r1006]: / trunk / course / examples / vtk_marching_cubes.py  Maximize  Restore  History

Download this file

54 lines (44 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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())
# Some iso values
# vessles : 120
# cortex : 100
# face : 20
iso.SetValue(0,100)
isoMapper = vtk.vtkPolyDataMapper()
isoMapper.SetInput(iso.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)
# 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()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.