Commit 4d912616bf4ad6241252952ba4be247705e7957e

Authored by tfmoraes
1 parent 25192bff

STYLE: Removed exceeding white spaces

Showing 1 changed file with 182 additions and 201 deletions   Show diff stats
invesalius/data/viewer_volume.py
@@ -74,9 +74,51 @@ class Viewer(wx.Panel): @@ -74,9 +74,51 @@ class Viewer(wx.Panel):
74 74
75 self.__bind_events() 75 self.__bind_events()
76 self.__bind_events_wx() 76 self.__bind_events_wx()
77 - 77 +
78 self.mouse_pressed = 0 78 self.mouse_pressed = 0
79 - 79 +
  80 + def __bind_events(self):
  81 + ps.Publisher().subscribe(self.LoadActor,
  82 + 'Load surface actor into viewer')
  83 + ps.Publisher().subscribe(self.UpdateRender,
  84 + 'Render volume viewer')
  85 + ps.Publisher().subscribe(self.ChangeBackgroundColour,
  86 + 'Change volume viewer background colour')
  87 + # Raycating - related
  88 + ps.Publisher().subscribe(self.LoadVolume,
  89 + 'Load volume into viewer')
  90 + ps.Publisher().subscribe(self.OnSetWindowLevelText,
  91 + 'Set volume window and level text')
  92 + ps.Publisher().subscribe(self.OnHideRaycasting,
  93 + 'Hide raycasting volume')
  94 + ps.Publisher().subscribe(self.OnShowRaycasting,
  95 + 'Update raycasting preset')
  96 + ###
  97 + ps.Publisher().subscribe(self.AppendActor,'AppendActor')
  98 + ps.Publisher().subscribe(self.SetWidgetInteractor,
  99 + 'Set Widget Interactor')
  100 + ps.Publisher().subscribe(self.OnSetViewAngle,
  101 + 'Set volume view angle')
  102 +
  103 + ps.Publisher().subscribe(self.SetNewMode,
  104 + ('Set interaction mode', const.MODE_WW_WL))
  105 + ps.Publisher().subscribe(self.OnDisableBrightContrast,
  106 + ('Set interaction mode',
  107 + const.MODE_SLICE_EDITOR))
  108 +
  109 + ps.Publisher().subscribe(self.OnExportSurface, 'Export surface to file')
  110 +
  111 + ps.Publisher().subscribe(self.LoadSlicePlane, 'Load slice plane')
  112 +
  113 + ps.Publisher().subscribe(self.ResetCamClippingRange, 'Reset cam clipping range')
  114 +
  115 + ps.Publisher().subscribe(self.OnEnableStyle, 'Enable style')
  116 + ps.Publisher().subscribe(self.OnDisableStyle, 'Disable style')
  117 +
  118 + def __bind_events_wx(self):
  119 + #self.Bind(wx.EVT_SIZE, self.OnSize)
  120 + pass
  121 +
80 def SetInteractorStyle(self, state): 122 def SetInteractorStyle(self, state):
81 action = { 123 action = {
82 const.STATE_PAN: 124 const.STATE_PAN:
@@ -110,7 +152,7 @@ class Viewer(wx.Panel): @@ -110,7 +152,7 @@ class Viewer(wx.Panel):
110 { 152 {
111 } 153 }
112 } 154 }
113 - 155 +
114 if (state == const.STATE_ZOOM_SL): 156 if (state == const.STATE_ZOOM_SL):
115 style = vtk.vtkInteractorStyleRubberBandZoom() 157 style = vtk.vtkInteractorStyleRubberBandZoom()
116 self.interactor.SetInteractorStyle(style) 158 self.interactor.SetInteractorStyle(style)
@@ -119,12 +161,41 @@ class Viewer(wx.Panel): @@ -119,12 +161,41 @@ class Viewer(wx.Panel):
119 style = vtk.vtkInteractorStyleTrackballCamera() 161 style = vtk.vtkInteractorStyleTrackballCamera()
120 self.interactor.SetInteractorStyle(style) 162 self.interactor.SetInteractorStyle(style)
121 self.style = style 163 self.style = style
122 - 164 +
123 # Check each event available for each mode 165 # Check each event available for each mode
124 for event in action[state]: 166 for event in action[state]:
125 # Bind event 167 # Bind event
126 style.AddObserver(event,action[state][event]) 168 style.AddObserver(event,action[state][event])
127 - 169 +
  170 + def SetStyle(self, pubsub_evt):
  171 + print "SetStyle"
  172 + mode = pubsub_evt.data
  173 +
  174 + if (mode == const.MODE_ZOOM_SELECTION):
  175 + self.SetMode('ZOOMSELECT')
  176 + elif(mode == const.MODE_MOVE):
  177 + self.SetMode('PAN')
  178 + elif(mode == const.MODE_ZOOM):
  179 + self.SetMode('ZOOM')
  180 + elif(mode == const.MODE_ROTATE):
  181 + self.SetMode('SPIN')
  182 + elif(mode == const.MODE_WW_WL):
  183 + self.SetMode('WINDOWLEVEL')
  184 +
  185 + def SetNewMode(self, pubsub_evt):
  186 + mode = pubsub_evt.topic[1]
  187 +
  188 + if (mode == const.MODE_ZOOM_SELECTION):
  189 + self.SetMode('ZOOMSELECT')
  190 + elif(mode == const.MODE_MOVE):
  191 + self.SetMode('PAN')
  192 + elif(mode == const.MODE_ZOOM):
  193 + self.SetMode('ZOOM')
  194 + elif(mode == const.MODE_ROTATE):
  195 + self.SetMode('SPIN')
  196 + elif(mode == const.MODE_WW_WL):
  197 + self.SetMode('WINDOWLEVEL')
  198 +
128 def OnSpinMove(self, evt, obj): 199 def OnSpinMove(self, evt, obj):
129 if (self.mouse_pressed): 200 if (self.mouse_pressed):
130 evt.Spin() 201 evt.Spin()
@@ -133,11 +204,11 @@ class Viewer(wx.Panel): @@ -133,11 +204,11 @@ class Viewer(wx.Panel):
133 def OnSpinClick(self, evt, obj): 204 def OnSpinClick(self, evt, obj):
134 self.mouse_pressed = 1 205 self.mouse_pressed = 1
135 evt.StartSpin() 206 evt.StartSpin()
136 - 207 +
137 def OnReleaseSpinClick(self,evt,obj): 208 def OnReleaseSpinClick(self,evt,obj):
138 self.mouse_pressed = 0 209 self.mouse_pressed = 0
139 evt.EndSpin() 210 evt.EndSpin()
140 - 211 +
141 def OnZoomMove(self, evt, obj): 212 def OnZoomMove(self, evt, obj):
142 if (self.mouse_pressed): 213 if (self.mouse_pressed):
143 evt.Dolly() 214 evt.Dolly()
@@ -146,12 +217,11 @@ class Viewer(wx.Panel): @@ -146,12 +217,11 @@ class Viewer(wx.Panel):
146 def OnZoomClick(self, evt, obj): 217 def OnZoomClick(self, evt, obj):
147 self.mouse_pressed = 1 218 self.mouse_pressed = 1
148 evt.StartDolly() 219 evt.StartDolly()
149 - 220 +
150 def OnReleaseZoomClick(self,evt,obj): 221 def OnReleaseZoomClick(self,evt,obj):
151 self.mouse_pressed = 0 222 self.mouse_pressed = 0
152 evt.EndDolly() 223 evt.EndDolly()
153 -  
154 - 224 +
155 def OnPanMove(self, evt, obj): 225 def OnPanMove(self, evt, obj):
156 if (self.mouse_pressed): 226 if (self.mouse_pressed):
157 evt.Pan() 227 evt.Pan()
@@ -160,41 +230,11 @@ class Viewer(wx.Panel): @@ -160,41 +230,11 @@ class Viewer(wx.Panel):
160 def OnPanClick(self, evt, obj): 230 def OnPanClick(self, evt, obj):
161 self.mouse_pressed = 1 231 self.mouse_pressed = 1
162 evt.StartPan() 232 evt.StartPan()
163 - 233 +
164 def OnReleasePanClick(self,evt,obj): 234 def OnReleasePanClick(self,evt,obj):
165 self.mouse_pressed = 0 235 self.mouse_pressed = 0
166 evt.EndPan() 236 evt.EndPan()
167 -  
168 - def SetStyle(self, pubsub_evt):  
169 - print "SetStyle"  
170 - mode = pubsub_evt.data  
171 -  
172 - if (mode == const.MODE_ZOOM_SELECTION):  
173 - self.SetMode('ZOOMSELECT')  
174 - elif(mode == const.MODE_MOVE):  
175 - self.SetMode('PAN')  
176 - elif(mode == const.MODE_ZOOM):  
177 - self.SetMode('ZOOM')  
178 - elif(mode == const.MODE_ROTATE):  
179 - self.SetMode('SPIN')  
180 - elif(mode == const.MODE_WW_WL):  
181 - self.SetMode('WINDOWLEVEL')  
182 237
183 -  
184 - def SetNewMode(self, pubsub_evt):  
185 - mode = pubsub_evt.topic[1]  
186 -  
187 - if (mode == const.MODE_ZOOM_SELECTION):  
188 - self.SetMode('ZOOMSELECT')  
189 - elif(mode == const.MODE_MOVE):  
190 - self.SetMode('PAN')  
191 - elif(mode == const.MODE_ZOOM):  
192 - self.SetMode('ZOOM')  
193 - elif(mode == const.MODE_ROTATE):  
194 - self.SetMode('SPIN')  
195 - elif(mode == const.MODE_WW_WL):  
196 - self.SetMode('WINDOWLEVEL')  
197 -  
198 def OnWindowLevelMove(self, obj, evt): 238 def OnWindowLevelMove(self, obj, evt):
199 if self.onclick and self.raycasting_volume: 239 if self.onclick and self.raycasting_volume:
200 mouse_x, mouse_y = self.interactor.GetEventPosition() 240 mouse_x, mouse_y = self.interactor.GetEventPosition()
@@ -218,83 +258,6 @@ class Viewer(wx.Panel): @@ -218,83 +258,6 @@ class Viewer(wx.Panel):
218 if const.RAYCASTING_WWWL_BLUR: 258 if const.RAYCASTING_WWWL_BLUR:
219 self.style.EndZoom() 259 self.style.EndZoom()
220 260
221 - def ShowOrientationCube(self):  
222 - print "ORIENTATION CUBE!"  
223 - cube = vtk.vtkAnnotatedCubeActor()  
224 - cube.GetXMinusFaceProperty().SetColor(1,0,0)  
225 - cube.GetXPlusFaceProperty().SetColor(1,0,0)  
226 - cube.GetYMinusFaceProperty().SetColor(0,1,0)  
227 - cube.GetYPlusFaceProperty().SetColor(0,1,0)  
228 - cube.GetZMinusFaceProperty().SetColor(0,0,1)  
229 - cube.GetZPlusFaceProperty().SetColor(0,0,1)  
230 - cube.GetTextEdgesProperty().SetColor(0,0,0)  
231 -  
232 - # anatomic labelling  
233 - cube.SetXPlusFaceText ("A")  
234 - cube.SetXMinusFaceText("P")  
235 - cube.SetYPlusFaceText ("L")  
236 - cube.SetYMinusFaceText("R")  
237 - cube.SetZPlusFaceText ("S")  
238 - cube.SetZMinusFaceText("I")  
239 -  
240 - axes = vtk.vtkAxesActor()  
241 - axes.SetShaftTypeToCylinder()  
242 - axes.SetTipTypeToCone()  
243 - axes.SetXAxisLabelText("X")  
244 - axes.SetYAxisLabelText("Y")  
245 - axes.SetZAxisLabelText("Z")  
246 - #axes.SetNormalizedLabelPosition(.5, .5, .5)  
247 -  
248 - orientation_widget = vtk.vtkOrientationMarkerWidget()  
249 - orientation_widget.SetOrientationMarker(cube)  
250 - orientation_widget.SetViewport(0.85,0.85,1.0,1.0)  
251 - #orientation_widget.SetOrientationMarker(axes)  
252 - orientation_widget.SetInteractor(self.interactor)  
253 - orientation_widget.SetEnabled(1)  
254 - orientation_widget.On()  
255 - orientation_widget.InteractiveOff()  
256 -  
257 -  
258 - def __bind_events(self):  
259 - ps.Publisher().subscribe(self.LoadActor,  
260 - 'Load surface actor into viewer')  
261 - ps.Publisher().subscribe(self.UpdateRender,  
262 - 'Render volume viewer')  
263 - ps.Publisher().subscribe(self.ChangeBackgroundColour,  
264 - 'Change volume viewer background colour')  
265 - # Raycating - related  
266 - ps.Publisher().subscribe(self.LoadVolume,  
267 - 'Load volume into viewer')  
268 - ps.Publisher().subscribe(self.OnSetWindowLevelText,  
269 - 'Set volume window and level text')  
270 - ps.Publisher().subscribe(self.OnHideRaycasting,  
271 - 'Hide raycasting volume')  
272 - ps.Publisher().subscribe(self.OnShowRaycasting,  
273 - 'Update raycasting preset')  
274 - ###  
275 - ps.Publisher().subscribe(self.AppendActor,'AppendActor')  
276 - ps.Publisher().subscribe(self.SetWidgetInteractor,  
277 - 'Set Widget Interactor')  
278 - ps.Publisher().subscribe(self.OnSetViewAngle,  
279 - 'Set volume view angle')  
280 -  
281 - ps.Publisher().subscribe(self.SetNewMode,  
282 - ('Set interaction mode', const.MODE_WW_WL))  
283 - ps.Publisher().subscribe(self.OnDisableBrightContrast,  
284 - ('Set interaction mode',  
285 - const.MODE_SLICE_EDITOR))  
286 -  
287 - ps.Publisher().subscribe(self.OnExportSurface, 'Export surface to file')  
288 -  
289 - ps.Publisher().subscribe(self.LoadSlicePlane, 'Load slice plane')  
290 -  
291 - ps.Publisher().subscribe(self.ResetCamClippingRange, 'Reset cam clipping range')  
292 -  
293 -  
294 - ps.Publisher().subscribe(self.OnEnableStyle, 'Enable style')  
295 - ps.Publisher().subscribe(self.OnDisableStyle, 'Disable style')  
296 -  
297 -  
298 def OnEnableStyle(self, pubsub_evt): 261 def OnEnableStyle(self, pubsub_evt):
299 state = pubsub_evt.data 262 state = pubsub_evt.data
300 if (state in const.VOLUME_STYLES): 263 if (state in const.VOLUME_STYLES):
@@ -310,11 +273,9 @@ class Viewer(wx.Panel): @@ -310,11 +273,9 @@ class Viewer(wx.Panel):
310 new_state = self.interaction_style.RemoveState(state) 273 new_state = self.interaction_style.RemoveState(state)
311 self.SetInteractorStyle(new_state) 274 self.SetInteractorStyle(new_state)
312 275
313 -  
314 def ResetCamClippingRange(self, pubsub_evt): 276 def ResetCamClippingRange(self, pubsub_evt):
315 self.ren.ResetCamera() 277 self.ren.ResetCamera()
316 self.ren.ResetCameraClippingRange() 278 self.ren.ResetCameraClippingRange()
317 -  
318 279
319 def OnExportSurface(self, pubsub_evt): 280 def OnExportSurface(self, pubsub_evt):
320 filename, filetype = pubsub_evt.data 281 filename, filetype = pubsub_evt.data
@@ -338,32 +299,17 @@ class Viewer(wx.Panel): @@ -338,32 +299,17 @@ class Viewer(wx.Panel):
338 writer.SetInput(renwin) 299 writer.SetInput(renwin)
339 writer.Write() 300 writer.Write()
340 301
341 -  
342 -  
343 - def __bind_events_wx(self):  
344 - #self.Bind(wx.EVT_SIZE, self.OnSize)  
345 - pass  
346 -  
347 def OnEnableBrightContrast(self, pubsub_evt): 302 def OnEnableBrightContrast(self, pubsub_evt):
348 style = self.style 303 style = self.style
349 style.AddObserver("MouseMoveEvent", self.OnMove) 304 style.AddObserver("MouseMoveEvent", self.OnMove)
350 style.AddObserver("LeftButtonPressEvent", self.OnClick) 305 style.AddObserver("LeftButtonPressEvent", self.OnClick)
351 style.AddObserver("LeftButtonReleaseEvent", self.OnRelease) 306 style.AddObserver("LeftButtonReleaseEvent", self.OnRelease)
352 307
353 -  
354 def OnDisableBrightContrast(self, pubsub_evt): 308 def OnDisableBrightContrast(self, pubsub_evt):
355 style = vtk.vtkInteractorStyleTrackballCamera() 309 style = vtk.vtkInteractorStyleTrackballCamera()
356 self.interactor.SetInteractorStyle(style) 310 self.interactor.SetInteractorStyle(style)
357 self.style = style 311 self.style = style
358 -  
359 312
360 - def OnSize(self, evt):  
361 - self.UpdateRender()  
362 - self.Refresh()  
363 - self.interactor.UpdateWindowUI()  
364 - self.interactor.Update()  
365 - evt.Skip()  
366 -  
367 def OnSetWindowLevelText(self, pubsub_evt): 313 def OnSetWindowLevelText(self, pubsub_evt):
368 if self.raycasting_volume: 314 if self.raycasting_volume:
369 ww, wl = pubsub_evt.data 315 ww, wl = pubsub_evt.data
@@ -377,30 +323,12 @@ class Viewer(wx.Panel): @@ -377,30 +323,12 @@ class Viewer(wx.Panel):
377 self.raycasting_volume = False 323 self.raycasting_volume = False
378 self.text.Hide() 324 self.text.Hide()
379 325
380 - def LoadVolume(self, pubsub_evt):  
381 - self.raycasting_volume = True  
382 -  
383 - volume = pubsub_evt.data[0]  
384 - colour = pubsub_evt.data[1]  
385 - ww, wl = pubsub_evt.data[2]  
386 -  
387 - self.light = self.ren.GetLights().GetNextItem()  
388 -  
389 - self.ren.AddVolume(volume)  
390 - self.text.SetValue("WL: %d WW: %d"%(wl, ww))  
391 - self.ren.AddActor(self.text.actor)  
392 - self.ren.SetBackground(colour)  
393 -  
394 - if not (self.view_angle):  
395 - self.SetViewAngle(const.VOL_FRONT)  
396 - else:  
397 - self.ren.ResetCamera()  
398 - self.ren.ResetCameraClippingRange()  
399 - 326 + def OnSize(self, evt):
400 self.UpdateRender() 327 self.UpdateRender()
401 -  
402 - def LoadSlicePlane(self, pubsub_evt):  
403 - self.slice_plane = SlicePlane() 328 + self.Refresh()
  329 + self.interactor.UpdateWindowUI()
  330 + self.interactor.Update()
  331 + evt.Skip()
404 332
405 def ChangeBackgroundColour(self, pubsub_evt): 333 def ChangeBackgroundColour(self, pubsub_evt):
406 colour = pubsub_evt.data 334 colour = pubsub_evt.data
@@ -409,10 +337,10 @@ class Viewer(wx.Panel): @@ -409,10 +337,10 @@ class Viewer(wx.Panel):
409 337
410 def LoadActor(self, pubsub_evt): 338 def LoadActor(self, pubsub_evt):
411 actor = pubsub_evt.data 339 actor = pubsub_evt.data
412 - 340 +
413 ren = self.ren 341 ren = self.ren
414 ren.AddActor(actor) 342 ren.AddActor(actor)
415 - 343 +
416 if not (self.view_angle): 344 if not (self.view_angle):
417 self.SetViewAngle(const.VOL_FRONT) 345 self.SetViewAngle(const.VOL_FRONT)
418 self.view_angle = 1 346 self.view_angle = 1
@@ -421,40 +349,100 @@ class Viewer(wx.Panel): @@ -421,40 +349,100 @@ class Viewer(wx.Panel):
421 ren.ResetCameraClippingRange() 349 ren.ResetCameraClippingRange()
422 350
423 #self.ShowOrientationCube() 351 #self.ShowOrientationCube()
424 -  
425 self.interactor.Render() 352 self.interactor.Render()
426 353
  354 + def LoadSlicePlane(self, pubsub_evt):
  355 + self.slice_plane = SlicePlane()
  356 +
  357 + def LoadVolume(self, pubsub_evt):
  358 + self.raycasting_volume = True
  359 +
  360 + volume = pubsub_evt.data[0]
  361 + colour = pubsub_evt.data[1]
  362 + ww, wl = pubsub_evt.data[2]
  363 +
  364 + self.light = self.ren.GetLights().GetNextItem()
  365 +
  366 + self.ren.AddVolume(volume)
  367 + self.text.SetValue("WL: %d WW: %d"%(wl, ww))
  368 + self.ren.AddActor(self.text.actor)
  369 + self.ren.SetBackground(colour)
  370 +
  371 + if not (self.view_angle):
  372 + self.SetViewAngle(const.VOL_FRONT)
  373 + else:
  374 + self.ren.ResetCamera()
  375 + self.ren.ResetCameraClippingRange()
  376 +
  377 + self.UpdateRender()
  378 +
427 def OnSetViewAngle(self, evt_pubsub): 379 def OnSetViewAngle(self, evt_pubsub):
428 view = evt_pubsub.data 380 view = evt_pubsub.data
429 self.SetViewAngle(view) 381 self.SetViewAngle(view)
430 382
431 def SetViewAngle(self, view): 383 def SetViewAngle(self, view):
432 -  
433 cam = self.ren.GetActiveCamera() 384 cam = self.ren.GetActiveCamera()
434 cam.SetFocalPoint(0,0,0) 385 cam.SetFocalPoint(0,0,0)
435 - 386 +
436 proj = prj.Project() 387 proj = prj.Project()
437 orig_orien = proj.original_orientation 388 orig_orien = proj.original_orientation
438 - 389 +
439 xv,yv,zv = const.VOLUME_POSITION[orig_orien][0][view] 390 xv,yv,zv = const.VOLUME_POSITION[orig_orien][0][view]
440 xp,yp,zp = const.VOLUME_POSITION[orig_orien][1][view] 391 xp,yp,zp = const.VOLUME_POSITION[orig_orien][1][view]
441 - 392 +
442 cam.SetViewUp(xv,yv,zv) 393 cam.SetViewUp(xv,yv,zv)
443 cam.SetPosition(xp,yp,zp) 394 cam.SetPosition(xp,yp,zp)
444 - 395 +
445 self.ren.ResetCameraClippingRange() 396 self.ren.ResetCameraClippingRange()
446 self.ren.ResetCamera() 397 self.ren.ResetCamera()
447 self.interactor.Render() 398 self.interactor.Render()
448 399
  400 + def ShowOrientationCube(self):
  401 + print "ORIENTATION CUBE!"
  402 + cube = vtk.vtkAnnotatedCubeActor()
  403 + cube.GetXMinusFaceProperty().SetColor(1,0,0)
  404 + cube.GetXPlusFaceProperty().SetColor(1,0,0)
  405 + cube.GetYMinusFaceProperty().SetColor(0,1,0)
  406 + cube.GetYPlusFaceProperty().SetColor(0,1,0)
  407 + cube.GetZMinusFaceProperty().SetColor(0,0,1)
  408 + cube.GetZPlusFaceProperty().SetColor(0,0,1)
  409 + cube.GetTextEdgesProperty().SetColor(0,0,0)
  410 +
  411 + # anatomic labelling
  412 + cube.SetXPlusFaceText ("A")
  413 + cube.SetXMinusFaceText("P")
  414 + cube.SetYPlusFaceText ("L")
  415 + cube.SetYMinusFaceText("R")
  416 + cube.SetZPlusFaceText ("S")
  417 + cube.SetZMinusFaceText("I")
  418 +
  419 + axes = vtk.vtkAxesActor()
  420 + axes.SetShaftTypeToCylinder()
  421 + axes.SetTipTypeToCone()
  422 + axes.SetXAxisLabelText("X")
  423 + axes.SetYAxisLabelText("Y")
  424 + axes.SetZAxisLabelText("Z")
  425 + #axes.SetNormalizedLabelPosition(.5, .5, .5)
  426 +
  427 + orientation_widget = vtk.vtkOrientationMarkerWidget()
  428 + orientation_widget.SetOrientationMarker(cube)
  429 + orientation_widget.SetViewport(0.85,0.85,1.0,1.0)
  430 + #orientation_widget.SetOrientationMarker(axes)
  431 + orientation_widget.SetInteractor(self.interactor)
  432 + orientation_widget.SetEnabled(1)
  433 + orientation_widget.On()
  434 + orientation_widget.InteractiveOff()
  435 +
449 def UpdateRender(self, evt_pubsub=None): 436 def UpdateRender(self, evt_pubsub=None):
450 self.interactor.Render() 437 self.interactor.Render()
451 - 438 +
452 def SetWidgetInteractor(self, evt_pubsub=None): 439 def SetWidgetInteractor(self, evt_pubsub=None):
453 evt_pubsub.data.SetInteractor(self.interactor._Iren) 440 evt_pubsub.data.SetInteractor(self.interactor._Iren)
454 441
455 def AppendActor(self, evt_pubsub=None): 442 def AppendActor(self, evt_pubsub=None):
456 self.ren.AddActor(evt_pubsub.data) 443 self.ren.AddActor(evt_pubsub.data)
457 444
  445 +
458 class SlicePlane: 446 class SlicePlane:
459 def __init__(self): 447 def __init__(self):
460 project = prj.Project() 448 project = prj.Project()
@@ -462,22 +450,20 @@ class SlicePlane: @@ -462,22 +450,20 @@ class SlicePlane:
462 self.Create() 450 self.Create()
463 self.__bind_evt() 451 self.__bind_evt()
464 self.__bind_vtk_evt() 452 self.__bind_vtk_evt()
465 - 453 +
466 def __bind_evt(self): 454 def __bind_evt(self):
467 ps.Publisher().subscribe(self.Enable, 'Enable plane') 455 ps.Publisher().subscribe(self.Enable, 'Enable plane')
468 ps.Publisher().subscribe(self.Disable, 'Disable plane') 456 ps.Publisher().subscribe(self.Disable, 'Disable plane')
469 ps.Publisher().subscribe(self.ChangeSlice, 'Change slice from slice plane') 457 ps.Publisher().subscribe(self.ChangeSlice, 'Change slice from slice plane')
470 - 458 +
471 def __bind_vtk_evt(self): 459 def __bind_vtk_evt(self):
472 self.plane_x.AddObserver("InteractionEvent", self.PlaneEvent) 460 self.plane_x.AddObserver("InteractionEvent", self.PlaneEvent)
473 self.plane_y.AddObserver("InteractionEvent", self.PlaneEvent) 461 self.plane_y.AddObserver("InteractionEvent", self.PlaneEvent)
474 self.plane_z.AddObserver("InteractionEvent", self.PlaneEvent) 462 self.plane_z.AddObserver("InteractionEvent", self.PlaneEvent)
475 - 463 +
476 def PlaneEvent(self, obj, evt): 464 def PlaneEvent(self, obj, evt):
477 -  
478 number = obj.GetSliceIndex() 465 number = obj.GetSliceIndex()
479 plane_axis = obj.GetPlaneOrientation() 466 plane_axis = obj.GetPlaneOrientation()
480 -  
481 if (self.original_orientation == const.AXIAL): 467 if (self.original_orientation == const.AXIAL):
482 if (plane_axis == 0): 468 if (plane_axis == 0):
483 orientation = "SAGITAL" 469 orientation = "SAGITAL"
@@ -487,7 +473,7 @@ class SlicePlane: @@ -487,7 +473,7 @@ class SlicePlane:
487 number = abs(dimen[0] - (number + 1)) 473 number = abs(dimen[0] - (number + 1))
488 else: 474 else:
489 orientation = "AXIAL" 475 orientation = "AXIAL"
490 - 476 +
491 elif(self.original_orientation == const.SAGITAL): 477 elif(self.original_orientation == const.SAGITAL):
492 if (plane_axis == 0): 478 if (plane_axis == 0):
493 orientation = "CORONAL" 479 orientation = "CORONAL"
@@ -506,14 +492,12 @@ class SlicePlane: @@ -506,14 +492,12 @@ class SlicePlane:
506 number = abs(dimen[0] - (number + 1)) 492 number = abs(dimen[0] - (number + 1))
507 else: 493 else:
508 orientation = "CORONAL" 494 orientation = "CORONAL"
509 -  
510 - 495 +
511 if (obj.GetSlicePosition() != 0.0): 496 if (obj.GetSlicePosition() != 0.0):
512 ps.Publisher().sendMessage(('Set scroll position', \ 497 ps.Publisher().sendMessage(('Set scroll position', \
513 orientation), number) 498 orientation), number)
514 -  
515 - def Create(self):  
516 499
  500 + def Create(self):
517 plane_x = self.plane_x = vtk.vtkImagePlaneWidget() 501 plane_x = self.plane_x = vtk.vtkImagePlaneWidget()
518 plane_x.DisplayTextOff() 502 plane_x.DisplayTextOff()
519 ps.Publisher().sendMessage('Input Image in the widget', plane_x) 503 ps.Publisher().sendMessage('Input Image in the widget', plane_x)
@@ -537,7 +521,7 @@ class SlicePlane: @@ -537,7 +521,7 @@ class SlicePlane:
537 prop1.SetColor(0, 1, 0) 521 prop1.SetColor(0, 1, 0)
538 cursor_property = plane_y.GetCursorProperty() 522 cursor_property = plane_y.GetCursorProperty()
539 cursor_property.SetOpacity(0) 523 cursor_property.SetOpacity(0)
540 - 524 +
541 plane_z = self.plane_z = vtk.vtkImagePlaneWidget() 525 plane_z = self.plane_z = vtk.vtkImagePlaneWidget()
542 plane_z.DisplayTextOff() 526 plane_z.DisplayTextOff()
543 ps.Publisher().sendMessage('Input Image in the widget', plane_z) 527 ps.Publisher().sendMessage('Input Image in the widget', plane_z)
@@ -556,40 +540,40 @@ class SlicePlane: @@ -556,40 +540,40 @@ class SlicePlane:
556 540
557 prop1 = plane_x.GetPlaneProperty() 541 prop1 = plane_x.GetPlaneProperty()
558 prop1.SetColor(0, 0, 1) 542 prop1.SetColor(0, 0, 1)
559 - 543 +
560 prop2 = plane_y.GetPlaneProperty() 544 prop2 = plane_y.GetPlaneProperty()
561 prop2.SetColor(0, 1, 0) 545 prop2.SetColor(0, 1, 0)
562 - 546 +
563 elif(self.original_orientation == const.SAGITAL): 547 elif(self.original_orientation == const.SAGITAL):
564 prop3 = plane_y.GetPlaneProperty() 548 prop3 = plane_y.GetPlaneProperty()
565 prop3.SetColor(1, 0, 0) 549 prop3.SetColor(1, 0, 0)
566 550
567 prop1 = plane_z.GetPlaneProperty() 551 prop1 = plane_z.GetPlaneProperty()
568 prop1.SetColor(0, 0, 1) 552 prop1.SetColor(0, 0, 1)
569 - 553 +
570 prop2 = plane_x.GetPlaneProperty() 554 prop2 = plane_x.GetPlaneProperty()
571 prop2.SetColor(0, 1, 0) 555 prop2.SetColor(0, 1, 0)
572 - 556 +
573 else: 557 else:
574 prop3 = plane_y.GetPlaneProperty() 558 prop3 = plane_y.GetPlaneProperty()
575 prop3.SetColor(1, 0, 0) 559 prop3.SetColor(1, 0, 0)
576 560
577 prop1 = plane_x.GetPlaneProperty() 561 prop1 = plane_x.GetPlaneProperty()
578 prop1.SetColor(0, 0, 1) 562 prop1.SetColor(0, 0, 1)
579 - 563 +
580 prop2 = plane_z.GetPlaneProperty() 564 prop2 = plane_z.GetPlaneProperty()
581 prop2.SetColor(0, 1, 0) 565 prop2.SetColor(0, 1, 0)
582 - 566 +
583 ps.Publisher().sendMessage('Set Widget Interactor', plane_x) 567 ps.Publisher().sendMessage('Set Widget Interactor', plane_x)
584 ps.Publisher().sendMessage('Set Widget Interactor', plane_y) 568 ps.Publisher().sendMessage('Set Widget Interactor', plane_y)
585 ps.Publisher().sendMessage('Set Widget Interactor', plane_z) 569 ps.Publisher().sendMessage('Set Widget Interactor', plane_z)
586 - 570 +
587 self.Render() 571 self.Render()
588 - 572 +
589 def Enable(self, evt_pubsub=None): 573 def Enable(self, evt_pubsub=None):
590 if (evt_pubsub): 574 if (evt_pubsub):
591 label = evt_pubsub.data 575 label = evt_pubsub.data
592 - 576 +
593 if(self.original_orientation == const.AXIAL): 577 if(self.original_orientation == const.AXIAL):
594 if(label == "Axial"): 578 if(label == "Axial"):
595 self.plane_z.On() 579 self.plane_z.On()
@@ -602,7 +586,7 @@ class SlicePlane: @@ -602,7 +586,7 @@ class SlicePlane:
602 c = self.plane_x.GetTexture() 586 c = self.plane_x.GetTexture()
603 c.SetRestrictPowerOf2ImageSmaller(1) 587 c.SetRestrictPowerOf2ImageSmaller(1)
604 #print dir(a) 588 #print dir(a)
605 - 589 +
606 elif(self.original_orientation == const.SAGITAL): 590 elif(self.original_orientation == const.SAGITAL):
607 if(label == "Axial"): 591 if(label == "Axial"):
608 self.plane_y.On() 592 self.plane_y.On()
@@ -617,7 +601,7 @@ class SlicePlane: @@ -617,7 +601,7 @@ class SlicePlane:
617 self.plane_z.On() 601 self.plane_z.On()
618 elif(label == "Sagital"): 602 elif(label == "Sagital"):
619 self.plane_x.On() 603 self.plane_x.On()
620 - 604 +
621 else: 605 else:
622 self.plane_z.On() 606 self.plane_z.On()
623 self.plane_x.On() 607 self.plane_x.On()
@@ -628,7 +612,7 @@ class SlicePlane: @@ -628,7 +612,7 @@ class SlicePlane:
628 def Disable(self, evt_pubsub=None): 612 def Disable(self, evt_pubsub=None):
629 if (evt_pubsub): 613 if (evt_pubsub):
630 label = evt_pubsub.data 614 label = evt_pubsub.data
631 - 615 +
632 if(self.original_orientation == const.AXIAL): 616 if(self.original_orientation == const.AXIAL):
633 if(label == "Axial"): 617 if(label == "Axial"):
634 self.plane_z.Off() 618 self.plane_z.Off()
@@ -636,7 +620,7 @@ class SlicePlane: @@ -636,7 +620,7 @@ class SlicePlane:
636 self.plane_y.Off() 620 self.plane_y.Off()
637 elif(label == "Sagital"): 621 elif(label == "Sagital"):
638 self.plane_x.Off() 622 self.plane_x.Off()
639 - 623 +
640 elif(self.original_orientation == const.SAGITAL): 624 elif(self.original_orientation == const.SAGITAL):
641 if(label == "Axial"): 625 if(label == "Axial"):
642 self.plane_y.Off() 626 self.plane_y.Off()
@@ -658,13 +642,12 @@ class SlicePlane: @@ -658,13 +642,12 @@ class SlicePlane:
658 642
659 self.Render() 643 self.Render()
660 644
661 -  
662 def Render(self): 645 def Render(self):
663 ps.Publisher().sendMessage('Render volume viewer') 646 ps.Publisher().sendMessage('Render volume viewer')
664 - 647 +
665 def ChangeSlice(self, pubsub_evt = None): 648 def ChangeSlice(self, pubsub_evt = None):
666 orientation, number = pubsub_evt.data 649 orientation, number = pubsub_evt.data
667 - 650 +
668 if (self.original_orientation == const.AXIAL): 651 if (self.original_orientation == const.AXIAL):
669 if (orientation == "CORONAL"): 652 if (orientation == "CORONAL"):
670 self.SetSliceNumber(number, "Y") 653 self.SetSliceNumber(number, "Y")
@@ -672,7 +655,7 @@ class SlicePlane: @@ -672,7 +655,7 @@ class SlicePlane:
672 self.SetSliceNumber(number, "X") 655 self.SetSliceNumber(number, "X")
673 else: 656 else:
674 self.SetSliceNumber(number, "Z") 657 self.SetSliceNumber(number, "Z")
675 - 658 +
676 elif(self.original_orientation == const.SAGITAL): 659 elif(self.original_orientation == const.SAGITAL):
677 if (orientation == "CORONAL"): 660 if (orientation == "CORONAL"):
678 self.SetSliceNumber(number, "X") 661 self.SetSliceNumber(number, "X")
@@ -680,7 +663,7 @@ class SlicePlane: @@ -680,7 +663,7 @@ class SlicePlane:
680 self.SetSliceNumber(number, "Z") 663 self.SetSliceNumber(number, "Z")
681 else: 664 else:
682 self.SetSliceNumber(number, "Y") 665 self.SetSliceNumber(number, "Y")
683 - 666 +
684 else: 667 else:
685 if (orientation == "CORONAL"): 668 if (orientation == "CORONAL"):
686 self.SetSliceNumber(number, "Z") 669 self.SetSliceNumber(number, "Z")
@@ -688,9 +671,9 @@ class SlicePlane: @@ -688,9 +671,9 @@ class SlicePlane:
688 self.SetSliceNumber(number, "X") 671 self.SetSliceNumber(number, "X")
689 else: 672 else:
690 self.SetSliceNumber(number, "Y") 673 self.SetSliceNumber(number, "Y")
691 - 674 +
692 self.Render() 675 self.Render()
693 - 676 +
694 def SetSliceNumber(self, number, axis): 677 def SetSliceNumber(self, number, axis):
695 if (axis == "X"): 678 if (axis == "X"):
696 self.plane_x.SetPlaneOrientationToXAxes() 679 self.plane_x.SetPlaneOrientationToXAxes()
@@ -702,14 +685,12 @@ class SlicePlane: @@ -702,14 +685,12 @@ class SlicePlane:
702 self.plane_z.SetPlaneOrientationToZAxes() 685 self.plane_z.SetPlaneOrientationToZAxes()
703 self.plane_z.SetSliceIndex(number) 686 self.plane_z.SetSliceIndex(number)
704 687
705 -  
706 def PointId(self, evt, obj): 688 def PointId(self, evt, obj):
707 #TODO: add in the code 689 #TODO: add in the code
708 # picker = vtk.vtkPointPicker() 690 # picker = vtk.vtkPointPicker()
709 # interactor.SetPicker(picker) 691 # interactor.SetPicker(picker)
710 # interactor.AddObserver("left...", self.PointId) 692 # interactor.AddObserver("left...", self.PointId)
711 -  
712 x,y = evt.GetLastEventPosition() 693 x,y = evt.GetLastEventPosition()
713 self.picker.Pick(x, y, 0, self.ren1) 694 self.picker.Pick(x, y, 0, self.ren1)
714 point_id = self.picker.GetPointId() 695 point_id = self.picker.GetPointId()
715 - 696 +