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