Commit 9519edaa1d0ffd159f193aab1ae2cdb8de2b8a84

Authored by Thiago Franco de Moraes
1 parent 5722493b
Exists in master

Using Isort and Black to improve code format in geometry

Showing 1 changed file with 203 additions and 152 deletions   Show diff stats
invesalius/data/geometry.py
1 -#-------------------------------------------------------------------------- 1 +# --------------------------------------------------------------------------
2 # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas 2 # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
3 # Copyright: (C) 2001 Centro de Pesquisas Renato Archer 3 # Copyright: (C) 2001 Centro de Pesquisas Renato Archer
4 -# Homepage: http://www.softwarepublico.gov.br / 4 +# Homepage: http://www.softwarepublico.gov.br/
5 # http://www.cti.gov.br/invesalius 5 # http://www.cti.gov.br/invesalius
6 # Contact: invesalius@cti.gov.br 6 # Contact: invesalius@cti.gov.br
7 # License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt) 7 # License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
8 -#-------------------------------------------------------------------------- 8 +# --------------------------------------------------------------------------
9 # Este programa e software livre; voce pode redistribui-lo e/ou 9 # Este programa e software livre; voce pode redistribui-lo e/ou
10 # modifica-lo sob os termos da Licenca Publica Geral GNU, conforme 10 # modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
11 # publicada pela Free Software Foundation; de acordo com a versao 2 11 # publicada pela Free Software Foundation; de acordo com a versao 2
@@ -16,17 +16,17 @@ @@ -16,17 +16,17 @@
16 # COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM 16 # COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
17 # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais 17 # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
18 # detalhes. 18 # detalhes.
19 -#-------------------------------------------------------------------------- 19 +# --------------------------------------------------------------------------
20 20
21 -from six import with_metaclass 21 +import math
22 22
23 import numpy as np 23 import numpy as np
24 -import math  
25 import vtk 24 import vtk
  25 +from six import with_metaclass
26 from wx.lib.pubsub import pub as Publisher 26 from wx.lib.pubsub import pub as Publisher
27 27
28 -import invesalius.utils as utils  
29 import invesalius.constants as const 28 import invesalius.constants as const
  29 +import invesalius.utils as utils
30 30
31 31
32 class Box(with_metaclass(utils.Singleton, object)): 32 class Box(with_metaclass(utils.Singleton, object)):
@@ -62,7 +62,7 @@ class Box(with_metaclass(utils.Singleton, object)): @@ -62,7 +62,7 @@ class Box(with_metaclass(utils.Singleton, object)):
62 def SetX(self, i, f): 62 def SetX(self, i, f):
63 self.xi = i 63 self.xi = i
64 self.xf = f 64 self.xf = f
65 - self.size_x = f 65 + self.size_x = f
66 66
67 def SetY(self, i, f): 67 def SetY(self, i, f):
68 self.yi = i 68 self.yi = i
@@ -75,7 +75,7 @@ class Box(with_metaclass(utils.Singleton, object)): @@ -75,7 +75,7 @@ class Box(with_metaclass(utils.Singleton, object)):
75 self.size_z = f 75 self.size_z = f
76 76
77 def SetSpacing(self, x, y, z): 77 def SetSpacing(self, x, y, z):
78 - self.xs = x 78 + self.xs = x
79 self.ys = y 79 self.ys = y
80 self.zs = z 80 self.zs = z
81 81
@@ -100,63 +100,90 @@ class Box(with_metaclass(utils.Singleton, object)): @@ -100,63 +100,90 @@ class Box(with_metaclass(utils.Singleton, object)):
100 Update values in a matrix to each orientation. 100 Update values in a matrix to each orientation.
101 """ 101 """
102 102
103 - self.sagital[const.SAGITAL_LEFT] = [[self.xi, self.yi - (self.ys/2), self.zi],\  
104 - [self.xi, self.yi - (self.ys/2), self.zf]]  
105 -  
106 - self.sagital[const.SAGITAL_RIGHT] = [[self.xi, self.yf + (self.ys/2), self.zi],\  
107 - [self.xi, self.yf + (self.ys/2), self.zf]]  
108 -  
109 - self.sagital[const.SAGITAL_BOTTOM] = [[self.xi, self.yi, self.zi - (self.zs/2)],\  
110 - [self.xi, self.yf, self.zi - (self.zs/2)]]  
111 -  
112 - self.sagital[const.SAGITAL_UPPER] = [[self.xi, self.yi, self.zf + (self.zs/2) ],\  
113 - [self.xi, self.yf, self.zf + (self.zs/2) ]]  
114 -  
115 - self.coronal[const.CORONAL_BOTTOM] = [[self.xi, self.yi, self.zi - (self.zs/2)],\  
116 - [self.xf, self.yf, self.zi - (self.zs/2)]]  
117 -  
118 - self.coronal[const.CORONAL_UPPER] = [[self.xi, self.yi, self.zf + (self.zs/2)],\  
119 - [self.xf, self.yf, self.zf + (self.zs/2)]]  
120 -  
121 - self.coronal[const.CORONAL_LEFT] = [[self.xi - (self.xs/2), self.yi, self.zi],\  
122 - [self.xi - (self.xs/2), self.yf, self.zf]]  
123 -  
124 - self.coronal[const.CORONAL_RIGHT] = [[self.xf + (self.xs/2), self.yi, self.zi],\  
125 - [self.xf + (self.xs/2), self.yf, self.zf]]  
126 -  
127 - self.axial[const.AXIAL_BOTTOM] = [[self.xi, self.yi - (self.ys/2), self.zi],\  
128 - [self.xf, self.yi - (self.ys/2), self.zf]]  
129 -  
130 - self.axial[const.AXIAL_UPPER] = [[self.xi, self.yf + (self.ys/2), self.zi],\  
131 - [self.xf, self.yf + (self.ys/2), self.zf]]  
132 -  
133 - self.axial[const.AXIAL_LEFT] = [[self.xi - (self.xs/2), self.yi, self.zi],\  
134 - [self.xi - (self.xs/2), self.yf, self.zf]]  
135 -  
136 - self.axial[const.AXIAL_RIGHT] = [[self.xf + (self.xs/2), self.yi, self.zi],\  
137 - [self.xf + (self.xs/2), self.yf, self.zf]]  
138 -  
139 - Publisher.sendMessage('Update crop limits into gui', limits=self.GetLimits())  
140 - 103 + self.sagital[const.SAGITAL_LEFT] = [
  104 + [self.xi, self.yi - (self.ys / 2), self.zi],
  105 + [self.xi, self.yi - (self.ys / 2), self.zf],
  106 + ]
  107 +
  108 + self.sagital[const.SAGITAL_RIGHT] = [
  109 + [self.xi, self.yf + (self.ys / 2), self.zi],
  110 + [self.xi, self.yf + (self.ys / 2), self.zf],
  111 + ]
  112 +
  113 + self.sagital[const.SAGITAL_BOTTOM] = [
  114 + [self.xi, self.yi, self.zi - (self.zs / 2)],
  115 + [self.xi, self.yf, self.zi - (self.zs / 2)],
  116 + ]
  117 +
  118 + self.sagital[const.SAGITAL_UPPER] = [
  119 + [self.xi, self.yi, self.zf + (self.zs / 2)],
  120 + [self.xi, self.yf, self.zf + (self.zs / 2)],
  121 + ]
  122 +
  123 + self.coronal[const.CORONAL_BOTTOM] = [
  124 + [self.xi, self.yi, self.zi - (self.zs / 2)],
  125 + [self.xf, self.yf, self.zi - (self.zs / 2)],
  126 + ]
  127 +
  128 + self.coronal[const.CORONAL_UPPER] = [
  129 + [self.xi, self.yi, self.zf + (self.zs / 2)],
  130 + [self.xf, self.yf, self.zf + (self.zs / 2)],
  131 + ]
  132 +
  133 + self.coronal[const.CORONAL_LEFT] = [
  134 + [self.xi - (self.xs / 2), self.yi, self.zi],
  135 + [self.xi - (self.xs / 2), self.yf, self.zf],
  136 + ]
  137 +
  138 + self.coronal[const.CORONAL_RIGHT] = [
  139 + [self.xf + (self.xs / 2), self.yi, self.zi],
  140 + [self.xf + (self.xs / 2), self.yf, self.zf],
  141 + ]
  142 +
  143 + self.axial[const.AXIAL_BOTTOM] = [
  144 + [self.xi, self.yi - (self.ys / 2), self.zi],
  145 + [self.xf, self.yi - (self.ys / 2), self.zf],
  146 + ]
  147 +
  148 + self.axial[const.AXIAL_UPPER] = [
  149 + [self.xi, self.yf + (self.ys / 2), self.zi],
  150 + [self.xf, self.yf + (self.ys / 2), self.zf],
  151 + ]
  152 +
  153 + self.axial[const.AXIAL_LEFT] = [
  154 + [self.xi - (self.xs / 2), self.yi, self.zi],
  155 + [self.xi - (self.xs / 2), self.yf, self.zf],
  156 + ]
  157 +
  158 + self.axial[const.AXIAL_RIGHT] = [
  159 + [self.xf + (self.xs / 2), self.yi, self.zi],
  160 + [self.xf + (self.xs / 2), self.yf, self.zf],
  161 + ]
  162 +
  163 + Publisher.sendMessage("Update crop limits into gui", limits=self.GetLimits())
141 164
142 def GetLimits(self): 165 def GetLimits(self):
143 """ 166 """
144 Return the bounding box limits (initial and final) in x, y and z. 167 Return the bounding box limits (initial and final) in x, y and z.
145 """ 168 """
146 169
147 - limits = [ int(self.xi / self.xs), int(self.xf / self. xs),\  
148 - int(self.yi / self.ys), int(self.yf / self.ys),\  
149 - int(self.zi / self.zs), int(self.zf / self.zs)] 170 + limits = [
  171 + int(self.xi / self.xs),
  172 + int(self.xf / self.xs),
  173 + int(self.yi / self.ys),
  174 + int(self.yf / self.ys),
  175 + int(self.zi / self.zs),
  176 + int(self.zf / self.zs),
  177 + ]
150 178
151 return limits 179 return limits
152 -  
153 - 180 +
154 def UpdatePositionBySideBox(self, pc, axis, position): 181 def UpdatePositionBySideBox(self, pc, axis, position):
155 """ 182 """
156 Checks the coordinates are in any side of box and update it. 183 Checks the coordinates are in any side of box and update it.
157 Is necessary to move limits of box. 184 Is necessary to move limits of box.
158 - """  
159 - 185 + """
  186 +
160 if axis == "AXIAL": 187 if axis == "AXIAL":
161 if position == const.AXIAL_UPPER: 188 if position == const.AXIAL_UPPER:
162 if pc[1] > self.yi and pc[1] > 0 and pc[1] <= self.size_y: 189 if pc[1] > self.yi and pc[1] > 0 and pc[1] <= self.size_y:
@@ -167,15 +194,13 @@ class Box(with_metaclass(utils.Singleton, object)): @@ -167,15 +194,13 @@ class Box(with_metaclass(utils.Singleton, object)):
167 self.yi = pc[1] 194 self.yi = pc[1]
168 195
169 if position == const.AXIAL_LEFT: 196 if position == const.AXIAL_LEFT:
170 - if pc[0] < self.xf and pc[0] >= 0: 197 + if pc[0] < self.xf and pc[0] >= 0:
171 self.xi = pc[0] 198 self.xi = pc[0]
172 199
173 -  
174 if position == const.AXIAL_RIGHT: 200 if position == const.AXIAL_RIGHT:
175 if pc[0] > self.xi and pc[0] <= self.size_x: 201 if pc[0] > self.xi and pc[0] <= self.size_x:
176 self.xf = pc[0] 202 self.xf = pc[0]
177 203
178 -  
179 if axis == "SAGITAL": 204 if axis == "SAGITAL":
180 if position == const.SAGITAL_UPPER: 205 if position == const.SAGITAL_UPPER:
181 if pc[2] > self.zi and pc[2] > 0 and pc[2] <= self.size_z: 206 if pc[2] > self.zi and pc[2] > 0 and pc[2] <= self.size_z:
@@ -186,14 +211,13 @@ class Box(with_metaclass(utils.Singleton, object)): @@ -186,14 +211,13 @@ class Box(with_metaclass(utils.Singleton, object)):
186 self.zi = pc[2] 211 self.zi = pc[2]
187 212
188 if position == const.SAGITAL_LEFT: 213 if position == const.SAGITAL_LEFT:
189 - if pc[1] < self.yf and pc[1] >= 0: 214 + if pc[1] < self.yf and pc[1] >= 0:
190 self.yi = pc[1] 215 self.yi = pc[1]
191 216
192 if position == const.SAGITAL_RIGHT: 217 if position == const.SAGITAL_RIGHT:
193 if pc[1] > self.yi and pc[1] <= self.size_y: 218 if pc[1] > self.yi and pc[1] <= self.size_y:
194 self.yf = pc[1] 219 self.yf = pc[1]
195 220
196 -  
197 if axis == "CORONAL": 221 if axis == "CORONAL":
198 if position == const.CORONAL_UPPER: 222 if position == const.CORONAL_UPPER:
199 if pc[2] > self.zi and pc[2] > 0 and pc[2] <= self.size_z: 223 if pc[2] > self.zi and pc[2] > 0 and pc[2] <= self.size_z:
@@ -204,16 +228,15 @@ class Box(with_metaclass(utils.Singleton, object)): @@ -204,16 +228,15 @@ class Box(with_metaclass(utils.Singleton, object)):
204 self.zi = pc[2] 228 self.zi = pc[2]
205 229
206 if position == const.CORONAL_LEFT: 230 if position == const.CORONAL_LEFT:
207 - if pc[0] < self.xf and pc[0] >= 0: 231 + if pc[0] < self.xf and pc[0] >= 0:
208 self.xi = pc[0] 232 self.xi = pc[0]
209 - 233 +
210 if position == const.CORONAL_RIGHT: 234 if position == const.CORONAL_RIGHT:
211 if pc[0] > self.yi and pc[0] <= self.size_y: 235 if pc[0] > self.yi and pc[0] <= self.size_y:
212 - self.xf = pc[0] 236 + self.xf = pc[0]
213 237
214 self.MakeMatrix() 238 self.MakeMatrix()
215 239
216 -  
217 def UpdatePositionByInsideBox(self, pc, axis): 240 def UpdatePositionByInsideBox(self, pc, axis):
218 """ 241 """
219 Checks the coordinates are inside the box and update it. 242 Checks the coordinates are inside the box and update it.
@@ -253,13 +276,13 @@ class Box(with_metaclass(utils.Singleton, object)): @@ -253,13 +276,13 @@ class Box(with_metaclass(utils.Singleton, object)):
253 self.MakeMatrix() 276 self.MakeMatrix()
254 277
255 278
256 -  
257 -class DrawCrop2DRetangle(): 279 +class DrawCrop2DRetangle:
258 """ 280 """
259 This class is responsible for draw and control user 281 This class is responsible for draw and control user
260 interactions with the box. Each side of box is displayed in an 282 interactions with the box. Each side of box is displayed in an
261 anatomical orientation (axial, sagital or coronal). 283 anatomical orientation (axial, sagital or coronal).
262 """ 284 """
  285 +
263 def __init__(self): 286 def __init__(self):
264 self.viewer = None 287 self.viewer = None
265 self.points_in_display = {} 288 self.points_in_display = {}
@@ -280,66 +303,80 @@ class DrawCrop2DRetangle(): @@ -280,66 +303,80 @@ class DrawCrop2DRetangle():
280 x_pos_sl_, y_pos_sl_ = self.viewer.get_slice_pixel_coord_by_screen_pos(x, y) 303 x_pos_sl_, y_pos_sl_ = self.viewer.get_slice_pixel_coord_by_screen_pos(x, y)
281 slice_spacing = self.viewer.slice_.spacing 304 slice_spacing = self.viewer.slice_.spacing
282 xs, ys, zs = slice_spacing 305 xs, ys, zs = slice_spacing
283 - 306 +
284 x_pos_sl = x_pos_sl_ * xs 307 x_pos_sl = x_pos_sl_ * xs
285 y_pos_sl = y_pos_sl_ * ys 308 y_pos_sl = y_pos_sl_ * ys
286 309
287 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(x, y) 310 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(x, y)
288 311
289 if self.viewer.orientation == "AXIAL": 312 if self.viewer.orientation == "AXIAL":
290 -  
291 - if self.status_move == const.AXIAL_UPPER or\  
292 - self.status_move == const.AXIAL_BOTTOM:  
293 - Publisher.sendMessage('Set interactor resize NS cursor')  
294 - elif self.status_move == const.AXIAL_LEFT or\  
295 - self.status_move == const.AXIAL_RIGHT:  
296 - Publisher.sendMessage('Set interactor resize WE cursor') 313 +
  314 + if (
  315 + self.status_move == const.AXIAL_UPPER
  316 + or self.status_move == const.AXIAL_BOTTOM
  317 + ):
  318 + Publisher.sendMessage("Set interactor resize NS cursor")
  319 + elif (
  320 + self.status_move == const.AXIAL_LEFT
  321 + or self.status_move == const.AXIAL_RIGHT
  322 + ):
  323 + Publisher.sendMessage("Set interactor resize WE cursor")
297 elif self.crop_pan == const.CROP_PAN: 324 elif self.crop_pan == const.CROP_PAN:
298 - Publisher.sendMessage('Set interactor resize NSWE cursor') 325 + Publisher.sendMessage("Set interactor resize NSWE cursor")
299 else: 326 else:
300 - Publisher.sendMessage('Set interactor default cursor') 327 + Publisher.sendMessage("Set interactor default cursor")
301 328
302 if self.viewer.orientation == "SAGITAL": 329 if self.viewer.orientation == "SAGITAL":
303 - if self.status_move == const.SAGITAL_UPPER or\  
304 - self.status_move == const.SAGITAL_BOTTOM:  
305 - Publisher.sendMessage('Set interactor resize NS cursor')  
306 - elif self.status_move == const.SAGITAL_LEFT or\  
307 - self.status_move == const.SAGITAL_RIGHT:  
308 - Publisher.sendMessage('Set interactor resize WE cursor') 330 + if (
  331 + self.status_move == const.SAGITAL_UPPER
  332 + or self.status_move == const.SAGITAL_BOTTOM
  333 + ):
  334 + Publisher.sendMessage("Set interactor resize NS cursor")
  335 + elif (
  336 + self.status_move == const.SAGITAL_LEFT
  337 + or self.status_move == const.SAGITAL_RIGHT
  338 + ):
  339 + Publisher.sendMessage("Set interactor resize WE cursor")
309 elif self.crop_pan == const.CROP_PAN: 340 elif self.crop_pan == const.CROP_PAN:
310 - Publisher.sendMessage('Set interactor resize NSWE cursor') 341 + Publisher.sendMessage("Set interactor resize NSWE cursor")
311 else: 342 else:
312 - Publisher.sendMessage('Set interactor default cursor') 343 + Publisher.sendMessage("Set interactor default cursor")
313 344
314 if self.viewer.orientation == "CORONAL": 345 if self.viewer.orientation == "CORONAL":
315 - if self.status_move == const.CORONAL_UPPER or\  
316 - self.status_move == const.CORONAL_BOTTOM:  
317 - Publisher.sendMessage('Set interactor resize NS cursor')  
318 - elif self.status_move == const.CORONAL_LEFT or\  
319 - self.status_move == const.CORONAL_RIGHT:  
320 - Publisher.sendMessage('Set interactor resize WE cursor') 346 + if (
  347 + self.status_move == const.CORONAL_UPPER
  348 + or self.status_move == const.CORONAL_BOTTOM
  349 + ):
  350 + Publisher.sendMessage("Set interactor resize NS cursor")
  351 + elif (
  352 + self.status_move == const.CORONAL_LEFT
  353 + or self.status_move == const.CORONAL_RIGHT
  354 + ):
  355 + Publisher.sendMessage("Set interactor resize WE cursor")
321 elif self.crop_pan == const.CROP_PAN: 356 elif self.crop_pan == const.CROP_PAN:
322 - Publisher.sendMessage('Set interactor resize NSWE cursor') 357 + Publisher.sendMessage("Set interactor resize NSWE cursor")
323 else: 358 else:
324 - Publisher.sendMessage('Set interactor default cursor')  
325 - 359 + Publisher.sendMessage("Set interactor default cursor")
  360 +
326 if self.mouse_pressed and self.status_move: 361 if self.mouse_pressed and self.status_move:
327 - self.box.UpdatePositionBySideBox((x * xs, y * ys, z * zs),\  
328 - self.viewer.orientation, self.status_move) 362 + self.box.UpdatePositionBySideBox(
  363 + (x * xs, y * ys, z * zs), self.viewer.orientation, self.status_move
  364 + )
329 365
330 nv_x = x - self.last_x 366 nv_x = x - self.last_x
331 nv_y = y - self.last_y 367 nv_y = y - self.last_y
332 nv_z = z - self.last_z 368 nv_z = z - self.last_z
333 369
334 if self.mouse_pressed and self.crop_pan: 370 if self.mouse_pressed and self.crop_pan:
335 - self.box.UpdatePositionByInsideBox((nv_x * xs, nv_y * ys, nv_z * zs),\  
336 - self.viewer.orientation) 371 + self.box.UpdatePositionByInsideBox(
  372 + (nv_x * xs, nv_y * ys, nv_z * zs), self.viewer.orientation
  373 + )
337 374
338 self.last_x = x 375 self.last_x = x
339 self.last_y = y 376 self.last_y = y
340 self.last_z = z 377 self.last_z = z
341 378
342 - Publisher.sendMessage('Redraw canvas') 379 + Publisher.sendMessage("Redraw canvas")
343 380
344 def ReleaseLeft(self): 381 def ReleaseLeft(self):
345 self.status_move = None 382 self.status_move = None
@@ -352,7 +389,7 @@ class DrawCrop2DRetangle(): @@ -352,7 +389,7 @@ class DrawCrop2DRetangle():
352 389
353 slice_spacing = self.viewer.slice_.spacing 390 slice_spacing = self.viewer.slice_.spacing
354 xs, ys, zs = slice_spacing 391 xs, ys, zs = slice_spacing
355 - 392 +
356 if self.viewer.orientation == "AXIAL": 393 if self.viewer.orientation == "AXIAL":
357 x_pos_sl = x_pos_sl_ * xs 394 x_pos_sl = x_pos_sl_ * xs
358 y_pos_sl = y_pos_sl_ * ys 395 y_pos_sl = y_pos_sl_ * ys
@@ -361,19 +398,21 @@ class DrawCrop2DRetangle(): @@ -361,19 +398,21 @@ class DrawCrop2DRetangle():
361 p0 = p[0] 398 p0 = p[0]
362 p1 = p[1] 399 p1 = p[1]
363 400
364 - dist = self.distance_from_point_line((p0[0], p0[1]),\  
365 - (p1[0], p1[1]),\  
366 - (x_pos_sl, y_pos_sl)) 401 + dist = self.distance_from_point_line(
  402 + (p0[0], p0[1]), (p1[0], p1[1]), (x_pos_sl, y_pos_sl)
  403 + )
367 404
368 if dist <= 2: 405 if dist <= 2:
369 if self.point_between_line(p0, p1, (x_pos_sl, y_pos_sl), "AXIAL"): 406 if self.point_between_line(p0, p1, (x_pos_sl, y_pos_sl), "AXIAL"):
370 self.status_move = k 407 self.status_move = k
371 break 408 break
372 409
373 - if self.point_into_box(p0, p1, (x_pos_sl, y_pos_sl), "AXIAL")\  
374 - and self.status_move == None: 410 + if (
  411 + self.point_into_box(p0, p1, (x_pos_sl, y_pos_sl), "AXIAL")
  412 + and self.status_move == None
  413 + ):
375 self.crop_pan = const.CROP_PAN 414 self.crop_pan = const.CROP_PAN
376 - #break 415 + # break
377 else: 416 else:
378 if self.crop_pan: 417 if self.crop_pan:
379 self.crop_pan = None 418 self.crop_pan = None
@@ -382,27 +421,28 @@ class DrawCrop2DRetangle(): @@ -382,27 +421,28 @@ class DrawCrop2DRetangle():
382 if not (self.mouse_pressed) and k != self.status_move: 421 if not (self.mouse_pressed) and k != self.status_move:
383 self.status_move = None 422 self.status_move = None
384 423
385 -  
386 if self.viewer.orientation == "CORONAL": 424 if self.viewer.orientation == "CORONAL":
387 x_pos_sl = x_pos_sl_ * xs 425 x_pos_sl = x_pos_sl_ * xs
388 y_pos_sl = y_pos_sl_ * zs 426 y_pos_sl = y_pos_sl_ * zs
389 - 427 +
390 for k, p in self.box.coronal.items(): 428 for k, p in self.box.coronal.items():
391 p0 = p[0] 429 p0 = p[0]
392 p1 = p[1] 430 p1 = p[1]
393 431
394 - dist = self.distance_from_point_line((p0[0], p0[2]),\  
395 - (p1[0], p1[2]),\  
396 - (x_pos_sl, y_pos_sl)) 432 + dist = self.distance_from_point_line(
  433 + (p0[0], p0[2]), (p1[0], p1[2]), (x_pos_sl, y_pos_sl)
  434 + )
397 if dist <= 2: 435 if dist <= 2:
398 if self.point_between_line(p0, p1, (x_pos_sl, y_pos_sl), "CORONAL"): 436 if self.point_between_line(p0, p1, (x_pos_sl, y_pos_sl), "CORONAL"):
399 self.status_move = k 437 self.status_move = k
400 break 438 break
401 439
402 - if self.point_into_box(p0, p1, (x_pos_sl, y_pos_sl), "CORONAL")\  
403 - and self.status_move == None: 440 + if (
  441 + self.point_into_box(p0, p1, (x_pos_sl, y_pos_sl), "CORONAL")
  442 + and self.status_move == None
  443 + ):
404 self.crop_pan = const.CROP_PAN 444 self.crop_pan = const.CROP_PAN
405 - #break 445 + # break
406 else: 446 else:
407 if self.crop_pan: 447 if self.crop_pan:
408 self.crop_pan = None 448 self.crop_pan = None
@@ -411,7 +451,6 @@ class DrawCrop2DRetangle(): @@ -411,7 +451,6 @@ class DrawCrop2DRetangle():
411 if not (self.mouse_pressed) and k != self.status_move: 451 if not (self.mouse_pressed) and k != self.status_move:
412 self.status_move = None 452 self.status_move = None
413 453
414 -  
415 if self.viewer.orientation == "SAGITAL": 454 if self.viewer.orientation == "SAGITAL":
416 x_pos_sl = x_pos_sl_ * ys 455 x_pos_sl = x_pos_sl_ * ys
417 y_pos_sl = y_pos_sl_ * zs 456 y_pos_sl = y_pos_sl_ * zs
@@ -420,19 +459,21 @@ class DrawCrop2DRetangle(): @@ -420,19 +459,21 @@ class DrawCrop2DRetangle():
420 p0 = p[0] 459 p0 = p[0]
421 p1 = p[1] 460 p1 = p[1]
422 461
423 - dist = self.distance_from_point_line((p0[1], p0[2]),\  
424 - (p1[1], p1[2]),\  
425 - (x_pos_sl, y_pos_sl)) 462 + dist = self.distance_from_point_line(
  463 + (p0[1], p0[2]), (p1[1], p1[2]), (x_pos_sl, y_pos_sl)
  464 + )
426 465
427 if dist <= 2: 466 if dist <= 2:
428 if self.point_between_line(p0, p1, (x_pos_sl, y_pos_sl), "SAGITAL"): 467 if self.point_between_line(p0, p1, (x_pos_sl, y_pos_sl), "SAGITAL"):
429 self.status_move = k 468 self.status_move = k
430 break 469 break
431 470
432 - if self.point_into_box(p0, p1, (x_pos_sl, y_pos_sl), "SAGITAL")\  
433 - and self.status_move == None: 471 + if (
  472 + self.point_into_box(p0, p1, (x_pos_sl, y_pos_sl), "SAGITAL")
  473 + and self.status_move == None
  474 + ):
434 self.crop_pan = const.CROP_PAN 475 self.crop_pan = const.CROP_PAN
435 - #break 476 + # break
436 else: 477 else:
437 if self.crop_pan: 478 if self.crop_pan:
438 self.crop_pan = None 479 self.crop_pan = None
@@ -441,8 +482,6 @@ class DrawCrop2DRetangle(): @@ -441,8 +482,6 @@ class DrawCrop2DRetangle():
441 if not (self.mouse_pressed) and k != self.status_move: 482 if not (self.mouse_pressed) and k != self.status_move:
442 self.status_move = None 483 self.status_move = None
443 484
444 -  
445 -  
446 def draw_to_canvas(self, gc, canvas): 485 def draw_to_canvas(self, gc, canvas):
447 """ 486 """
448 Draws to an wx.GraphicsContext. 487 Draws to an wx.GraphicsContext.
@@ -457,61 +496,71 @@ class DrawCrop2DRetangle(): @@ -457,61 +496,71 @@ class DrawCrop2DRetangle():
457 def point_into_box(self, p1, p2, pc, axis): 496 def point_into_box(self, p1, p2, pc, axis):
458 497
459 if axis == "AXIAL": 498 if axis == "AXIAL":
460 - if pc[0] > self.box.xi + 10 and pc[0] < self.box.xf - 10\  
461 - and pc[1] - 10 > self.box.yi and pc[1] < self.box.yf - 10: 499 + if (
  500 + pc[0] > self.box.xi + 10
  501 + and pc[0] < self.box.xf - 10
  502 + and pc[1] - 10 > self.box.yi
  503 + and pc[1] < self.box.yf - 10
  504 + ):
462 return True 505 return True
463 else: 506 else:
464 return False 507 return False
465 508
466 if axis == "SAGITAL": 509 if axis == "SAGITAL":
467 - if pc[0] > self.box.yi + 10 and pc[0] < self.box.yf - 10\  
468 - and pc[1] - 10 > self.box.zi and pc[1] < self.box.zf - 10: 510 + if (
  511 + pc[0] > self.box.yi + 10
  512 + and pc[0] < self.box.yf - 10
  513 + and pc[1] - 10 > self.box.zi
  514 + and pc[1] < self.box.zf - 10
  515 + ):
469 return True 516 return True
470 else: 517 else:
471 return False 518 return False
472 519
473 if axis == "CORONAL": 520 if axis == "CORONAL":
474 - if pc[0] > self.box.xi + 10 and pc[0] < self.box.xf - 10\  
475 - and pc[1] - 10 > self.box.zi and pc[1] < self.box.zf - 10: 521 + if (
  522 + pc[0] > self.box.xi + 10
  523 + and pc[0] < self.box.xf - 10
  524 + and pc[1] - 10 > self.box.zi
  525 + and pc[1] < self.box.zf - 10
  526 + ):
476 return True 527 return True
477 else: 528 else:
478 return False 529 return False
479 530
480 -  
481 def point_between_line(self, p1, p2, pc, axis): 531 def point_between_line(self, p1, p2, pc, axis):
482 """ 532 """
483 Checks whether a point is in the line limits 533 Checks whether a point is in the line limits
484 """ 534 """
485 535
486 if axis == "AXIAL": 536 if axis == "AXIAL":
487 - if p1[0] < pc[0] and p2[0] > pc[0]: #x axis 537 + if p1[0] < pc[0] and p2[0] > pc[0]: # x axis
488 return True 538 return True
489 - elif p1[1] < pc[1] and p2[1] > pc[1]: #y axis 539 + elif p1[1] < pc[1] and p2[1] > pc[1]: # y axis
490 return True 540 return True
491 else: 541 else:
492 return False 542 return False
493 elif axis == "SAGITAL": 543 elif axis == "SAGITAL":
494 - if p1[1] < pc[0] and p2[1] > pc[0]: #y axis 544 + if p1[1] < pc[0] and p2[1] > pc[0]: # y axis
495 return True 545 return True
496 - elif p1[2] < pc[1] and p2[2] > pc[1]: #z axis 546 + elif p1[2] < pc[1] and p2[2] > pc[1]: # z axis
497 return True 547 return True
498 else: 548 else:
499 return False 549 return False
500 elif axis == "CORONAL": 550 elif axis == "CORONAL":
501 - if p1[0] < pc[0] and p2[0] > pc[0]: #x axis 551 + if p1[0] < pc[0] and p2[0] > pc[0]: # x axis
502 return True 552 return True
503 - elif p1[2] < pc[1] and p2[2] > pc[1]: #z axis 553 + elif p1[2] < pc[1] and p2[2] > pc[1]: # z axis
504 return True 554 return True
505 else: 555 else:
506 return False 556 return False
507 557
508 -  
509 def distance_from_point_line(self, p1, p2, pc): 558 def distance_from_point_line(self, p1, p2, pc):
510 """ 559 """
511 Calculate the distance from point pc to a line formed by p1 and p2. 560 Calculate the distance from point pc to a line formed by p1 and p2.
512 """ 561 """
513 562
514 - #TODO: Same function into clut_raycasting 563 + # TODO: Same function into clut_raycasting
515 # Create a function to organize it. 564 # Create a function to organize it.
516 565
517 # Create a vector pc-p1 and p2-p1 566 # Create a vector pc-p1 and p2-p1
@@ -527,20 +576,19 @@ class DrawCrop2DRetangle(): @@ -527,20 +576,19 @@ class DrawCrop2DRetangle():
527 distance = math.sin(theta) * len_A 576 distance = math.sin(theta) * len_A
528 return distance 577 return distance
529 578
530 -  
531 def Coord3DtoDisplay(self, x, y, z, canvas): 579 def Coord3DtoDisplay(self, x, y, z, canvas):
532 580
533 coord = vtk.vtkCoordinate() 581 coord = vtk.vtkCoordinate()
534 coord.SetValue(x, y, z) 582 coord.SetValue(x, y, z)
535 cx, cy = coord.GetComputedDisplayValue(canvas.evt_renderer) 583 cx, cy = coord.GetComputedDisplayValue(canvas.evt_renderer)
536 - 584 +
537 return (cx, cy) 585 return (cx, cy)
538 586
539 def MakeBox(self): 587 def MakeBox(self):
540 588
541 slice_size = self.viewer.slice_.matrix.shape 589 slice_size = self.viewer.slice_.matrix.shape
542 zf, yf, xf = slice_size[0] - 1, slice_size[1] - 1, slice_size[2] - 1 590 zf, yf, xf = slice_size[0] - 1, slice_size[1] - 1, slice_size[2] - 1
543 - 591 +
544 slice_spacing = self.viewer.slice_.spacing 592 slice_spacing = self.viewer.slice_.spacing
545 xs, ys, zs = slice_spacing 593 xs, ys, zs = slice_spacing
546 594
@@ -553,55 +601,58 @@ class DrawCrop2DRetangle(): @@ -553,55 +601,58 @@ class DrawCrop2DRetangle():
553 box.SetSpacing(xs, ys, zs) 601 box.SetSpacing(xs, ys, zs)
554 box.MakeMatrix() 602 box.MakeMatrix()
555 603
556 -  
557 def UpdateValues(self, canvas): 604 def UpdateValues(self, canvas):
558 605
559 box = self.box 606 box = self.box
560 - slice_number = self.viewer.slice_data.number 607 + slice_number = self.viewer.slice_data.number
561 608
562 slice_spacing = self.viewer.slice_.spacing 609 slice_spacing = self.viewer.slice_.spacing
563 xs, ys, zs = slice_spacing 610 xs, ys, zs = slice_spacing
564 - 611 +
565 if canvas.orientation == "AXIAL": 612 if canvas.orientation == "AXIAL":
566 for points in box.axial.values(): 613 for points in box.axial.values():
567 pi_x, pi_y, pi_z = points[0] 614 pi_x, pi_y, pi_z = points[0]
568 pf_x, pf_y, pf_z = points[1] 615 pf_x, pf_y, pf_z = points[1]
569 616
570 s_cxi, s_cyi = self.Coord3DtoDisplay(pi_x, pi_y, pi_z, canvas) 617 s_cxi, s_cyi = self.Coord3DtoDisplay(pi_x, pi_y, pi_z, canvas)
571 - s_cxf, s_cyf = self.Coord3DtoDisplay(pf_x, pf_y, pf_z ,canvas) 618 + s_cxf, s_cyf = self.Coord3DtoDisplay(pf_x, pf_y, pf_z, canvas)
572 619
573 sn = slice_number * zs 620 sn = slice_number * zs
574 if sn >= box.zi and sn <= box.zf: 621 if sn >= box.zi and sn <= box.zf:
575 - canvas.draw_line((s_cxi, s_cyi),(s_cxf, s_cyf), colour=(255,255,255,255))  
576 - 622 + canvas.draw_line(
  623 + (s_cxi, s_cyi), (s_cxf, s_cyf), colour=(255, 255, 255, 255)
  624 + )
  625 +
577 elif canvas.orientation == "CORONAL": 626 elif canvas.orientation == "CORONAL":
578 for points in box.coronal.values(): 627 for points in box.coronal.values():
579 pi_x, pi_y, pi_z = points[0] 628 pi_x, pi_y, pi_z = points[0]
580 pf_x, pf_y, pf_z = points[1] 629 pf_x, pf_y, pf_z = points[1]
581 630
582 s_cxi, s_cyi = self.Coord3DtoDisplay(pi_x, pi_y, pi_z, canvas) 631 s_cxi, s_cyi = self.Coord3DtoDisplay(pi_x, pi_y, pi_z, canvas)
583 - s_cxf, s_cyf = self.Coord3DtoDisplay(pf_x, pf_y, pf_z ,canvas) 632 + s_cxf, s_cyf = self.Coord3DtoDisplay(pf_x, pf_y, pf_z, canvas)
584 633
585 sn = slice_number * ys 634 sn = slice_number * ys
586 635
587 if sn >= box.yi and sn <= box.yf: 636 if sn >= box.yi and sn <= box.yf:
588 - canvas.draw_line((s_cxi, s_cyi),(s_cxf, s_cyf), colour=(255,255,255,255)) 637 + canvas.draw_line(
  638 + (s_cxi, s_cyi), (s_cxf, s_cyf), colour=(255, 255, 255, 255)
  639 + )
589 640
590 elif canvas.orientation == "SAGITAL": 641 elif canvas.orientation == "SAGITAL":
591 for points in box.sagital.values(): 642 for points in box.sagital.values():
592 - 643 +
593 pi_x, pi_y, pi_z = points[0] 644 pi_x, pi_y, pi_z = points[0]
594 pf_x, pf_y, pf_z = points[1] 645 pf_x, pf_y, pf_z = points[1]
595 646
596 s_cxi, s_cyi = self.Coord3DtoDisplay(pi_x, pi_y, pi_z, canvas) 647 s_cxi, s_cyi = self.Coord3DtoDisplay(pi_x, pi_y, pi_z, canvas)
597 - s_cxf, s_cyf = self.Coord3DtoDisplay(pf_x, pf_y, pf_z ,canvas) 648 + s_cxf, s_cyf = self.Coord3DtoDisplay(pf_x, pf_y, pf_z, canvas)
598 649
599 sn = slice_number * xs 650 sn = slice_number * xs
600 if sn >= box.xi and sn <= box.xf: 651 if sn >= box.xi and sn <= box.xf:
601 - canvas.draw_line((s_cxi, s_cyi),(s_cxf, s_cyf), colour=(255,255,255,255))  
602 - 652 + canvas.draw_line(
  653 + (s_cxi, s_cyi), (s_cxf, s_cyf), colour=(255, 255, 255, 255)
  654 + )
603 655
604 def SetViewer(self, viewer): 656 def SetViewer(self, viewer):
605 self.viewer = viewer 657 self.viewer = viewer
606 self.MakeBox() 658 self.MakeBox()
607 -