vmtk 1.5.0__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vmtk/__init__.py +0 -0
- vmtk/pype.py +353 -0
- vmtk/pypebatch.py +111 -0
- vmtk/pypemain.py +116 -0
- vmtk/pypepad.py +608 -0
- vmtk/pyperun.py +49 -0
- vmtk/pypes.py +12 -0
- vmtk/pypescript.py +691 -0
- vmtk/pypeserver.py +87 -0
- vmtk/pypetest.py +92 -0
- vmtk/pypetestrunner.py +202 -0
- vmtk/pypewrapper.py +239 -0
- vmtk/share/vmtkimagevolumeviewerpresets.xml +27 -0
- vmtk/vmtkactivetubes.py +92 -0
- vmtk/vmtkbifurcationprofiles.py +94 -0
- vmtk/vmtkbifurcationreferencesystems.py +77 -0
- vmtk/vmtkbifurcationsections.py +153 -0
- vmtk/vmtkbifurcationvectors.py +120 -0
- vmtk/vmtkboundarylayer.py +127 -0
- vmtk/vmtkboundarylayer2.py +137 -0
- vmtk/vmtkboundaryreferencesystems.py +75 -0
- vmtk/vmtkbranchclipper.py +154 -0
- vmtk/vmtkbranchextractor.py +78 -0
- vmtk/vmtkbranchgeometry.py +96 -0
- vmtk/vmtkbranchmapping.py +128 -0
- vmtk/vmtkbranchmetrics.py +120 -0
- vmtk/vmtkbranchpatching.py +103 -0
- vmtk/vmtkbranchsections.py +117 -0
- vmtk/vmtkcenterlineattributes.py +66 -0
- vmtk/vmtkcenterlinegeometry.py +96 -0
- vmtk/vmtkcenterlineimage.py +118 -0
- vmtk/vmtkcenterlineinterpolation.py +123 -0
- vmtk/vmtkcenterlinelabeler.py +149 -0
- vmtk/vmtkcenterlinemerge.py +80 -0
- vmtk/vmtkcenterlinemeshsections.py +104 -0
- vmtk/vmtkcenterlinemodeller.py +78 -0
- vmtk/vmtkcenterlineoffsetattributes.py +151 -0
- vmtk/vmtkcenterlineresampling.py +62 -0
- vmtk/vmtkcenterlines.py +689 -0
- vmtk/vmtkcenterlinesections.py +87 -0
- vmtk/vmtkcenterlinesmoothing.py +64 -0
- vmtk/vmtkcenterlinesnetwork.py +303 -0
- vmtk/vmtkcenterlinestonumpy.py +114 -0
- vmtk/vmtkcenterlineviewer.py +175 -0
- vmtk/vmtkcontribscripts.py +36 -0
- vmtk/vmtkdelaunayvoronoi.py +256 -0
- vmtk/vmtkdijkstradistancetopoints.py +299 -0
- vmtk/vmtkdistancetocenterlines.py +129 -0
- vmtk/vmtkdistancetospheres.py +365 -0
- vmtk/vmtkendpointextractor.py +85 -0
- vmtk/vmtkendpointsections.py +161 -0
- vmtk/vmtkentityrenumber.py +87 -0
- vmtk/vmtkflowextensions.py +193 -0
- vmtk/vmtkgeodesicsurfaceresolution.py +343 -0
- vmtk/vmtkicpregistration.py +140 -0
- vmtk/vmtkimagebinarize.py +69 -0
- vmtk/vmtkimagecast.py +88 -0
- vmtk/vmtkimagecompare.py +102 -0
- vmtk/vmtkimagecompose.py +84 -0
- vmtk/vmtkimagecurvedmpr.py +84 -0
- vmtk/vmtkimagefeaturecorrection.py +85 -0
- vmtk/vmtkimagefeatures.py +204 -0
- vmtk/vmtkimageinitialization.py +636 -0
- vmtk/vmtkimagemipviewer.py +135 -0
- vmtk/vmtkimagemorphology.py +77 -0
- vmtk/vmtkimagenormalize.py +62 -0
- vmtk/vmtkimageobjectenhancement.py +100 -0
- vmtk/vmtkimageotsuthresholds.py +80 -0
- vmtk/vmtkimagereader.py +318 -0
- vmtk/vmtkimagereslice.py +149 -0
- vmtk/vmtkimageseeder.py +208 -0
- vmtk/vmtkimageshiftscale.py +123 -0
- vmtk/vmtkimagesmoothing.py +124 -0
- vmtk/vmtkimagetonumpy.py +86 -0
- vmtk/vmtkimagevesselenhancement.py +213 -0
- vmtk/vmtkimageviewer.py +184 -0
- vmtk/vmtkimagevoipainter.py +245 -0
- vmtk/vmtkimagevoiselector.py +232 -0
- vmtk/vmtkimagevolumeviewer.py +323 -0
- vmtk/vmtkimagewriter.py +311 -0
- vmtk/vmtklevelsetsegmentation.py +390 -0
- vmtk/vmtklineartoquadratic.py +107 -0
- vmtk/vmtklineresampling.py +68 -0
- vmtk/vmtklocalgeometry.py +182 -0
- vmtk/vmtkmarchingcubes.py +79 -0
- vmtk/vmtkmeshaddexternallayer.py +256 -0
- vmtk/vmtkmesharrayoperation.py +102 -0
- vmtk/vmtkmeshboundaryinspector.py +168 -0
- vmtk/vmtkmeshbranchclipper.py +154 -0
- vmtk/vmtkmeshclipcenterlines.py +649 -0
- vmtk/vmtkmeshclipper.py +161 -0
- vmtk/vmtkmeshcompare.py +152 -0
- vmtk/vmtkmeshconnectivity.py +85 -0
- vmtk/vmtkmeshcutter.py +131 -0
- vmtk/vmtkmeshdatareader.py +351 -0
- vmtk/vmtkmeshextractpointdata.py +83 -0
- vmtk/vmtkmeshgenerator.py +366 -0
- vmtk/vmtkmeshlambda2.py +72 -0
- vmtk/vmtkmeshlinearize.py +60 -0
- vmtk/vmtkmeshmerge.py +73 -0
- vmtk/vmtkmeshmergetimesteps.py +210 -0
- vmtk/vmtkmeshpolyballevaluation.py +82 -0
- vmtk/vmtkmeshprojection.py +65 -0
- vmtk/vmtkmeshreader.py +339 -0
- vmtk/vmtkmeshscaling.py +62 -0
- vmtk/vmtkmeshtetrahedralize.py +60 -0
- vmtk/vmtkmeshtetrahedralize2.py +68 -0
- vmtk/vmtkmeshtonumpy.py +144 -0
- vmtk/vmtkmeshtosurface.py +64 -0
- vmtk/vmtkmeshtransform.py +97 -0
- vmtk/vmtkmeshtransformtoras.py +67 -0
- vmtk/vmtkmeshvectorfromcomponents.py +72 -0
- vmtk/vmtkmeshviewer.py +202 -0
- vmtk/vmtkmeshviewer2.py +293 -0
- vmtk/vmtkmeshvolume.py +69 -0
- vmtk/vmtkmeshvorticityhelicity.py +79 -0
- vmtk/vmtkmeshwallshearrate.py +79 -0
- vmtk/vmtkmeshwriter.py +381 -0
- vmtk/vmtkmeshwriter2.py +361 -0
- vmtk/vmtknetworkeditor.py +893 -0
- vmtk/vmtknetworkextraction.py +81 -0
- vmtk/vmtknetworkwriter.py +249 -0
- vmtk/vmtknumpyreader.py +126 -0
- vmtk/vmtknumpytocenterlines.py +83 -0
- vmtk/vmtknumpytoimage.py +94 -0
- vmtk/vmtknumpytomesh.py +122 -0
- vmtk/vmtknumpytosurface.py +145 -0
- vmtk/vmtknumpywriter.py +155 -0
- vmtk/vmtkparticletracer.py +190 -0
- vmtk/vmtkpathlineanimator.py +268 -0
- vmtk/vmtkpetergeneratesurface.py +259 -0
- vmtk/vmtkpeterresurface.py +232 -0
- vmtk/vmtkpetersurfaceclipper.py +338 -0
- vmtk/vmtkpointsplitextractor.py +88 -0
- vmtk/vmtkpointtransform.py +71 -0
- vmtk/vmtkpolyballmodeller.py +78 -0
- vmtk/vmtkpotentialfit.py +99 -0
- vmtk/vmtkpythonscript.py +69 -0
- vmtk/vmtkrbfinterpolation.py +99 -0
- vmtk/vmtkrenderer.py +376 -0
- vmtk/vmtkrendertoimage.py +61 -0
- vmtk/vmtkscripts.py +158 -0
- vmtk/vmtksurfaceappend.py +58 -0
- vmtk/vmtksurfacearrayoperation.py +104 -0
- vmtk/vmtksurfacearraysmoothing.py +134 -0
- vmtk/vmtksurfacebooleanoperation.py +85 -0
- vmtk/vmtksurfacecapper.py +209 -0
- vmtk/vmtksurfacecelldatatopointdata.py +57 -0
- vmtk/vmtksurfacecenterlineprojection.py +69 -0
- vmtk/vmtksurfacecliploop.py +137 -0
- vmtk/vmtksurfaceclipper.py +213 -0
- vmtk/vmtksurfacecompare.py +146 -0
- vmtk/vmtksurfaceconnectivity.py +111 -0
- vmtk/vmtksurfaceconnectivityselector.py +231 -0
- vmtk/vmtksurfacecurvature.py +153 -0
- vmtk/vmtksurfacedecimation.py +76 -0
- vmtk/vmtksurfacedistance.py +93 -0
- vmtk/vmtksurfaceendclipper.py +350 -0
- vmtk/vmtksurfaceextractannularwalls.py +135 -0
- vmtk/vmtksurfaceextractinnercylinder.py +128 -0
- vmtk/vmtksurfacekiteremoval.py +60 -0
- vmtk/vmtksurfaceloopextraction.py +147 -0
- vmtk/vmtksurfacemassproperties.py +72 -0
- vmtk/vmtksurfacemodeller.py +69 -0
- vmtk/vmtksurfacenormals.py +85 -0
- vmtk/vmtksurfacepointdatatocelldata.py +57 -0
- vmtk/vmtksurfacepolyballevaluation.py +82 -0
- vmtk/vmtksurfaceprojection.py +62 -0
- vmtk/vmtksurfacereader.py +252 -0
- vmtk/vmtksurfacereferencesystemtransform.py +140 -0
- vmtk/vmtksurfaceregiondrawing.py +175 -0
- vmtk/vmtksurfaceremeshing.py +154 -0
- vmtk/vmtksurfaceresolution.py +335 -0
- vmtk/vmtksurfacescaling.py +72 -0
- vmtk/vmtksurfacesmoothing.py +92 -0
- vmtk/vmtksurfacesubdivision.py +70 -0
- vmtk/vmtksurfacetobinaryimage.py +122 -0
- vmtk/vmtksurfacetomesh.py +65 -0
- vmtk/vmtksurfacetonumpy.py +126 -0
- vmtk/vmtksurfacetransform.py +97 -0
- vmtk/vmtksurfacetransforminteractive.py +194 -0
- vmtk/vmtksurfacetransformtoras.py +72 -0
- vmtk/vmtksurfacetriangle.py +60 -0
- vmtk/vmtksurfaceviewer.py +362 -0
- vmtk/vmtksurfacewriter.py +276 -0
- vmtk/vmtksurfacewriter2.py +227 -0
- vmtk/vmtksurfmesh.py +59 -0
- vmtk/vmtktetgen.py +158 -0
- vmtk/vmtktetringenerator.py +687 -0
- vmtk/vmtkthreshold.py +73 -0
- vmtk/vtkvmtk.py +23 -0
- vmtk/vtkvmtkCommon.dll +0 -0
- vmtk/vtkvmtkCommonPython.pyd +0 -0
- vmtk/vtkvmtkComputationalGeometry.dll +0 -0
- vmtk/vtkvmtkComputationalGeometryPython.pyd +0 -0
- vmtk/vtkvmtkContrib.dll +0 -0
- vmtk/vtkvmtkContribPython.pyd +0 -0
- vmtk/vtkvmtkDifferentialGeometry.dll +0 -0
- vmtk/vtkvmtkDifferentialGeometryPython.pyd +0 -0
- vmtk/vtkvmtkIO.dll +0 -0
- vmtk/vtkvmtkIOPython.pyd +0 -0
- vmtk/vtkvmtkITK.dll +0 -0
- vmtk/vtkvmtkITKPython.pyd +0 -0
- vmtk/vtkvmtkMisc.dll +0 -0
- vmtk/vtkvmtkMiscPython.pyd +0 -0
- vmtk/vtkvmtkRendering.dll +0 -0
- vmtk/vtkvmtkRenderingPython.pyd +0 -0
- vmtk/vtkvmtkSegmentation.dll +0 -0
- vmtk/vtkvmtkSegmentationPython.pyd +0 -0
- vmtk-1.5.0.dist-info/METADATA +308 -0
- vmtk-1.5.0.dist-info/RECORD +215 -0
- vmtk-1.5.0.dist-info/WHEEL +5 -0
- vmtk-1.5.0.dist-info/entry_points.txt +2 -0
- vmtk-1.5.0.dist-info/licenses/LICENSE +867 -0
- vmtk-1.5.0.dist-info/top_level.txt +1 -0
vmtk/__init__.py
ADDED
|
File without changes
|
vmtk/pype.py
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
## Program: PypeS
|
|
4
|
+
## Module: $RCSfile: pype.py,v $
|
|
5
|
+
## Language: Python
|
|
6
|
+
## Date: $Date: 2006/07/07 10:45:42 $
|
|
7
|
+
## Version: $Revision: 1.18 $
|
|
8
|
+
|
|
9
|
+
## Copyright (c) Luca Antiga, David Steinman. All rights reserved.
|
|
10
|
+
## See LICENSE file for details.
|
|
11
|
+
|
|
12
|
+
## This software is distributed WITHOUT ANY WARRANTY; without even
|
|
13
|
+
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
14
|
+
## PURPOSE. See the above copyright notices for more information.
|
|
15
|
+
|
|
16
|
+
from __future__ import absolute_import # NEEDS TO STAY AS TOP LEVEL IMPORT
|
|
17
|
+
import sys
|
|
18
|
+
import os
|
|
19
|
+
import importlib
|
|
20
|
+
from inspect import isclass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
pype = 'Pype'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class NullOutputStream(object):
|
|
27
|
+
|
|
28
|
+
def __init__(self):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
def write(self,text):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
def flush(self):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Pype(object):
|
|
39
|
+
'''
|
|
40
|
+
Orchestrates the interaction among PypeScripts.
|
|
41
|
+
|
|
42
|
+
It enables one to pipe one PypeScript after another, and it takes care
|
|
43
|
+
of connecting the right arguments from one script to the other. It can
|
|
44
|
+
be called from the command line by issuing pype pype-arguments or
|
|
45
|
+
automatically instantiated from a pypescript.
|
|
46
|
+
|
|
47
|
+
Attributes:
|
|
48
|
+
ScriptObjectList (list):
|
|
49
|
+
ScriptList (list):
|
|
50
|
+
AutoPipe (bool):
|
|
51
|
+
LogOn (bool):
|
|
52
|
+
ScriptName (str):
|
|
53
|
+
ExitOnError (bool)
|
|
54
|
+
InputStream (function):
|
|
55
|
+
OutputStream (function)
|
|
56
|
+
Arguments (string):
|
|
57
|
+
'''
|
|
58
|
+
|
|
59
|
+
def __init__(self):
|
|
60
|
+
self.ScriptObjectList = []
|
|
61
|
+
self.ScriptList = []
|
|
62
|
+
self.AutoPipe = 1
|
|
63
|
+
self.LogOn = 1
|
|
64
|
+
self.ScriptName = 'pype'
|
|
65
|
+
self.ExitOnError = 1
|
|
66
|
+
self.InputStream = sys.stdin
|
|
67
|
+
self.OutputStream = sys.stdout
|
|
68
|
+
self.Arguments = None
|
|
69
|
+
|
|
70
|
+
def GetUsageString(self):
|
|
71
|
+
usageString = 'Usage: pype --nolog --noauto --query firstScriptName -scriptOptionName scriptOptionValue --pipe secondScriptName -scriptOptionName scriptOptionValue -scriptOptionName @firstScriptName.scriptOptionName -id 2 --pipe thirdScriptName -scriptOptionName @secondScriptName-2.scriptOptionName'
|
|
72
|
+
return usageString
|
|
73
|
+
|
|
74
|
+
def SetOutputStreamToNull(self):
|
|
75
|
+
self.OutputStream = NullOutputStream()
|
|
76
|
+
|
|
77
|
+
def PrintLog(self,logMessage,indent=0):
|
|
78
|
+
'''Prints log messages from pypescript members to the console.
|
|
79
|
+
|
|
80
|
+
All vmtkscripts subclassing from pypes.Pype use the PrintLog method in order
|
|
81
|
+
to write their output to the console.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
logMessage (str): the message to be logged
|
|
85
|
+
indent (int): number of spaces to intent the message. Defaults to 0.
|
|
86
|
+
'''
|
|
87
|
+
if not self.LogOn:
|
|
88
|
+
return
|
|
89
|
+
indentUnit = ' '
|
|
90
|
+
indentation = ''
|
|
91
|
+
for i in range(indent):
|
|
92
|
+
indentation = indentation + indentUnit
|
|
93
|
+
self.OutputStream.write(indentation + logMessage + '\n')
|
|
94
|
+
|
|
95
|
+
def PrintError(self,errorMessage):
|
|
96
|
+
''' Prints error messages from pypescript members to the console then raises a runtime error.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
errorMessage (string): the error message to print to the console
|
|
100
|
+
'''
|
|
101
|
+
self.OutputStream.write(errorMessage + '\n')
|
|
102
|
+
raise RuntimeError(errorMessage)
|
|
103
|
+
|
|
104
|
+
def SetArgumentsString(self,argumentsString):
|
|
105
|
+
''' Splits an input string into a list containing the class name and arguments.
|
|
106
|
+
|
|
107
|
+
sets the class attribute "Arguments".
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
argumentsString (string): the input argument string
|
|
111
|
+
'''
|
|
112
|
+
if '"' not in argumentsString:
|
|
113
|
+
self.Arguments = argumentsString.split()
|
|
114
|
+
import re
|
|
115
|
+
quoteRe = re.compile('(\".*?\")')
|
|
116
|
+
splitArguments = quoteRe.split(argumentsString)
|
|
117
|
+
arguments = []
|
|
118
|
+
for splitArgument in splitArguments:
|
|
119
|
+
arg = splitArgument
|
|
120
|
+
if splitArgument.startswith('"') and splitArgument.endswith('"'):
|
|
121
|
+
arg = splitArgument[1:-1]
|
|
122
|
+
arguments.append(arg)
|
|
123
|
+
else:
|
|
124
|
+
arguments.extend(arg.strip().split())
|
|
125
|
+
if '"' in arg:
|
|
126
|
+
self.PrintError('Error: non-matching quote found')
|
|
127
|
+
self.Arguments = arguments
|
|
128
|
+
|
|
129
|
+
def ParseArguments(self):
|
|
130
|
+
self.ScriptList = []
|
|
131
|
+
arguments = self.Arguments[:]
|
|
132
|
+
if os.path.basename(arguments[0]).strip() in ['pyperun']:
|
|
133
|
+
arguments.remove(arguments[0])
|
|
134
|
+
pypeArguments = []
|
|
135
|
+
for arg in arguments:
|
|
136
|
+
if arg[:2] == '--':
|
|
137
|
+
pypeArguments.append(arg)
|
|
138
|
+
else:
|
|
139
|
+
break
|
|
140
|
+
if '--help' in pypeArguments:
|
|
141
|
+
self.PrintLog(self.GetUsageString())
|
|
142
|
+
return
|
|
143
|
+
if '--noauto' in pypeArguments:
|
|
144
|
+
self.AutoPipe = 0
|
|
145
|
+
if '--nolog' in pypeArguments:
|
|
146
|
+
self.LogOn = 0
|
|
147
|
+
if '--query' in pypeArguments:
|
|
148
|
+
queryScripts = arguments[arguments.index('--query')+1:]
|
|
149
|
+
for queryScript in queryScripts:
|
|
150
|
+
exec('from vmtk import '+queryScript)
|
|
151
|
+
exec('allScripts = '+queryScript+'.__all__')
|
|
152
|
+
self.PrintLog('\n'.join(allScripts))
|
|
153
|
+
return
|
|
154
|
+
for arg in pypeArguments:
|
|
155
|
+
arguments.remove(arg)
|
|
156
|
+
if 'FILE' in arguments:
|
|
157
|
+
text = ''
|
|
158
|
+
self.OutputStream.write('\nThe current pype contains filename placeholders identified by the string FILE.')
|
|
159
|
+
self.OutputStream.write('\nEvery occcurence of FILE is meant to be replaced with an actual file path.\n')
|
|
160
|
+
self.OutputStream.write('\nPress \'c\' to continue and be automathically prompted for the required filenames.')
|
|
161
|
+
self.OutputStream.write('\nPress \'e\' to exit. You can still edit your pype manually and run it back.\n\n')
|
|
162
|
+
while text not in ['c','e']:
|
|
163
|
+
self.OutputStream.write('> ')
|
|
164
|
+
text = self.InputStream.readline().rstrip('\n')
|
|
165
|
+
if text == 'e':
|
|
166
|
+
return
|
|
167
|
+
elif text =='c':
|
|
168
|
+
while 'FILE' in arguments:
|
|
169
|
+
arguments[arguments.index('FILE')] = 'BROWSER'
|
|
170
|
+
while '--pipe' in arguments:
|
|
171
|
+
scriptSlice = arguments[:arguments.index('--pipe')]
|
|
172
|
+
self.ScriptList.append([os.path.splitext(os.path.split(scriptSlice[0])[1])[0],scriptSlice[1:]])
|
|
173
|
+
arguments = arguments[arguments.index('--pipe')+1:]
|
|
174
|
+
scriptSlice = arguments[:]
|
|
175
|
+
if not arguments:
|
|
176
|
+
return
|
|
177
|
+
self.ScriptList.append([os.path.splitext(os.path.split(scriptSlice[0])[1])[0],scriptSlice[1:]])
|
|
178
|
+
|
|
179
|
+
def GetCompatibleMember(self,member,script):
|
|
180
|
+
pushedInputMembers = [scriptMember for scriptMember in script.InputMembers if scriptMember.Pushed]
|
|
181
|
+
compatibleOutputMembers = [scriptMember for scriptMember in pushedInputMembers + script.OutputMembers if scriptMember.AutoPipe and (scriptMember.MemberName == member.MemberName) and (scriptMember.MemberType == member.MemberType)]
|
|
182
|
+
if not compatibleOutputMembers:
|
|
183
|
+
return None
|
|
184
|
+
return compatibleOutputMembers[0]
|
|
185
|
+
|
|
186
|
+
def AutoPipeScriptObject(self,scriptObject):
|
|
187
|
+
self.PrintLog('Automatic piping ' + scriptObject.ScriptName)
|
|
188
|
+
for memberEntry in scriptObject.InputMembers:
|
|
189
|
+
if not memberEntry.AutoPipe:
|
|
190
|
+
continue
|
|
191
|
+
if memberEntry.MemberType == 'id':
|
|
192
|
+
continue
|
|
193
|
+
if memberEntry.MemberType == 'handle':
|
|
194
|
+
continue
|
|
195
|
+
|
|
196
|
+
candidateScriptObjectList = [candidateScriptObject for candidateScriptObject in self.ScriptObjectList if self.GetCompatibleMember(memberEntry,candidateScriptObject)]
|
|
197
|
+
if not candidateScriptObjectList:
|
|
198
|
+
continue
|
|
199
|
+
pipedScriptObject = candidateScriptObjectList[-1]
|
|
200
|
+
pipedMember = self.GetCompatibleMember(memberEntry,pipedScriptObject)
|
|
201
|
+
# Creates a memberpipe name of the following format
|
|
202
|
+
# Image = vmtkimagereader-0.Image
|
|
203
|
+
memberEntry.MemberPipe = pipedScriptObject.ScriptName + '-' + str(pipedScriptObject.Id) + '.' + pipedMember.MemberName
|
|
204
|
+
self.PrintLog(memberEntry.MemberName + ' = ' + memberEntry.MemberPipe,1)
|
|
205
|
+
|
|
206
|
+
def GetScriptObject(self,scriptName,scriptId):
|
|
207
|
+
for scriptObject in self.ScriptObjectList:
|
|
208
|
+
if (scriptObject.ScriptName == scriptName) & (scriptObject.Id == scriptId):
|
|
209
|
+
return scriptObject
|
|
210
|
+
|
|
211
|
+
def ExplicitPipeScriptObject(self,scriptObject):
|
|
212
|
+
self.PrintLog('Explicit piping ' + scriptObject.ScriptName)
|
|
213
|
+
for memberEntry in scriptObject.InputMembers:
|
|
214
|
+
memberName = memberEntry.MemberName
|
|
215
|
+
option = memberEntry.OptionName
|
|
216
|
+
memberType = memberEntry.MemberType
|
|
217
|
+
if memberEntry.ExplicitPipe == 'None':
|
|
218
|
+
memberEntry.MemberPipe = None
|
|
219
|
+
exec ('scriptObject.'+memberEntry.MemberName+'= None')
|
|
220
|
+
continue
|
|
221
|
+
if memberEntry.ExplicitPipe:
|
|
222
|
+
pipedArgument = memberEntry.ExplicitPipe
|
|
223
|
+
splitPipedArgument = pipedArgument.split('.')
|
|
224
|
+
if (len(splitPipedArgument)<2):
|
|
225
|
+
self.PrintError('Error: invalid option piping: '+pipedArgument)
|
|
226
|
+
upstreamPipedModuleName = splitPipedArgument[0]
|
|
227
|
+
if not upstreamPipedModuleName:
|
|
228
|
+
upstreamPipedModuleName = self.ScriptObjectList[-1].ScriptName
|
|
229
|
+
upstreamPipedOption = ''
|
|
230
|
+
if (len(splitPipedArgument) == 2):
|
|
231
|
+
upstreamPipedOption = splitPipedArgument[1]
|
|
232
|
+
else:
|
|
233
|
+
self.PrintError('Error: invalid option piping: '+pipedArgument)
|
|
234
|
+
|
|
235
|
+
upstreamPipedId = ''
|
|
236
|
+
splitUpstreamPipedModuleName = upstreamPipedModuleName.split('-')
|
|
237
|
+
if (len(splitUpstreamPipedModuleName) > 1):
|
|
238
|
+
upstreamPipedModuleName = splitUpstreamPipedModuleName[-2]
|
|
239
|
+
upstreamPipedId = splitUpstreamPipedModuleName[-1]
|
|
240
|
+
|
|
241
|
+
if not upstreamPipedOption:
|
|
242
|
+
self.PrintError('Error: invalid option piping: '+pipedArgument)
|
|
243
|
+
|
|
244
|
+
candidateScriptObjectList = []
|
|
245
|
+
|
|
246
|
+
if upstreamPipedModuleName:
|
|
247
|
+
candidateScriptObjectList = [candidateScriptObject for candidateScriptObject in self.ScriptObjectList if candidateScriptObject.ScriptName == upstreamPipedModuleName]
|
|
248
|
+
if upstreamPipedId:
|
|
249
|
+
candidateScriptObjectList = [candidateScriptObject for candidateScriptObject in candidateScriptObjectList if upstreamPipedId == candidateScriptObject.Id]
|
|
250
|
+
|
|
251
|
+
if not candidateScriptObjectList:
|
|
252
|
+
self.PrintError('Error: invalid option piping: '+pipedArgument)
|
|
253
|
+
continue
|
|
254
|
+
|
|
255
|
+
pipedScriptObject = candidateScriptObjectList[-1]
|
|
256
|
+
|
|
257
|
+
candidatePipedMembers = [member for member in pipedScriptObject.OutputMembers + pipedScriptObject.InputMembers if upstreamPipedOption == member.OptionName]
|
|
258
|
+
|
|
259
|
+
if not candidatePipedMembers:
|
|
260
|
+
self.PrintError('Error: invalid option piping: '+pipedArgument)
|
|
261
|
+
continue
|
|
262
|
+
|
|
263
|
+
pipedMember = candidatePipedMembers[0]
|
|
264
|
+
|
|
265
|
+
memberEntry.MemberPipe = pipedScriptObject.ScriptName + '-' + str(pipedScriptObject.Id) + '.' + pipedMember.MemberName
|
|
266
|
+
self.PrintLog(memberName+' = '+memberEntry.MemberPipe,1)
|
|
267
|
+
|
|
268
|
+
def PipeScriptObject(self,scriptObject):
|
|
269
|
+
for memberEntry in [member for member in scriptObject.InputMembers if member.MemberPipe and not member.MemberValue]:
|
|
270
|
+
pipedScriptName = memberEntry.MemberPipe.split('.')[0].split('-')[0]
|
|
271
|
+
pipedScriptId = memberEntry.MemberPipe.split('.')[0].split('-')[1]
|
|
272
|
+
pipedMemberName = memberEntry.MemberPipe.split('.')[1]
|
|
273
|
+
previousScriptObjects = self.ScriptObjectList[:]
|
|
274
|
+
if scriptObject in previousScriptObjects:
|
|
275
|
+
previousScriptObjects = previousScriptObjects[:previousScriptObjects.index(scriptObject)]
|
|
276
|
+
candidatePipedScriptObjects = [candidateScriptObject for candidateScriptObject in previousScriptObjects if (candidateScriptObject.ScriptName == pipedScriptName) and (candidateScriptObject.Id == pipedScriptId)]
|
|
277
|
+
pipedScriptObject = candidatePipedScriptObjects[-1]
|
|
278
|
+
exec ('scriptObject.'+memberEntry.MemberName+'='+'pipedScriptObject.'+pipedMemberName)
|
|
279
|
+
|
|
280
|
+
def Execute(self):
|
|
281
|
+
try:
|
|
282
|
+
from vmtk import pypes
|
|
283
|
+
except ImportError:
|
|
284
|
+
return None
|
|
285
|
+
self.ScriptObjectList = []
|
|
286
|
+
for scriptNameAndArguments in self.ScriptList:
|
|
287
|
+
self.PrintLog('')
|
|
288
|
+
scriptName = scriptNameAndArguments[0]
|
|
289
|
+
try:
|
|
290
|
+
module = importlib.import_module('vmtk.'+scriptName)
|
|
291
|
+
# Find the principle class to instantiate the requested action defined inside the requested writerModule script.
|
|
292
|
+
# Returns a single member list (containing the principle class name) which satisfies the following criteria:
|
|
293
|
+
# 1) is a class defined within the script
|
|
294
|
+
# 2) the class is a subclass of pypes.pypescript
|
|
295
|
+
scriptObjectClasses = [x for x in dir(module) if isclass(getattr(module, x)) and issubclass(getattr(module, x), pypes.pypeScript)]
|
|
296
|
+
scriptObjectClassName = scriptObjectClasses[0]
|
|
297
|
+
except ImportError as e:
|
|
298
|
+
self.PrintError(str(e))
|
|
299
|
+
break
|
|
300
|
+
scriptObject = getattr(module, scriptObjectClassName)
|
|
301
|
+
scriptObject = scriptObject()
|
|
302
|
+
scriptArguments = scriptNameAndArguments[1]
|
|
303
|
+
scriptObject.Arguments = scriptArguments
|
|
304
|
+
scriptObject.LogOn = self.LogOn
|
|
305
|
+
if self.InputStream:
|
|
306
|
+
scriptObject.InputStream = self.InputStream
|
|
307
|
+
if self.OutputStream:
|
|
308
|
+
scriptObject.OutputStream = self.OutputStream
|
|
309
|
+
scriptObject.ExitOnError = self.ExitOnError
|
|
310
|
+
if self.AutoPipe:
|
|
311
|
+
self.AutoPipeScriptObject(scriptObject)
|
|
312
|
+
self.PrintLog('Parsing options ' + scriptObject.ScriptName)
|
|
313
|
+
execute = scriptObject.ParseArguments()
|
|
314
|
+
if not execute:
|
|
315
|
+
return
|
|
316
|
+
if scriptObject.Disabled:
|
|
317
|
+
self.PrintLog('\n' + scriptObject.ScriptName + ' is disabled. Bypassing it.')
|
|
318
|
+
continue
|
|
319
|
+
self.ExplicitPipeScriptObject(scriptObject)
|
|
320
|
+
self.PipeScriptObject(scriptObject)
|
|
321
|
+
scriptObject.PrintInputMembers()
|
|
322
|
+
scriptObject.IORead()
|
|
323
|
+
self.PrintLog('Executing ' + scriptObject.ScriptName + ' ...')
|
|
324
|
+
scriptObject.Execute()
|
|
325
|
+
self.PrintLog('Done executing ' + scriptObject.ScriptName + '.')
|
|
326
|
+
scriptObject.IOWrite()
|
|
327
|
+
scriptObject.PrintOutputMembers()
|
|
328
|
+
self.ScriptObjectList.append(scriptObject)
|
|
329
|
+
|
|
330
|
+
for scriptObject in self.ScriptObjectList:
|
|
331
|
+
scriptObject.Deallocate()
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def PypeRun(arguments):
|
|
335
|
+
|
|
336
|
+
pipe = Pype()
|
|
337
|
+
pipe.ExitOnError = 0
|
|
338
|
+
pipe.SetArgumentsString(arguments)
|
|
339
|
+
pipe.ParseArguments()
|
|
340
|
+
pipe.Execute()
|
|
341
|
+
return pipe
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
if __name__=='__main__':
|
|
345
|
+
from vmtk import pypes
|
|
346
|
+
main = pypes.pypeMain()
|
|
347
|
+
main.Arguments = sys.argv
|
|
348
|
+
main.Execute()
|
|
349
|
+
|
|
350
|
+
# pipe = Pype()
|
|
351
|
+
# pipe.Arguments = sys.argv
|
|
352
|
+
# pipe.ParseArguments()
|
|
353
|
+
# pipe.Execute()
|
vmtk/pypebatch.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!${PYTHON_SHEBANG}
|
|
2
|
+
|
|
3
|
+
## Program: PypeS
|
|
4
|
+
## Module: $RCSfile: pypebatch.py,v $
|
|
5
|
+
## Language: Python
|
|
6
|
+
## Date: $Date: 2005/09/14 09:47:30 $
|
|
7
|
+
## Version: $Revision: 1.4 $
|
|
8
|
+
|
|
9
|
+
## Copyright (c) Luca Antiga, David Steinman. All rights reserved.
|
|
10
|
+
## See LICENSE file for details.
|
|
11
|
+
|
|
12
|
+
## This software is distributed WITHOUT ANY WARRANTY; without even
|
|
13
|
+
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
14
|
+
## PURPOSE. See the above copyright notices for more information.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
from __future__ import print_function, absolute_import # NEED TO STAY AS TOP IMPORT
|
|
18
|
+
import sys
|
|
19
|
+
import os
|
|
20
|
+
import os.path
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class pypeBatch(object):
|
|
24
|
+
|
|
25
|
+
def __init__(self):
|
|
26
|
+
self.Arguments = []
|
|
27
|
+
|
|
28
|
+
self.Directory = '.'
|
|
29
|
+
self.ScriptName = ''
|
|
30
|
+
self.ScriptArguments = []
|
|
31
|
+
|
|
32
|
+
def GetUsageString(self):
|
|
33
|
+
usageString = 'Usage: pypebatch -d directory scriptName scriptArguments ["pythonStringMethods"]'
|
|
34
|
+
return usageString
|
|
35
|
+
|
|
36
|
+
def PrintLog(self,logMessage,indent=0):
|
|
37
|
+
indentUnit = ' '
|
|
38
|
+
indentation = ''
|
|
39
|
+
for i in range(indent):
|
|
40
|
+
indentation = indentation + indentUnit
|
|
41
|
+
print(indentation + logMessage)
|
|
42
|
+
|
|
43
|
+
def PrintError(self,logMessage):
|
|
44
|
+
print(logMessage)
|
|
45
|
+
|
|
46
|
+
def ParseArguments(self):
|
|
47
|
+
state = 0
|
|
48
|
+
for arg in self.Arguments:
|
|
49
|
+
if (arg == '--help'):
|
|
50
|
+
self.PrintLog(self.GetUsageString())
|
|
51
|
+
sys.exit()
|
|
52
|
+
elif (arg == '-d'):
|
|
53
|
+
state = 1
|
|
54
|
+
elif (state == 1):
|
|
55
|
+
self.Directory = arg
|
|
56
|
+
state = 2
|
|
57
|
+
elif (state == 0):
|
|
58
|
+
state == 2
|
|
59
|
+
elif (state == 2):
|
|
60
|
+
if (self.ScriptName == ''):
|
|
61
|
+
self.ScriptName = arg
|
|
62
|
+
self.ScriptArguments.append(arg)
|
|
63
|
+
|
|
64
|
+
def ReplaceFileNamesInScriptArguments(self,fileName):
|
|
65
|
+
actualScriptArguments = []
|
|
66
|
+
for arg in self.ScriptArguments:
|
|
67
|
+
if not ((arg[0]=='[') & (arg[-1]==']')):
|
|
68
|
+
actualScriptArguments.append(arg)
|
|
69
|
+
continue
|
|
70
|
+
pattern = arg[1:-1]
|
|
71
|
+
actualArgument = self.Directory + '/'
|
|
72
|
+
if (pattern != ''):
|
|
73
|
+
## exec('actualArgument += fileName.' + pattern)
|
|
74
|
+
actualArgument += fileName.__getattribute__(pattern)
|
|
75
|
+
else:
|
|
76
|
+
actualArgument += fileName
|
|
77
|
+
actualScriptArguments.append(actualArgument)
|
|
78
|
+
return actualScriptArguments
|
|
79
|
+
|
|
80
|
+
def Execute(self):
|
|
81
|
+
self.PrintLog('')
|
|
82
|
+
moduleName = self.ScriptName
|
|
83
|
+
exec('from vmtk import '+ moduleName)
|
|
84
|
+
scriptObjectClassName = ''
|
|
85
|
+
exec ('scriptObjectClassName = '+moduleName+'.'+moduleName)
|
|
86
|
+
moduleScriptObjectClassName = moduleName+'.'+scriptObjectClassName
|
|
87
|
+
scriptObject = 0
|
|
88
|
+
|
|
89
|
+
fileNames = os.listdir(self.Directory)
|
|
90
|
+
|
|
91
|
+
for fileName in fileNames:
|
|
92
|
+
|
|
93
|
+
self.PrintLog('Creating ' + scriptObjectClassName + ' instance.')
|
|
94
|
+
exec ('scriptObject = '+moduleScriptObjectClassName+'()')
|
|
95
|
+
completeFileName = os.path.normpath(self.Directory + '/' + fileName)
|
|
96
|
+
self.PrintLog('Replacing FileNames in ' + scriptObject.ScriptName + ' arguments')
|
|
97
|
+
actualScriptArguments = self.ReplaceFileNamesInScriptArguments(fileName)
|
|
98
|
+
scriptObject.Arguments = actualScriptArguments
|
|
99
|
+
scriptObject.ParseArguments()
|
|
100
|
+
scriptString = ''
|
|
101
|
+
for arg in actualScriptArguments:
|
|
102
|
+
scriptString += arg + ' '
|
|
103
|
+
self.PrintLog('Executing ' + scriptString)
|
|
104
|
+
scriptObject.Execute()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if __name__=='__main__':
|
|
108
|
+
batch = pypeBatch()
|
|
109
|
+
batch.Arguments = sys.argv
|
|
110
|
+
batch.ParseArguments()
|
|
111
|
+
batch.Execute()
|
vmtk/pypemain.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
## Program: PypeS
|
|
4
|
+
## Module: pypemain.py
|
|
5
|
+
## Language: Python
|
|
6
|
+
|
|
7
|
+
## Copyright (c) Luca Antiga, David Steinman. All rights reserved.
|
|
8
|
+
## See LICENSE file for details.
|
|
9
|
+
|
|
10
|
+
## This software is distributed WITHOUT ANY WARRANTY; without even
|
|
11
|
+
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
12
|
+
## PURPOSE. See the above copyright notices for more information.
|
|
13
|
+
|
|
14
|
+
"""Entry point for the "vmtk" command installed by the PyPI package.
|
|
15
|
+
|
|
16
|
+
This provides the same behavior as the vmtk launcher script at the root of
|
|
17
|
+
the source tree (vmtk.py), as an importable function that can be declared
|
|
18
|
+
as a console_scripts entry point in setup.py:
|
|
19
|
+
|
|
20
|
+
vmtk <pype> execute a pype (e.g. "vmtk vmtkimageviewer -ifile image.vti")
|
|
21
|
+
vmtk --file FILE execute the pypes listed in FILE
|
|
22
|
+
vmtk [--ui pad] start the interactive PypePad user interface
|
|
23
|
+
vmtk --ui console start an interactive console
|
|
24
|
+
vmtk --help print usage information
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import print_function, absolute_import
|
|
28
|
+
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def main():
|
|
33
|
+
from vmtk import pypes
|
|
34
|
+
|
|
35
|
+
vmtkOptions = ['--help', '--ui', '--file']
|
|
36
|
+
|
|
37
|
+
if len(sys.argv) > 1 and sys.argv[1] not in vmtkOptions:
|
|
38
|
+
arguments = sys.argv[1:]
|
|
39
|
+
print("Executing", ' '.join(arguments))
|
|
40
|
+
pipe = pypes.Pype()
|
|
41
|
+
pipe.ExitOnError = 0
|
|
42
|
+
pipe.Arguments = arguments
|
|
43
|
+
pipe.ParseArguments()
|
|
44
|
+
pipe.Execute()
|
|
45
|
+
return 0
|
|
46
|
+
|
|
47
|
+
if len(sys.argv) > 1 and '--file' in sys.argv:
|
|
48
|
+
fileindex = sys.argv.index('--file') + 1
|
|
49
|
+
if fileindex < len(sys.argv):
|
|
50
|
+
with open(sys.argv[fileindex], 'r') as inputfile:
|
|
51
|
+
physicalLines = [line for line in inputfile.readlines()
|
|
52
|
+
if line and line.strip() and line.strip()[0] != '#']
|
|
53
|
+
lines = []
|
|
54
|
+
for line in physicalLines:
|
|
55
|
+
if lines and lines[-1].endswith('\\\n'):
|
|
56
|
+
lines[-1] = lines[-1][:-2] + line
|
|
57
|
+
else:
|
|
58
|
+
lines.append(line)
|
|
59
|
+
for line in lines:
|
|
60
|
+
pipe = pypes.Pype()
|
|
61
|
+
pipe.ExitOnError = 0
|
|
62
|
+
pipe.Arguments = line.split()
|
|
63
|
+
pipe.ParseArguments()
|
|
64
|
+
pipe.Execute()
|
|
65
|
+
return 0
|
|
66
|
+
|
|
67
|
+
if '--help' in sys.argv:
|
|
68
|
+
print('Usage: \tvmtk [--ui pad|console]\t\tStart in interactive mode'
|
|
69
|
+
'\n\tvmtk [PYPE]\t\t\tExecute the pype [PYPE]'
|
|
70
|
+
'\n\tvmtk --file [FILE]\t\tExecute the content of file [FILE]')
|
|
71
|
+
return 0
|
|
72
|
+
|
|
73
|
+
ui = 'pad'
|
|
74
|
+
if '--ui' in sys.argv and sys.argv.index('--ui') != len(sys.argv) - 1:
|
|
75
|
+
ui = sys.argv[sys.argv.index('--ui') + 1]
|
|
76
|
+
|
|
77
|
+
if ui == 'pad':
|
|
78
|
+
try:
|
|
79
|
+
from vmtk import pypepad
|
|
80
|
+
except ImportError:
|
|
81
|
+
print("error")
|
|
82
|
+
ui = 'console'
|
|
83
|
+
else:
|
|
84
|
+
pypepad.RunPypeTkPad()
|
|
85
|
+
|
|
86
|
+
if ui == 'console':
|
|
87
|
+
try:
|
|
88
|
+
import readline
|
|
89
|
+
except ImportError:
|
|
90
|
+
pass
|
|
91
|
+
else:
|
|
92
|
+
readline.parse_and_bind("tab: complete")
|
|
93
|
+
|
|
94
|
+
while 1:
|
|
95
|
+
try:
|
|
96
|
+
inputString = input("vmtk> ")
|
|
97
|
+
except EOFError:
|
|
98
|
+
sys.stdout.write('\n')
|
|
99
|
+
return 0
|
|
100
|
+
if not inputString:
|
|
101
|
+
continue
|
|
102
|
+
print("Executing", inputString)
|
|
103
|
+
pipe = pypes.Pype()
|
|
104
|
+
pipe.ExitOnError = 0
|
|
105
|
+
pipe.Arguments = inputString.split()
|
|
106
|
+
pipe.ParseArguments()
|
|
107
|
+
try:
|
|
108
|
+
pipe.Execute()
|
|
109
|
+
except Exception:
|
|
110
|
+
continue
|
|
111
|
+
|
|
112
|
+
return 0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if __name__ == '__main__':
|
|
116
|
+
sys.exit(main())
|