Hi, I've been trying to make a python script that takes in models of vessels
with cerebral aneurysms and will eventually give the user an isolated aneurysm.
Basically, the script is pretty simple and does almost the same thing as
typing these commands into pypepad, but asks the user for the number of the
centerline tract to construct around instead of vmtkcenterlinelabeler:
vmtksurfacereader -ifile surface1.vtp --pipe vmtkcenterlines --pipe
vmtkbranchextractor --pipe vmtkcenterlinelabeler --pipe vmtkbranchclipper
-groupids 2 -ofile surface.vtp --pipe vmtkrenderer --pipe vmtksurfaceviewer
--pipe vmtksurfaceviewer -ifile
/var/tmp/bberkowi/BIOMOST/Coil_Compaction_Growth_Project/Ben_B_auto_aneurysm_cutting/Recur_pt2_pre1L.vtp
-opacity 0.5
It doesn't work, though. I've just started to learn how to program with Python
and PypeS, so I was hoping someone could take a quick look at it and tell me if
I'm on the right track and if you see any glaring errors. I've attached the
file.
Thanks,
Ben Berkowitz
#! /usr/bin/env python
import vtk
import sys
import math
import string
from vmtk import vmtkcenterlines
from vmtk import vmtkcenterlineviewer
from vmtk import vmtkrenderer
from vmtk import pypes
from vmtk import vmtkscripts
isolateaneurysm = 'isolateAneurysm'
class isolateAneurysm(pypes.pypeScript):
def __init__(self):
pypes.pypeScript.__init__(self)
self.Surface = None
self.SurfaceInputFileName
self.AneurysmSurface = None
self.SetScriptName('isolateaneurysm')
self.SetScriptDoc('Slices the aneurysm using a distance threshold from the centerline')
self.SetInputMembers([
['Surface','i','vtkPolyData',1,'','the input surface','vmtksurfacereader'],
['SurfaceInputFileName','ifile','string',1,'','the input surface filename'],
['SurfaceOutputFileName','ofile','string',1,'','the output surface filename']
])
self.SetOutputMembers([
['AneurysmSurface','o','vtkPolyData',1,'','the output surface','vmtksurfacewriter']
])
def BranchInput(self):
branchString = int(self.InputText('Please input aneurysm centerline groupID: '))
for i in self.ExtractedBranches.GroupIdsArrayName:
if branchString == self.ExtractedBranches.GroupIdsArrayName:
branchString = None
return branchString
def Execute(self):
if self.Surface == None:
self.PrintError('Error: No Surface.')
# get centerlines
self.Centerlines = vmtkscripts.vmtkCenterlines
self.Centerlines.Surface = self.Surface
self.Centerlines.Execute()
#split up centerlines
self.ExtractedBranches = vmtkscripts.vmtkBranchExtractor
self.ExtractedBranches.Centerlines = self.Centerlines
self.ExtractedBranches.Execute()
#display centerlines with IDs
groupIdsArray = self.ExtractedBranches.Centerlines.GetCellData().GetArray(self.ExtractedBranches.GroupIdsArrayName)
groupIds = []
for i in range(groupIdsArray.GetNumberOfTuples()):
groupIds.append(int(groupIdsArray.GetComponent(i,0)))
groupIds.sort()
uniqueGroupIds = []
for groupId in groupIds:
if groupId not in uniqueGroupIds:
uniqueGroupIds.append(groupId)
labelMap = {}
viewer = vmtkcenterlineviewer.vmtkCenterlineViewer()
viewer.Centerlines = self.ExtractedBranches.Centerlines
viewer.CellDataArrayName = self.ExtractedBranches.GroupIdsArrayName
viewer.vmtkRenderer = vmtkrenderer.vmtkRenderer()
viewer.Execute()
#isolate surface
self.BranchClipper = vmtkscripts.vmtkBranchClipper
while self.BranchNumber == None:
self.BranchNumber = self.BranchInput(self)
if self.BranchNumber == None:
self.OutputText('Please enter a valid branch ID.')
self.BranchClipper.Centerlines = self.ExtractedBranches.Centerlines
self.BranchClipper.GroupIds = self.BranchNumber
self.BranchClipper.Execute()
#display aneurysm
self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer
self.SurfaceViewer.Surface = self.BranchClipper.Surface
self.SurfaceViewer.Execute()
#save aneurysm surface
self.WriteSurface = vmtkscripts.vmtkSurfaceWriter
self.WriteSurface.Surface = self.BranchClipper.Surface
self.WriteSurface.OutputFileName = self.AneurysmSurface
self.WriteSurface.Execute()
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
vmtk-users mailing list
vmtk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vmtk-users