Commit 233d55c0d8981d6105b53090e691b6c7ed9f5777
1 parent
e64f9318
Exists in
master
and in
68 other branches
FIX: Raycasting startup (show WW/WL, bkg colour)
Showing
3 changed files
with
44 additions
and
18 deletions
Show diff stats
invesalius/data/viewer_volume.py
| @@ -60,15 +60,20 @@ class Viewer(wx.Panel): | @@ -60,15 +60,20 @@ class Viewer(wx.Panel): | ||
| 60 | self.interactor = interactor | 60 | self.interactor = interactor |
| 61 | self.ren = ren | 61 | self.ren = ren |
| 62 | 62 | ||
| 63 | + self.raycasting_volume = False | ||
| 64 | + | ||
| 63 | self.onclick = False | 65 | self.onclick = False |
| 64 | 66 | ||
| 67 | + self.text = vtku.Text() | ||
| 68 | + | ||
| 69 | + self.view_angle = None | ||
| 70 | + | ||
| 65 | self.__bind_events() | 71 | self.__bind_events() |
| 66 | self.__bind_events_wx() | 72 | self.__bind_events_wx() |
| 67 | 73 | ||
| 68 | - self.view_angle = None | ||
| 69 | - | 74 | + |
| 70 | def OnMove(self, obj, evt): | 75 | def OnMove(self, obj, evt): |
| 71 | - if self.onclick: | 76 | + if self.onclick and self.raycasting_volume: |
| 72 | mouse_x, mouse_y = self.interactor.GetEventPosition() | 77 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
| 73 | diff_x = mouse_x - self.last_x | 78 | diff_x = mouse_x - self.last_x |
| 74 | diff_y = mouse_y - self.last_y | 79 | diff_y = mouse_y - self.last_y |
| @@ -92,15 +97,22 @@ class Viewer(wx.Panel): | @@ -92,15 +97,22 @@ class Viewer(wx.Panel): | ||
| 92 | 'Render volume viewer') | 97 | 'Render volume viewer') |
| 93 | ps.Publisher().subscribe(self.ChangeBackgroundColour, | 98 | ps.Publisher().subscribe(self.ChangeBackgroundColour, |
| 94 | 'Change volume viewer background colour') | 99 | 'Change volume viewer background colour') |
| 100 | + # Raycating - related | ||
| 95 | ps.Publisher().subscribe(self.LoadVolume, | 101 | ps.Publisher().subscribe(self.LoadVolume, |
| 96 | 'Load volume into viewer') | 102 | 'Load volume into viewer') |
| 103 | + ps.Publisher().subscribe(self.OnSetWindowLevelText, | ||
| 104 | + 'Set volume window and level text') | ||
| 105 | + ps.Publisher().subscribe(self.OnHideRaycasting, | ||
| 106 | + 'Hide raycasting volume') | ||
| 107 | + ps.Publisher().subscribe(self.OnShowRaycasting, | ||
| 108 | + 'Update raycasting preset') | ||
| 109 | + ### | ||
| 97 | ps.Publisher().subscribe(self.AppendActor,'AppendActor') | 110 | ps.Publisher().subscribe(self.AppendActor,'AppendActor') |
| 98 | ps.Publisher().subscribe(self.SetWidgetInteractor, | 111 | ps.Publisher().subscribe(self.SetWidgetInteractor, |
| 99 | 'Set Widget Interactor') | 112 | 'Set Widget Interactor') |
| 100 | ps.Publisher().subscribe(self.OnSetViewAngle, | 113 | ps.Publisher().subscribe(self.OnSetViewAngle, |
| 101 | 'Set volume view angle') | 114 | 'Set volume view angle') |
| 102 | - ps.Publisher().subscribe(self.OnSetWindowLevelText, | ||
| 103 | - 'Set volume window and level text') | 115 | + |
| 104 | ps.Publisher().subscribe(self.OnEnableBrightContrast, | 116 | ps.Publisher().subscribe(self.OnEnableBrightContrast, |
| 105 | ('Set interaction mode', const.MODE_WW_WL)) | 117 | ('Set interaction mode', const.MODE_WW_WL)) |
| 106 | ps.Publisher().subscribe(self.OnDisableBrightContrast, | 118 | ps.Publisher().subscribe(self.OnDisableBrightContrast, |
| @@ -133,19 +145,33 @@ class Viewer(wx.Panel): | @@ -133,19 +145,33 @@ class Viewer(wx.Panel): | ||
| 133 | evt.Skip() | 145 | evt.Skip() |
| 134 | 146 | ||
| 135 | def OnSetWindowLevelText(self, pubsub_evt): | 147 | def OnSetWindowLevelText(self, pubsub_evt): |
| 136 | - ww, wl = pubsub_evt.data | ||
| 137 | - self.text.SetValue("WL: %d WW: %d"%(wl, ww)) | 148 | + if self.raycasting_volume: |
| 149 | + ww, wl = pubsub_evt.data | ||
| 150 | + self.text.SetValue("WL: %d WW: %d"%(wl, ww)) | ||
| 151 | + | ||
| 152 | + def OnShowRaycasting(self, pubsub_evt): | ||
| 153 | + self.raycasting_volume = True | ||
| 154 | + self.text.Show() | ||
| 155 | + | ||
| 156 | + def OnHideRaycasting(self, pubsub_evt): | ||
| 157 | + self.raycasting_volume = False | ||
| 158 | + self.text.Hide() | ||
| 138 | 159 | ||
| 139 | def LoadVolume(self, pubsub_evt): | 160 | def LoadVolume(self, pubsub_evt): |
| 161 | + self.raycasting_volume = True | ||
| 162 | + | ||
| 140 | volume = pubsub_evt.data[0] | 163 | volume = pubsub_evt.data[0] |
| 164 | + colour = pubsub_evt.data[1] | ||
| 165 | + ww, wl = pubsub_evt.data[2] | ||
| 166 | + | ||
| 141 | self.light = self.ren.GetLights().GetNextItem() | 167 | self.light = self.ren.GetLights().GetNextItem() |
| 142 | 168 | ||
| 143 | - text = vtku.Text() | ||
| 144 | - self.text = text | ||
| 145 | - | ||
| 146 | self.ren.AddVolume(volume) | 169 | self.ren.AddVolume(volume) |
| 147 | - self.ren.AddActor(text.actor) | ||
| 148 | - | 170 | + self.text.SetValue("WL: %d WW: %d"%(wl, ww)) |
| 171 | + self.ren.AddActor(self.text.actor) | ||
| 172 | + self.ren.SetBackground(colour) | ||
| 173 | + | ||
| 174 | + | ||
| 149 | if not (self.view_angle): | 175 | if not (self.view_angle): |
| 150 | self.SetViewAngle(const.VOL_FRONT) | 176 | self.SetViewAngle(const.VOL_FRONT) |
| 151 | else: | 177 | else: |
invesalius/data/volume.py
| @@ -100,10 +100,8 @@ class Volume(): | @@ -100,10 +100,8 @@ class Volume(): | ||
| 100 | self.LoadVolume() | 100 | self.LoadVolume() |
| 101 | 101 | ||
| 102 | def OnHideVolume(self, pubsub_evt): | 102 | def OnHideVolume(self, pubsub_evt): |
| 103 | - print "Hide", self.plane, self.plane_on | ||
| 104 | self.volume.SetVisibility(0) | 103 | self.volume.SetVisibility(0) |
| 105 | if (self.plane and self.plane_on): | 104 | if (self.plane and self.plane_on): |
| 106 | - print "--- Hide Plane" | ||
| 107 | self.plane.Disable() | 105 | self.plane.Disable() |
| 108 | ps.Publisher().sendMessage('Render volume viewer') | 106 | ps.Publisher().sendMessage('Render volume viewer') |
| 109 | 107 | ||
| @@ -111,7 +109,6 @@ class Volume(): | @@ -111,7 +109,6 @@ class Volume(): | ||
| 111 | if self.exist: | 109 | if self.exist: |
| 112 | self.volume.SetVisibility(1) | 110 | self.volume.SetVisibility(1) |
| 113 | if (self.plane and self.plane_on): | 111 | if (self.plane and self.plane_on): |
| 114 | - print "----- Show Plane" | ||
| 115 | self.plane.Enable() | 112 | self.plane.Enable() |
| 116 | ps.Publisher().sendMessage('Render volume viewer') | 113 | ps.Publisher().sendMessage('Render volume viewer') |
| 117 | else: | 114 | else: |
| @@ -162,7 +159,6 @@ class Volume(): | @@ -162,7 +159,6 @@ class Volume(): | ||
| 162 | 159 | ||
| 163 | def OnSetRelativeWindowLevel(self, pubsub_evt): | 160 | def OnSetRelativeWindowLevel(self, pubsub_evt): |
| 164 | diff_ww, diff_wl = pubsub_evt.data | 161 | diff_ww, diff_wl = pubsub_evt.data |
| 165 | - print diff_ww | ||
| 166 | ww = self.ww + diff_ww | 162 | ww = self.ww + diff_ww |
| 167 | wl = self.wl + diff_wl | 163 | wl = self.wl + diff_wl |
| 168 | ps.Publisher().sendMessage('Set volume window and level text', | 164 | ps.Publisher().sendMessage('Set volume window and level text', |
| @@ -365,7 +361,6 @@ class Volume(): | @@ -365,7 +361,6 @@ class Volume(): | ||
| 365 | def ApplyConvolution(self, imagedata): | 361 | def ApplyConvolution(self, imagedata): |
| 366 | number_filters = len(self.config['convolutionFilters']) | 362 | number_filters = len(self.config['convolutionFilters']) |
| 367 | for filter in self.config['convolutionFilters']: | 363 | for filter in self.config['convolutionFilters']: |
| 368 | - print "convolving", filter | ||
| 369 | convolve = vtk.vtkImageConvolve() | 364 | convolve = vtk.vtkImageConvolve() |
| 370 | convolve.SetInput(imagedata) | 365 | convolve.SetInput(imagedata) |
| 371 | convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) | 366 | convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) |
| @@ -471,7 +466,9 @@ class Volume(): | @@ -471,7 +466,9 @@ class Volume(): | ||
| 471 | self.volume = volume | 466 | self.volume = volume |
| 472 | 467 | ||
| 473 | colour = self.GetBackgroundColour() | 468 | colour = self.GetBackgroundColour() |
| 474 | - ps.Publisher().sendMessage('Load volume into viewer', (volume, colour)) | 469 | + |
| 470 | + ps.Publisher().sendMessage('Load volume into viewer', | ||
| 471 | + (volume, colour, (self.ww, self.wl))) | ||
| 475 | 472 | ||
| 476 | def OnEnableTool(self, pubsub_evt): | 473 | def OnEnableTool(self, pubsub_evt): |
| 477 | tool_name, enable = pubsub_evt.data | 474 | tool_name, enable = pubsub_evt.data |
invesalius/data/vtk_utils.py