Commit 57c41ef5d96a613412a70bec057b5ac7660659b6
1 parent
2794a7ed
Exists in
master
and in
68 other branches
ADD: Volume raycasting cut plane enable/disable as volume is shown/hiden
Showing
1 changed file
with
26 additions
and
16 deletions
Show diff stats
invesalius/data/volume.py
... | ... | @@ -76,13 +76,11 @@ class Volume(): |
76 | 76 | self.wl = None |
77 | 77 | self.n = 0 |
78 | 78 | self.plane = None |
79 | + self.plane_on = False | |
79 | 80 | |
80 | 81 | self.__bind_events() |
81 | 82 | |
82 | 83 | def __bind_events(self): |
83 | - #ps.Publisher().subscribe(self.OnLoadVolume, 'Create volume raycasting') | |
84 | - #ps.Publisher().subscribe(self.OnShowVolume, | |
85 | - # 'Show raycasting volume') | |
86 | 84 | ps.Publisher().subscribe(self.OnHideVolume, |
87 | 85 | 'Hide raycasting volume') |
88 | 86 | ps.Publisher().subscribe(self.OnUpdatePreset, |
... | ... | @@ -102,12 +100,19 @@ class Volume(): |
102 | 100 | self.LoadVolume() |
103 | 101 | |
104 | 102 | def OnHideVolume(self, pubsub_evt): |
103 | + print "Hide", self.plane, self.plane_on | |
105 | 104 | self.volume.SetVisibility(0) |
105 | + if (self.plane and self.plane_on): | |
106 | + print "--- Hide Plane" | |
107 | + self.plane.Disable() | |
106 | 108 | ps.Publisher().sendMessage('Render volume viewer') |
107 | 109 | |
108 | 110 | def OnShowVolume(self, pubsub_evt): |
109 | 111 | if self.exist: |
110 | 112 | self.volume.SetVisibility(1) |
113 | + if (self.plane and self.plane_on): | |
114 | + print "----- Show Plane" | |
115 | + self.plane.Enable() | |
111 | 116 | ps.Publisher().sendMessage('Render volume viewer') |
112 | 117 | else: |
113 | 118 | ps.Publisher.sendMessage('Load raycasting preset', const.RAYCASTING_LABEL) |
... | ... | @@ -125,6 +130,9 @@ class Volume(): |
125 | 130 | self.LoadVolume() |
126 | 131 | self.exist = 1 |
127 | 132 | |
133 | + if (self.plane and self.plane_on): | |
134 | + self.plane.Enable() | |
135 | + | |
128 | 136 | def __load_preset_config(self): |
129 | 137 | self.config = prj.Project().raycasting_preset |
130 | 138 | |
... | ... | @@ -470,11 +478,13 @@ class Volume(): |
470 | 478 | if tool_name == "Cut plane": |
471 | 479 | if self.plane: |
472 | 480 | if enable: |
473 | - self.plane.EnablePlane() | |
481 | + self.plane_on = True | |
482 | + self.plane.Enable() | |
474 | 483 | else: |
475 | - print "TODO: Desabilitar plano" | |
476 | - self.plane.DisablePlane() | |
484 | + self.plane_on = False | |
485 | + self.plane.Disable() | |
477 | 486 | else: |
487 | + self.plane_on = True | |
478 | 488 | self.plane = CutPlane(self.final_imagedata, |
479 | 489 | self.volume_mapper) |
480 | 490 | |
... | ... | @@ -491,18 +501,18 @@ class CutPlane: |
491 | 501 | def __init__(self, img, volume_mapper): |
492 | 502 | self.img = img |
493 | 503 | self.volume_mapper = volume_mapper |
494 | - self.CreatePlane() | |
504 | + self.Create() | |
495 | 505 | self.__bind_events() |
496 | 506 | |
497 | 507 | def __bind_events(self): |
498 | - ps.Publisher().subscribe(self.ResetPlane, | |
508 | + ps.Publisher().subscribe(self.Reset, | |
499 | 509 | 'Reset Cut Plane') |
500 | - ps.Publisher().subscribe(self.EnablePlane, | |
510 | + ps.Publisher().subscribe(self.Enable, | |
501 | 511 | 'Enable Cut Plane') |
502 | - ps.Publisher().subscribe(self.DisablePlane, | |
512 | + ps.Publisher().subscribe(self.Disable, | |
503 | 513 | 'Disable Cut Plane') |
504 | 514 | |
505 | - def CreatePlane(self): | |
515 | + def Create(self): | |
506 | 516 | self.plane_widget = plane_widget = vtk.vtkImagePlaneWidget() |
507 | 517 | plane_widget.SetInput(self.img) |
508 | 518 | plane_widget.SetPlaneOrientationToXAxes() |
... | ... | @@ -527,7 +537,7 @@ class CutPlane: |
527 | 537 | plane_actor.SetMapper(plane_mapper) |
528 | 538 | plane_actor.GetProperty().BackfaceCullingOn() |
529 | 539 | plane_actor.GetProperty().SetOpacity(0) |
530 | - plane_widget.AddObserver("InteractionEvent", self.UpdatePlane) | |
540 | + plane_widget.AddObserver("InteractionEvent", self.Update) | |
531 | 541 | ps.Publisher().sendMessage('AppendActor', self.plane_actor) |
532 | 542 | ps.Publisher().sendMessage('Set Widget Interactor', self.plane_widget) |
533 | 543 | plane_actor.SetVisibility(1) |
... | ... | @@ -542,7 +552,7 @@ class CutPlane: |
542 | 552 | self.p2 = plane_widget.GetPoint2() |
543 | 553 | self.normal = plane_widget.GetNormal() |
544 | 554 | |
545 | - def UpdatePlane(self, a, b): | |
555 | + def Update(self, a, b): | |
546 | 556 | plane_source = self.plane_source |
547 | 557 | plane_widget = self.plane_widget |
548 | 558 | plane_source.SetOrigin(plane_widget.GetOrigin()) |
... | ... | @@ -554,19 +564,19 @@ class CutPlane: |
554 | 564 | self.plane.SetOrigin(plane_source.GetOrigin()) |
555 | 565 | ps.Publisher().sendMessage('Render volume viewer', None) |
556 | 566 | |
557 | - def EnablePlane(self, evt_pubsub=None): | |
567 | + def Enable(self, evt_pubsub=None): | |
558 | 568 | self.plane_widget.On() |
559 | 569 | self.plane_actor.VisibilityOn() |
560 | 570 | self.volume_mapper.RemoveClippingPlane(self.plane) |
561 | 571 | ps.Publisher().sendMessage('Render volume viewer', None) |
562 | 572 | |
563 | - def DisablePlane(self,evt_pubsub=None): | |
573 | + def Disable(self,evt_pubsub=None): | |
564 | 574 | self.plane_widget.Off() |
565 | 575 | self.plane_actor.VisibilityOff() |
566 | 576 | self.volume_mapper.AddClippingPlane(self.plane) |
567 | 577 | ps.Publisher().sendMessage('Render volume viewer', None) |
568 | 578 | |
569 | - def ResetPlane(self, evt_pubsub=None): | |
579 | + def Reset(self, evt_pubsub=None): | |
570 | 580 | plane_source = self.plane_source |
571 | 581 | plane_widget = self.plane_widget |
572 | 582 | plane_source.SetOrigin(self.origin) | ... | ... |