Commit fe149d00e964e42937fae10cbf9dcc35a125d204

Authored by Thiago Franco de Moraes
1 parent d498a62e
Exists in master

xrange -> range in cython files

invesalius_cy/cy_mesh.pyx
... ... @@ -6,6 +6,7 @@
6 6 #cython: cdivision=True
7 7 #cython: nonecheck=False
8 8  
  9 +import os
9 10 import sys
10 11 import time
11 12 cimport numpy as np
... ... @@ -68,7 +69,7 @@ cdef class Mesh:
68 69 self.faces = _faces
69 70 self.normals = _normals
70 71  
71   - for i in xrange(_faces.shape[0]):
  72 + for i in range(_faces.shape[0]):
72 73 self.map_vface[self.faces[i, 1]].push_back(i)
73 74 self.map_vface[self.faces[i, 2]].push_back(i)
74 75 self.map_vface[self.faces[i, 3]].push_back(i)
... ... @@ -201,12 +202,12 @@ cdef class Mesh:
201 202 idfaces = self.get_faces_by_vertex(v_id)
202 203 nf = idfaces.size()
203 204  
204   - for nid in xrange(nf):
  205 + for nid in range(nf):
205 206 f_id = deref(idfaces)[nid]
206 207 if status_f.find(f_id) == status_f.end():
207 208 status_f[f_id] = True
208 209  
209   - for j in xrange(3):
  210 + for j in range(3):
210 211 vj = self.faces[f_id, j+1]
211 212 if status_v.find(vj) == status_v.end():
212 213 status_v[vj] = True
... ... @@ -255,7 +256,7 @@ cdef vector[weight_t]* calc_artifacts_weight(Mesh mesh, vector[vertex_id_t]& ver
255 256 near_vertices = mesh.get_near_vertices_to_v(vi_id, tmax)
256 257 nnv = near_vertices.size()
257 258  
258   - for j in xrange(nnv):
  259 + for j in range(nnv):
259 260 vj_id = deref(near_vertices)[j]
260 261 vj = &mesh.vertices[vj_id, 0]
261 262  
... ... @@ -269,13 +270,13 @@ cdef vector[weight_t]* calc_artifacts_weight(Mesh mesh, vector[vertex_id_t]& ver
269 270  
270 271 del near_vertices
271 272  
272   - # for i in xrange(msize):
  273 + # for i in range(msize):
273 274 # if mesh.is_border(i):
274 275 # deref(weights)[i] = 0.0
275 276  
276 277 # cdef vertex_id_t v0, v1, v2
277   - # for i in xrange(mesh.faces.shape[0]):
278   - # for j in xrange(1, 4):
  278 + # for i in range(mesh.faces.shape[0]):
  279 + # for j in range(1, 4):
279 280 # v0 = mesh.faces[i, j]
280 281 # vi = &mesh.vertices[v0, 0]
281 282 # if mesh.is_border(v0):
... ... @@ -361,7 +362,7 @@ cdef vector[vertex_id_t]* find_staircase_artifacts(Mesh mesh, double[3] stack_or
361 362  
362 363 nv = mesh.vertices.shape[0]
363 364  
364   - for v_id in xrange(nv):
  365 + for v_id in range(nv):
365 366 max_z = -10000
366 367 min_z = 10000
367 368 max_y = -10000
... ... @@ -372,7 +373,7 @@ cdef vector[vertex_id_t]* find_staircase_artifacts(Mesh mesh, double[3] stack_or
372 373 f_ids = mesh.get_faces_by_vertex(v_id)
373 374 nf = deref(f_ids).size()
374 375  
375   - for i in xrange(nf):
  376 + for i in range(nf):
376 377 f_id = deref(f_ids)[i]
377 378 normal = &mesh.normals[f_id, 0]
378 379  
... ... @@ -415,7 +416,7 @@ cdef void taubin_smooth(Mesh mesh, vector[weight_t]& weights, float l, float m,
415 416 nvertices = mesh.vertices.shape[0]
416 417 cdef vector[Point] D = vector[Point](nvertices)
417 418 cdef vertex_t* vi
418   - for s in xrange(steps):
  419 + for s in range(steps):
419 420 for i in prange(nvertices, nogil=True):
420 421 D[i] = calc_d(mesh, i)
421 422  
... ...
invesalius_cy/floodfill.pyx
... ... @@ -142,11 +142,11 @@ def floodfill_threshold(np.ndarray[image_t, ndim=3] data, list seeds, int t0, in
142 142  
143 143 out[z, y, x] = fill
144 144  
145   - for k in xrange(odz):
  145 + for k in range(odz):
146 146 zo = z + k - offset_z
147   - for j in xrange(ody):
  147 + for j in range(ody):
148 148 yo = y + j - offset_y
149   - for i in xrange(odx):
  149 + for i in range(odx):
150 150 if strct[k, j, i]:
151 151 xo = x + i - offset_x
152 152 if 0 <= xo < dx and 0 <= yo < dy and 0 <= zo < dz and out[zo, yo, xo] != fill and t0 <= data[zo, yo, xo] <= t1:
... ... @@ -254,13 +254,13 @@ def fill_holes_automatically(np.ndarray[mask_t, ndim=3] mask, np.ndarray[np.uint
254 254 dy = mask.shape[1]
255 255 dx = mask.shape[2]
256 256  
257   - for z in xrange(dz):
258   - for y in xrange(dy):
259   - for x in xrange(dx):
  257 + for z in range(dz):
  258 + for y in range(dy):
  259 + for x in range(dx):
260 260 sizes[labels[z, y, x]] += 1
261 261  
262 262 #Checking if any hole will be filled
263   - for i in xrange(nlabels + 1):
  263 + for i in range(nlabels + 1):
264 264 if sizes[i] <= max_size:
265 265 modified = True
266 266  
... ... @@ -268,8 +268,8 @@ def fill_holes_automatically(np.ndarray[mask_t, ndim=3] mask, np.ndarray[np.uint
268 268 return 0
269 269  
270 270 for z in prange(dz, nogil=True):
271   - for y in xrange(dy):
272   - for x in xrange(dx):
  271 + for y in range(dy):
  272 + for x in range(dx):
273 273 if sizes[labels[z, y, x]] <= max_size:
274 274 mask[z, y, x] = 254
275 275  
... ...
invesalius_cy/interpolation.pyx
... ... @@ -172,28 +172,28 @@ cdef double lanczos3(image_t[:, :, :] V, double x, double y, double z) nogil:
172 172 cdef int m, n, o
173 173  
174 174 m = 0
175   - for k in xrange(zi, zf):
  175 + for k in range(zi, zf):
176 176 n = 0
177   - for j in xrange(yi, yf):
  177 + for j in range(yi, yf):
178 178 lx = 0
179   - for i in xrange(xi, xf):
  179 + for i in range(xi, xf):
180 180 lx += _G(V, i, j, k) * lanczos3_L(x - i, a)
181 181 temp_x[m][n] = lx
182 182 n += 1
183 183 m += 1
184 184  
185 185 m = 0
186   - for k in xrange(zi, zf):
  186 + for k in range(zi, zf):
187 187 n = 0
188 188 ly = 0
189   - for j in xrange(yi, yf):
  189 + for j in range(yi, yf):
190 190 ly += temp_x[m][n] * lanczos3_L(y - j, a)
191 191 n += 1
192 192 temp_y[m] = ly
193 193 m += 1
194 194  
195 195 m = 0
196   - for k in xrange(zi, zf):
  196 + for k in range(zi, zf):
197 197 lz += temp_y[m] * lanczos3_L(z - k, a)
198 198 m += 1
199 199  
... ... @@ -309,7 +309,7 @@ cdef void calc_coef_tricub(image_t[:, :, :] V, double x, double y, double z, dou
309 309  
310 310 for j in prange(64):
311 311 coef[j] = 0.0
312   - for i in xrange(64):
  312 + for i in range(64):
313 313 coef[j] += (temp[j][i] * _x[i])
314 314  
315 315  
... ... @@ -328,9 +328,9 @@ cdef double tricub_interpolate(image_t[:, :, :] V, double x, double y, double z)
328 328 cdef int yi = <int>floor(y)
329 329 cdef int zi = <int>floor(z)
330 330  
331   - for i in xrange(4):
332   - for j in xrange(4):
333   - for k in xrange(4):
  331 + for i in range(4):
  332 + for j in range(4):
  333 + for k in range(4):
334 334 result += (coef[i+4*j+16*k] * ((x-xi)**i) * ((y-yi)**j) * ((z-zi)**k))
335 335 # return V[<int>z, <int>y, <int>x]
336 336 # with gil:
... ... @@ -370,9 +370,9 @@ cdef double tricubicInterpolate(image_t[:, :, :] V, double x, double y, double z
370 370  
371 371 cdef int i, j, k
372 372  
373   - for i in xrange(4):
374   - for j in xrange(4):
375   - for k in xrange(4):
  373 + for i in range(4):
  374 + for j in range(4):
  375 + for k in range(4):
376 376 p[i][j][k] = _G(V, xi + i -1, yi + j -1, zi + k - 1)
377 377  
378 378 cdef double arr[4]
... ...
invesalius_cy/mips.pyx
... ... @@ -28,14 +28,14 @@ def lmip(np.ndarray[DTYPE16_t, ndim=3] image, int axis, DTYPE16_t tmin,
28 28  
29 29 # AXIAL
30 30 if axis == 0:
31   - for x in xrange(sx):
32   - for y in xrange(sy):
  31 + for x in range(sx):
  32 + for y in range(sy):
33 33 max = image[0, y, x]
34 34 if max >= tmin and max <= tmax:
35 35 start = 1
36 36 else:
37 37 start = 0
38   - for z in xrange(sz):
  38 + for z in range(sz):
39 39 if image[z, y, x] > max:
40 40 max = image[z, y, x]
41 41  
... ... @@ -49,14 +49,14 @@ def lmip(np.ndarray[DTYPE16_t, ndim=3] image, int axis, DTYPE16_t tmin,
49 49  
50 50 #CORONAL
51 51 elif axis == 1:
52   - for z in xrange(sz):
53   - for x in xrange(sx):
  52 + for z in range(sz):
  53 + for x in range(sx):
54 54 max = image[z, 0, x]
55 55 if max >= tmin and max <= tmax:
56 56 start = 1
57 57 else:
58 58 start = 0
59   - for y in xrange(sy):
  59 + for y in range(sy):
60 60 if image[z, y, x] > max:
61 61 max = image[z, y, x]
62 62  
... ... @@ -70,14 +70,14 @@ def lmip(np.ndarray[DTYPE16_t, ndim=3] image, int axis, DTYPE16_t tmin,
70 70  
71 71 #CORONAL
72 72 elif axis == 2:
73   - for z in xrange(sz):
74   - for y in xrange(sy):
  73 + for z in range(sz):
  74 + for y in range(sy):
75 75 max = image[z, y, 0]
76 76 if max >= tmin and max <= tmax:
77 77 start = 1
78 78 else:
79 79 start = 0
80   - for x in xrange(sx):
  80 + for x in range(sx):
81 81 if image[z, y, x] > max:
82 82 max = image[z, y, x]
83 83  
... ... @@ -164,11 +164,11 @@ def mida(np.ndarray[DTYPE16_t, ndim=3] image, int axis, DTYPE16_t wl,
164 164 # AXIAL
165 165 if axis == 0:
166 166 for x in prange(sx, nogil=True):
167   - for y in xrange(sy):
  167 + for y in range(sy):
168 168 fmax = 0.0
169 169 alpha_p = 0.0
170 170 colour_p = 0.0
171   - for z in xrange(sz):
  171 + for z in range(sz):
172 172 vl = image[z, y, x]
173 173 fpi = 1.0/(max - min) * (vl - min)
174 174 if fpi > fmax:
... ... @@ -198,11 +198,11 @@ def mida(np.ndarray[DTYPE16_t, ndim=3] image, int axis, DTYPE16_t wl,
198 198 #CORONAL
199 199 elif axis == 1:
200 200 for z in prange(sz, nogil=True):
201   - for x in xrange(sx):
  201 + for x in range(sx):
202 202 fmax = 0.0
203 203 alpha_p = 0.0
204 204 colour_p = 0.0
205   - for y in xrange(sy):
  205 + for y in range(sy):
206 206 vl = image[z, y, x]
207 207 fpi = 1.0/(max - min) * (vl - min)
208 208 if fpi > fmax:
... ... @@ -229,11 +229,11 @@ def mida(np.ndarray[DTYPE16_t, ndim=3] image, int axis, DTYPE16_t wl,
229 229 #AXIAL
230 230 elif axis == 2:
231 231 for z in prange(sz, nogil=True):
232   - for y in xrange(sy):
  232 + for y in range(sy):
233 233 fmax = 0.0
234 234 alpha_p = 0.0
235 235 colour_p = 0.0
236   - for x in xrange(sx):
  236 + for x in range(sx):
237 237 vl = image[z, y, x]
238 238 fpi = 1.0/(max - min) * (vl - min)
239 239 if fpi > fmax:
... ...
invesalius_cy/transforms.pyx
... ... @@ -116,23 +116,23 @@ def apply_view_matrix_transform(image_t[:, :, :] volume,
116 116 f_interp = lanczos3
117 117  
118 118 if orientation == 'AXIAL':
119   - for z in xrange(n, n+odz):
  119 + for z in range(n, n+odz):
120 120 for y in prange(dy, nogil=True):
121   - for x in xrange(dx):
  121 + for x in range(dx):
122 122 out[count, y, x] = coord_transform(volume, M, x, y, z, sx, sy, sz, f_interp, cval)
123 123 count += 1
124 124  
125 125 elif orientation == 'CORONAL':
126   - for y in xrange(n, n+ody):
  126 + for y in range(n, n+ody):
127 127 for z in prange(dz, nogil=True):
128   - for x in xrange(dx):
  128 + for x in range(dx):
129 129 out[z, count, x] = coord_transform(volume, M, x, y, z, sx, sy, sz, f_interp, cval)
130 130 count += 1
131 131  
132 132 elif orientation == 'SAGITAL':
133   - for x in xrange(n, n+odx):
  133 + for x in range(n, n+odx):
134 134 for z in prange(dz, nogil=True):
135   - for y in xrange(dy):
  135 + for y in range(dy):
136 136 out[z, y, count] = coord_transform(volume, M, x, y, z, sx, sy, sz, f_interp, cval)
137 137 count += 1
138 138  
... ... @@ -157,14 +157,14 @@ def convolve_non_zero(image_t[:, :, :] volume,
157 157 skx = kernel.shape[2]
158 158  
159 159 for z in prange(sz, nogil=True):
160   - for y in xrange(sy):
161   - for x in xrange(sx):
  160 + for y in range(sy):
  161 + for x in range(sx):
162 162 if volume[z, y, x] != 0:
163   - for k in xrange(skz):
  163 + for k in range(skz):
164 164 kz = z - skz // 2 + k
165   - for j in xrange(sky):
  165 + for j in range(sky):
166 166 ky = y - sky // 2 + j
167   - for i in xrange(skx):
  167 + for i in range(skx):
168 168 kx = x - skx // 2 + i
169 169  
170 170 if 0 <= kz < sz and 0 <= ky < sy and 0 <= kx < sx:
... ...