Thanks Luca, that is very helpful, it clears up a lot of things for me.  After 
thinking about it I went back to writing a python script rather than a VMTK 
module in order to simplify things for now.  However, I'm now having trouble 
running the vmtkscripts from within python.  Here is the python code:

# -*- coding: utf-8 -*-
#!/usr/bin/env python

import vtk
import sys
import math
import string

from vmtk import pypes
from vmtk import vmtkscripts

print sys.argv[1]+'\n'
print sys.argv[2]+'\n'

getForwardCenterlines = vmtkscripts.vmtkCenterlines()
inputSurfaceName = sys.argv[1]
print 'Input surface filename is '+inputSurfaceName+'\n'
print 'Centerline output filename is 
'+inputSurfaceName[:-4]+'_ForwardCenterlines.vtp\n'
getForwardCenterlines.SurfaceInputFileName = inputSurfaceName
getForwardCenterlines.CenterlinesOutputFileName = 
inputSurfaceName[:-4]+'_ForwardCenterlines.vtp'
getForwardCenterlines.VoronoiDiagramOutputFileName = 
inputSurfaceName[:-4]+'_VoronoiDiagram.vtp'
getForwardCenterlines.ResamplingStepLength = 0.1
print 'FORWARD CENTERLINES:\n\
Source seed: Inflow\n\
First target seed: Aneurysm dome\n\
Second target seed(s): Outflow.'
getForwardCenterlines.Execute()

and here is the terminal output:

d-###### :VMTK Programming$ python bjr_aneurysm_isolation.py 1004.vtp 
1004finished.vtp
1004.vtp

1004finished.vtp

Input surface filename is 1004.vtp

Centerline output filename is 1004_ForwardCenterlines.vtp

FORWARD CENTERLINES:
Source seed: Inflow
First target seed: Aneurysm dome
Second target seed(s): Outflow.
Error: No input surface.



________________________________
From: Luca Antiga [luca.ant...@orobix.com]
Sent: Saturday, January 21, 2012 12:25 PM
To: Berkowitz, Benjamin M
Cc: vmtk-users@lists.sourceforge.net
Subject: Re: [vmtk-users] Script doesn't work

Hi Ben,
 a few hints to get you going

- there's a mix of tabs and spaces in your python file, I suggest you either 
stick with tabs or spaces, otherwise errors could creep in

- there's no need of adding SurfaceInputFileName and SurfaceOutputFileName: 
whenever you add the name of a script after the documentation
like the 'vmtksurfacereader' in the next line
   ['Surface','i','vtkPolyData',1,'','the input surface','vmtksurfacereader'],
pypes automatically adds an -ifile option and uses vmtksurfacereader as a 
default reader. Same thing for the writer.
For the same reason, you can safely delete the last portion of your code:
self.WriteSurface = vmtkscripts.vmtkSurfaceWriter ...
since the output file will automatically be written as soon as you use -ofile 
at the command line.

- whenever you instantiate a script, like

self.BranchClipper = vmtkscripts.vmtkBranchClipper

you have to add '()' at the end, otherwise you're not actually creating an 
instance of the object (look it up on your Python reference, book or 
tutorials), this way

self.BranchClipper = vmtkscripts.vmtkBranchClipper()

- I'm not sure what you wanted to achieve with

for i in self.ExtractedBranches.GroupIdsArrayName:
    if branchString == self.ExtractedBranches.GroupIdsArrayName:
branchString = None
return branchString

 but this is probably not the right way 
(self.ExtractedBranches.GroupIdsArrayName is not a collection, it's a string, 
so iterating over a string will only get you one letter of the string at a time)

- I see you are using 'self' inside a method call for a method that has self as 
the only parameter (def BranchInput(self):)

while self.BranchNumber == None:
    self.BranchNumber = self.BranchInput(self)
    if self.BranchNumber == None:
                     ...

This is not syntactically correct, it should have been
self.BranchInput()

to make the long story short, when you write object methods in Python, the 
first argument to the method (self, but you can actually call it whatever you 
want) represents the object instance on which you're calling that method and 
does not have to be specified in the call, e.g.

class Foo(object):
def add(self, a, b):
return a + b

foo = Foo()
foo.add(1,2)
-> 3

You'll find it in your Python refs.

Hope this helps


Luca



On Jan 20, 2012, at 11:34 PM, Berkowitz, Benjamin M wrote:

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
<isolateaneurysm.py>------------------------------------------------------------------------------
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<mailto:vmtk-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/vmtk-users

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
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-d2d
_______________________________________________
vmtk-users mailing list
vmtk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vmtk-users

Reply via email to