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.
Files changed (215) hide show
  1. vmtk/__init__.py +0 -0
  2. vmtk/pype.py +353 -0
  3. vmtk/pypebatch.py +111 -0
  4. vmtk/pypemain.py +116 -0
  5. vmtk/pypepad.py +608 -0
  6. vmtk/pyperun.py +49 -0
  7. vmtk/pypes.py +12 -0
  8. vmtk/pypescript.py +691 -0
  9. vmtk/pypeserver.py +87 -0
  10. vmtk/pypetest.py +92 -0
  11. vmtk/pypetestrunner.py +202 -0
  12. vmtk/pypewrapper.py +239 -0
  13. vmtk/share/vmtkimagevolumeviewerpresets.xml +27 -0
  14. vmtk/vmtkactivetubes.py +92 -0
  15. vmtk/vmtkbifurcationprofiles.py +94 -0
  16. vmtk/vmtkbifurcationreferencesystems.py +77 -0
  17. vmtk/vmtkbifurcationsections.py +153 -0
  18. vmtk/vmtkbifurcationvectors.py +120 -0
  19. vmtk/vmtkboundarylayer.py +127 -0
  20. vmtk/vmtkboundarylayer2.py +137 -0
  21. vmtk/vmtkboundaryreferencesystems.py +75 -0
  22. vmtk/vmtkbranchclipper.py +154 -0
  23. vmtk/vmtkbranchextractor.py +78 -0
  24. vmtk/vmtkbranchgeometry.py +96 -0
  25. vmtk/vmtkbranchmapping.py +128 -0
  26. vmtk/vmtkbranchmetrics.py +120 -0
  27. vmtk/vmtkbranchpatching.py +103 -0
  28. vmtk/vmtkbranchsections.py +117 -0
  29. vmtk/vmtkcenterlineattributes.py +66 -0
  30. vmtk/vmtkcenterlinegeometry.py +96 -0
  31. vmtk/vmtkcenterlineimage.py +118 -0
  32. vmtk/vmtkcenterlineinterpolation.py +123 -0
  33. vmtk/vmtkcenterlinelabeler.py +149 -0
  34. vmtk/vmtkcenterlinemerge.py +80 -0
  35. vmtk/vmtkcenterlinemeshsections.py +104 -0
  36. vmtk/vmtkcenterlinemodeller.py +78 -0
  37. vmtk/vmtkcenterlineoffsetattributes.py +151 -0
  38. vmtk/vmtkcenterlineresampling.py +62 -0
  39. vmtk/vmtkcenterlines.py +689 -0
  40. vmtk/vmtkcenterlinesections.py +87 -0
  41. vmtk/vmtkcenterlinesmoothing.py +64 -0
  42. vmtk/vmtkcenterlinesnetwork.py +303 -0
  43. vmtk/vmtkcenterlinestonumpy.py +114 -0
  44. vmtk/vmtkcenterlineviewer.py +175 -0
  45. vmtk/vmtkcontribscripts.py +36 -0
  46. vmtk/vmtkdelaunayvoronoi.py +256 -0
  47. vmtk/vmtkdijkstradistancetopoints.py +299 -0
  48. vmtk/vmtkdistancetocenterlines.py +129 -0
  49. vmtk/vmtkdistancetospheres.py +365 -0
  50. vmtk/vmtkendpointextractor.py +85 -0
  51. vmtk/vmtkendpointsections.py +161 -0
  52. vmtk/vmtkentityrenumber.py +87 -0
  53. vmtk/vmtkflowextensions.py +193 -0
  54. vmtk/vmtkgeodesicsurfaceresolution.py +343 -0
  55. vmtk/vmtkicpregistration.py +140 -0
  56. vmtk/vmtkimagebinarize.py +69 -0
  57. vmtk/vmtkimagecast.py +88 -0
  58. vmtk/vmtkimagecompare.py +102 -0
  59. vmtk/vmtkimagecompose.py +84 -0
  60. vmtk/vmtkimagecurvedmpr.py +84 -0
  61. vmtk/vmtkimagefeaturecorrection.py +85 -0
  62. vmtk/vmtkimagefeatures.py +204 -0
  63. vmtk/vmtkimageinitialization.py +636 -0
  64. vmtk/vmtkimagemipviewer.py +135 -0
  65. vmtk/vmtkimagemorphology.py +77 -0
  66. vmtk/vmtkimagenormalize.py +62 -0
  67. vmtk/vmtkimageobjectenhancement.py +100 -0
  68. vmtk/vmtkimageotsuthresholds.py +80 -0
  69. vmtk/vmtkimagereader.py +318 -0
  70. vmtk/vmtkimagereslice.py +149 -0
  71. vmtk/vmtkimageseeder.py +208 -0
  72. vmtk/vmtkimageshiftscale.py +123 -0
  73. vmtk/vmtkimagesmoothing.py +124 -0
  74. vmtk/vmtkimagetonumpy.py +86 -0
  75. vmtk/vmtkimagevesselenhancement.py +213 -0
  76. vmtk/vmtkimageviewer.py +184 -0
  77. vmtk/vmtkimagevoipainter.py +245 -0
  78. vmtk/vmtkimagevoiselector.py +232 -0
  79. vmtk/vmtkimagevolumeviewer.py +323 -0
  80. vmtk/vmtkimagewriter.py +311 -0
  81. vmtk/vmtklevelsetsegmentation.py +390 -0
  82. vmtk/vmtklineartoquadratic.py +107 -0
  83. vmtk/vmtklineresampling.py +68 -0
  84. vmtk/vmtklocalgeometry.py +182 -0
  85. vmtk/vmtkmarchingcubes.py +79 -0
  86. vmtk/vmtkmeshaddexternallayer.py +256 -0
  87. vmtk/vmtkmesharrayoperation.py +102 -0
  88. vmtk/vmtkmeshboundaryinspector.py +168 -0
  89. vmtk/vmtkmeshbranchclipper.py +154 -0
  90. vmtk/vmtkmeshclipcenterlines.py +649 -0
  91. vmtk/vmtkmeshclipper.py +161 -0
  92. vmtk/vmtkmeshcompare.py +152 -0
  93. vmtk/vmtkmeshconnectivity.py +85 -0
  94. vmtk/vmtkmeshcutter.py +131 -0
  95. vmtk/vmtkmeshdatareader.py +351 -0
  96. vmtk/vmtkmeshextractpointdata.py +83 -0
  97. vmtk/vmtkmeshgenerator.py +366 -0
  98. vmtk/vmtkmeshlambda2.py +72 -0
  99. vmtk/vmtkmeshlinearize.py +60 -0
  100. vmtk/vmtkmeshmerge.py +73 -0
  101. vmtk/vmtkmeshmergetimesteps.py +210 -0
  102. vmtk/vmtkmeshpolyballevaluation.py +82 -0
  103. vmtk/vmtkmeshprojection.py +65 -0
  104. vmtk/vmtkmeshreader.py +339 -0
  105. vmtk/vmtkmeshscaling.py +62 -0
  106. vmtk/vmtkmeshtetrahedralize.py +60 -0
  107. vmtk/vmtkmeshtetrahedralize2.py +68 -0
  108. vmtk/vmtkmeshtonumpy.py +144 -0
  109. vmtk/vmtkmeshtosurface.py +64 -0
  110. vmtk/vmtkmeshtransform.py +97 -0
  111. vmtk/vmtkmeshtransformtoras.py +67 -0
  112. vmtk/vmtkmeshvectorfromcomponents.py +72 -0
  113. vmtk/vmtkmeshviewer.py +202 -0
  114. vmtk/vmtkmeshviewer2.py +293 -0
  115. vmtk/vmtkmeshvolume.py +69 -0
  116. vmtk/vmtkmeshvorticityhelicity.py +79 -0
  117. vmtk/vmtkmeshwallshearrate.py +79 -0
  118. vmtk/vmtkmeshwriter.py +381 -0
  119. vmtk/vmtkmeshwriter2.py +361 -0
  120. vmtk/vmtknetworkeditor.py +893 -0
  121. vmtk/vmtknetworkextraction.py +81 -0
  122. vmtk/vmtknetworkwriter.py +249 -0
  123. vmtk/vmtknumpyreader.py +126 -0
  124. vmtk/vmtknumpytocenterlines.py +83 -0
  125. vmtk/vmtknumpytoimage.py +94 -0
  126. vmtk/vmtknumpytomesh.py +122 -0
  127. vmtk/vmtknumpytosurface.py +145 -0
  128. vmtk/vmtknumpywriter.py +155 -0
  129. vmtk/vmtkparticletracer.py +190 -0
  130. vmtk/vmtkpathlineanimator.py +268 -0
  131. vmtk/vmtkpetergeneratesurface.py +259 -0
  132. vmtk/vmtkpeterresurface.py +232 -0
  133. vmtk/vmtkpetersurfaceclipper.py +338 -0
  134. vmtk/vmtkpointsplitextractor.py +88 -0
  135. vmtk/vmtkpointtransform.py +71 -0
  136. vmtk/vmtkpolyballmodeller.py +78 -0
  137. vmtk/vmtkpotentialfit.py +99 -0
  138. vmtk/vmtkpythonscript.py +69 -0
  139. vmtk/vmtkrbfinterpolation.py +99 -0
  140. vmtk/vmtkrenderer.py +376 -0
  141. vmtk/vmtkrendertoimage.py +61 -0
  142. vmtk/vmtkscripts.py +158 -0
  143. vmtk/vmtksurfaceappend.py +58 -0
  144. vmtk/vmtksurfacearrayoperation.py +104 -0
  145. vmtk/vmtksurfacearraysmoothing.py +134 -0
  146. vmtk/vmtksurfacebooleanoperation.py +85 -0
  147. vmtk/vmtksurfacecapper.py +209 -0
  148. vmtk/vmtksurfacecelldatatopointdata.py +57 -0
  149. vmtk/vmtksurfacecenterlineprojection.py +69 -0
  150. vmtk/vmtksurfacecliploop.py +137 -0
  151. vmtk/vmtksurfaceclipper.py +213 -0
  152. vmtk/vmtksurfacecompare.py +146 -0
  153. vmtk/vmtksurfaceconnectivity.py +111 -0
  154. vmtk/vmtksurfaceconnectivityselector.py +231 -0
  155. vmtk/vmtksurfacecurvature.py +153 -0
  156. vmtk/vmtksurfacedecimation.py +76 -0
  157. vmtk/vmtksurfacedistance.py +93 -0
  158. vmtk/vmtksurfaceendclipper.py +350 -0
  159. vmtk/vmtksurfaceextractannularwalls.py +135 -0
  160. vmtk/vmtksurfaceextractinnercylinder.py +128 -0
  161. vmtk/vmtksurfacekiteremoval.py +60 -0
  162. vmtk/vmtksurfaceloopextraction.py +147 -0
  163. vmtk/vmtksurfacemassproperties.py +72 -0
  164. vmtk/vmtksurfacemodeller.py +69 -0
  165. vmtk/vmtksurfacenormals.py +85 -0
  166. vmtk/vmtksurfacepointdatatocelldata.py +57 -0
  167. vmtk/vmtksurfacepolyballevaluation.py +82 -0
  168. vmtk/vmtksurfaceprojection.py +62 -0
  169. vmtk/vmtksurfacereader.py +252 -0
  170. vmtk/vmtksurfacereferencesystemtransform.py +140 -0
  171. vmtk/vmtksurfaceregiondrawing.py +175 -0
  172. vmtk/vmtksurfaceremeshing.py +154 -0
  173. vmtk/vmtksurfaceresolution.py +335 -0
  174. vmtk/vmtksurfacescaling.py +72 -0
  175. vmtk/vmtksurfacesmoothing.py +92 -0
  176. vmtk/vmtksurfacesubdivision.py +70 -0
  177. vmtk/vmtksurfacetobinaryimage.py +122 -0
  178. vmtk/vmtksurfacetomesh.py +65 -0
  179. vmtk/vmtksurfacetonumpy.py +126 -0
  180. vmtk/vmtksurfacetransform.py +97 -0
  181. vmtk/vmtksurfacetransforminteractive.py +194 -0
  182. vmtk/vmtksurfacetransformtoras.py +72 -0
  183. vmtk/vmtksurfacetriangle.py +60 -0
  184. vmtk/vmtksurfaceviewer.py +362 -0
  185. vmtk/vmtksurfacewriter.py +276 -0
  186. vmtk/vmtksurfacewriter2.py +227 -0
  187. vmtk/vmtksurfmesh.py +59 -0
  188. vmtk/vmtktetgen.py +158 -0
  189. vmtk/vmtktetringenerator.py +687 -0
  190. vmtk/vmtkthreshold.py +73 -0
  191. vmtk/vtkvmtk.py +23 -0
  192. vmtk/vtkvmtkCommon.dll +0 -0
  193. vmtk/vtkvmtkCommonPython.pyd +0 -0
  194. vmtk/vtkvmtkComputationalGeometry.dll +0 -0
  195. vmtk/vtkvmtkComputationalGeometryPython.pyd +0 -0
  196. vmtk/vtkvmtkContrib.dll +0 -0
  197. vmtk/vtkvmtkContribPython.pyd +0 -0
  198. vmtk/vtkvmtkDifferentialGeometry.dll +0 -0
  199. vmtk/vtkvmtkDifferentialGeometryPython.pyd +0 -0
  200. vmtk/vtkvmtkIO.dll +0 -0
  201. vmtk/vtkvmtkIOPython.pyd +0 -0
  202. vmtk/vtkvmtkITK.dll +0 -0
  203. vmtk/vtkvmtkITKPython.pyd +0 -0
  204. vmtk/vtkvmtkMisc.dll +0 -0
  205. vmtk/vtkvmtkMiscPython.pyd +0 -0
  206. vmtk/vtkvmtkRendering.dll +0 -0
  207. vmtk/vtkvmtkRenderingPython.pyd +0 -0
  208. vmtk/vtkvmtkSegmentation.dll +0 -0
  209. vmtk/vtkvmtkSegmentationPython.pyd +0 -0
  210. vmtk-1.5.0.dist-info/METADATA +308 -0
  211. vmtk-1.5.0.dist-info/RECORD +215 -0
  212. vmtk-1.5.0.dist-info/WHEEL +5 -0
  213. vmtk-1.5.0.dist-info/entry_points.txt +2 -0
  214. vmtk-1.5.0.dist-info/licenses/LICENSE +867 -0
  215. 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())