24
24
25
25
from itkTemplate import output
26
26
27
- # The following line defines an ascii string used for dynamically refreshing
28
- # the import and progress callbacks on the same terminal line.
29
- # See http://www.termsys.demon.co.uk/vtansi.htm
30
- # \033 is the C-style octal code for an escape character
31
- # [2000D moves the cursor back 2000 columns, this is a brute force way of
32
- # getting to the start of the line.
33
- # [K erases the end of the line
34
- clrLine = "\033 [2000D\033 [K"
27
+ from sys import stderr as system_error_stream
35
28
36
29
37
30
def set_nthreads (number_of_threads ):
@@ -61,90 +54,6 @@ def get_nthreads():
61
54
return threader .GetGlobalDefaultNumberOfThreads ()
62
55
63
56
64
- def auto_not_in_place (v = True ):
65
- """Force it to not run in place
66
- """
67
- import itkConfig
68
-
69
- itkConfig .NotInPlace = v
70
-
71
-
72
- def auto_progress (progress_type = 1 ):
73
- """Set up auto progress report
74
-
75
- progress_type:
76
- 1 or True -> auto progress be used in a terminal
77
- 2 -> simple auto progress (without special characters)
78
- 0 or False -> disable auto progress
79
- """
80
- import itkConfig
81
-
82
- if progress_type is True or progress_type == 1 :
83
- itkConfig .ImportCallback = terminal_import_callback
84
- itkConfig .ProgressCallback = terminal_progress_callback
85
-
86
- elif progress_type == 2 :
87
- itkConfig .ImportCallback = simple_import_callback
88
- itkConfig .ProgressCallback = simple_progress_callback
89
-
90
- elif progress_type is False or progress_type == 0 :
91
- itkConfig .ImportCallback = None
92
- itkConfig .ProgressCallback = None
93
-
94
- else :
95
- raise ValueError ("Invalid auto progress type: " + repr (progress_type ))
96
-
97
-
98
- def terminal_progress_callback (name , p ):
99
- """Display the progress of an object and clean the display once complete
100
-
101
- This function can be used with itkConfig.ProgressCallback
102
- """
103
- print (clrLine + "%s: %f" % (name , p ), file = system_error_stream , end = "" )
104
- if p == 1 :
105
- print (clrLine , file = system_error_stream , end = "" )
106
-
107
-
108
- def terminal_import_callback (name , p ):
109
- """Display the loading of a module and clean the display once complete
110
-
111
- This function can be used with itkConfig.ImportCallback
112
- """
113
- print (clrLine + "Loading %s... " % name , file = system_error_stream , end = "" )
114
- if p == 1 :
115
- print (clrLine , file = system_error_stream , end = "" )
116
-
117
-
118
- def simple_import_callback (name , p ):
119
- """Print a message when a module is loading
120
-
121
- This function can be used with itkConfig.ImportCallback
122
- """
123
- if p == 0 :
124
- print ("Loading %s... " % name , file = system_error_stream , end = "" )
125
- elif p == 1 :
126
- print ("done" , file = system_error_stream )
127
-
128
-
129
- def simple_progress_callback (name , p ):
130
- """Print a message when an object is running
131
-
132
- This function can be used with itkConfig.ProgressCallback
133
- """
134
- if p == 0 :
135
- print ("Running %s... " % name , file = system_error_stream , end = "" )
136
- elif p == 1 :
137
- print ("done" , file = system_error_stream )
138
-
139
-
140
- def force_load ():
141
- """force itk to load all the submodules"""
142
- import itk
143
-
144
- for k in dir (itk ):
145
- getattr (itk , k )
146
-
147
-
148
57
def echo (obj , f = system_error_stream ):
149
58
"""Print an object to stream
150
59
@@ -255,8 +164,7 @@ def _get_itk_pixelid(numpy_array_type):
255
164
256
165
257
166
def _GetArrayFromImage (image_or_filter , function , keep_axes , update ):
258
- """Get an Array with the content of the image buffer
259
- """
167
+ """Get an Array with the content of the image buffer"""
260
168
# Finds the image type
261
169
import itk
262
170
@@ -269,17 +177,15 @@ def _GetArrayFromImage(image_or_filter, function, keep_axes, update):
269
177
270
178
271
179
def GetArrayFromImage (image_or_filter , keep_axes = False , update = True ):
272
- """Get an array with the content of the image buffer
273
- """
180
+ """Get an array with the content of the image buffer"""
274
181
return _GetArrayFromImage (image_or_filter , "GetArrayFromImage" , keep_axes , update )
275
182
276
183
277
184
array_from_image = GetArrayFromImage
278
185
279
186
280
187
def GetArrayViewFromImage (image_or_filter , keep_axes = False , update = True ):
281
- """Get an array view with the content of the image buffer
282
- """
188
+ """Get an array view with the content of the image buffer"""
283
189
return _GetArrayFromImage (
284
190
image_or_filter , "GetArrayViewFromImage" , keep_axes , update
285
191
)
@@ -1038,7 +944,7 @@ def New(self, *args, **kargs):
1038
944
# extract the types from the arguments to instantiate the class
1039
945
import itk
1040
946
1041
- types = tuple (itk . class_ (o ) for o in args )
947
+ types = tuple (class_ (o ) for o in args )
1042
948
return self [types ].New (* args , ** kargs )
1043
949
1044
950
def __getitem__ (self , template_parameters ):
0 commit comments