Commit f55f424118149ff21850e80661d8f87b49d96bfe
1 parent
d176f8ec
Exists in
master
and in
6 other branches
ADD: Applying Victor's patch to add support and operations to navigator
Showing
3 changed files
with
487 additions
and
42 deletions
Show diff stats
invesalius/data/viewer_slice.py
... | ... | @@ -230,8 +230,10 @@ class Viewer(wx.Panel): |
230 | 230 | } |
231 | 231 | if state == const.SLICE_STATE_CROSS: |
232 | 232 | self.__set_cross_visibility(1) |
233 | + ps.Publisher().sendMessage('Activate ball reference') | |
233 | 234 | else: |
234 | 235 | self.__set_cross_visibility(0) |
236 | + ps.Publisher().sendMessage('Deactivate ball reference') | |
235 | 237 | |
236 | 238 | if state == const.STATE_WL: |
237 | 239 | self.on_wl = True |
... | ... | @@ -704,10 +706,25 @@ class Viewer(wx.Panel): |
704 | 706 | coord = self.CalcultateScrollPosition(coord_cross) |
705 | 707 | ps.Publisher().sendMessage('Update cross position', |
706 | 708 | (self.orientation, coord_cross)) |
709 | + ps.Publisher().sendMessage('Set ball reference position based on bound', coord_cross) | |
710 | + ps.Publisher().sendMessage('Set camera in volume', coord_cross) | |
711 | + ps.Publisher().sendMessage('Render volume viewer') | |
712 | + | |
707 | 713 | print "Scroll to", coord |
708 | 714 | self.ScrollSlice(coord) |
709 | 715 | self.interactor.Render() |
710 | 716 | |
717 | + def Navigation(self, pubsub_evt): | |
718 | + # Get point from base change | |
719 | + x, y, z = pubsub_evt.data | |
720 | + coord_cross = x, y, z | |
721 | + coord = self.CalcultateScrollPosition(coord_cross) | |
722 | + ps.Publisher().sendMessage('Update cross position', | |
723 | + (self.orientation, coord_cross)) | |
724 | + | |
725 | + self.ScrollSlice(coord) | |
726 | + self.interactor.Render() | |
727 | + | |
711 | 728 | def ScrollSlice(self, coord): |
712 | 729 | if self.orientation == "AXIAL": |
713 | 730 | ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), |
... | ... | @@ -834,6 +851,8 @@ class Viewer(wx.Panel): |
834 | 851 | self.orientation)) |
835 | 852 | ps.Publisher().subscribe(self.__update_cross_position, |
836 | 853 | 'Update cross position') |
854 | + ps.Publisher().subscribe(self.Navigation, | |
855 | + 'Co-registered Points') | |
837 | 856 | ### |
838 | 857 | ps.Publisher().subscribe(self.ChangeBrushSize, |
839 | 858 | 'Set edition brush size') | ... | ... |
invesalius/data/viewer_volume.py
... | ... | @@ -22,12 +22,14 @@ |
22 | 22 | |
23 | 23 | import sys |
24 | 24 | |
25 | +import numpy | |
25 | 26 | import wx |
26 | 27 | import vtk |
27 | 28 | from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor |
28 | 29 | import wx.lib.pubsub as ps |
29 | 30 | |
30 | 31 | import constants as const |
32 | +import data.bases as bases | |
31 | 33 | import data.vtk_utils as vtku |
32 | 34 | import project as prj |
33 | 35 | import style as st |
... | ... | @@ -42,6 +44,9 @@ class Viewer(wx.Panel): |
42 | 44 | |
43 | 45 | self.interaction_style = st.StyleStateManager() |
44 | 46 | |
47 | + self.ball_reference = None | |
48 | + self.initial_foco = None | |
49 | + | |
45 | 50 | style = vtk.vtkInteractorStyleTrackballCamera() |
46 | 51 | self.style = style |
47 | 52 | |
... | ... | @@ -135,6 +140,7 @@ class Viewer(wx.Panel): |
135 | 140 | ps.Publisher().subscribe(self.LoadSlicePlane, 'Load slice plane') |
136 | 141 | |
137 | 142 | ps.Publisher().subscribe(self.ResetCamClippingRange, 'Reset cam clipping range') |
143 | + ps.Publisher().subscribe(self.SetVolumeCamera, 'Set camera in volume') | |
138 | 144 | |
139 | 145 | ps.Publisher().subscribe(self.OnEnableStyle, 'Enable style') |
140 | 146 | ps.Publisher().subscribe(self.OnDisableStyle, 'Disable style') |
... | ... | @@ -157,6 +163,47 @@ class Viewer(wx.Panel): |
157 | 163 | ps.Publisher().subscribe(self.OnStartSeed,'Create surface by seeding - start') |
158 | 164 | ps.Publisher().subscribe(self.OnEndSeed,'Create surface by seeding - end') |
159 | 165 | |
166 | + ps.Publisher().subscribe(self.ActivateBallReference, | |
167 | + 'Activate ball reference') | |
168 | + ps.Publisher().subscribe(self.DeactivateBallReference, | |
169 | + 'Deactivate ball reference') | |
170 | + ps.Publisher().subscribe(self.SetBallReferencePosition, | |
171 | + 'Set ball reference position') | |
172 | + ps.Publisher().subscribe(self.SetBallReferencePositionBasedOnBound, | |
173 | + 'Set ball reference position based on bound') | |
174 | + | |
175 | + def CreateBallReference(self): | |
176 | + self.ball_reference = vtk.vtkSphereSource() | |
177 | + self.ball_reference.SetRadius(5) | |
178 | + | |
179 | + mapper = vtk.vtkPolyDataMapper() | |
180 | + mapper.SetInput(self.ball_reference.GetOutput()) | |
181 | + | |
182 | + p = vtk.vtkProperty() | |
183 | + p.SetColor(1, 0, 0) | |
184 | + | |
185 | + self.ball_actor = vtk.vtkActor() | |
186 | + self.ball_actor.SetMapper(mapper) | |
187 | + self.ball_actor.SetProperty(p) | |
188 | + | |
189 | + def ActivateBallReference(self, pubsub_evt): | |
190 | + if not self.ball_reference: | |
191 | + self.CreateBallReference() | |
192 | + self.ren.AddActor(self.ball_actor) | |
193 | + | |
194 | + def DeactivateBallReference(self, pubsub_evt): | |
195 | + if self.ball_reference: | |
196 | + self.ren.RemoveActor(self.ball_actor) | |
197 | + | |
198 | + def SetBallReferencePosition(self, pubsub_evt): | |
199 | + x, y, z = pubsub_evt.data | |
200 | + self.ball_reference.SetCenter(x, y, z) | |
201 | + | |
202 | + def SetBallReferencePositionBasedOnBound(self, pubsub_evt): | |
203 | + coord = pubsub_evt.data | |
204 | + x, y, z = bases.FlipX(coord) | |
205 | + self.ball_reference.SetCenter(x, y, z) | |
206 | + | |
160 | 207 | def OnStartSeed(self, pubsub_evt): |
161 | 208 | index = pubsub_evt.data |
162 | 209 | self.seed_points = [] |
... | ... | @@ -441,6 +488,31 @@ class Viewer(wx.Panel): |
441 | 488 | self.ren.ResetCamera() |
442 | 489 | self.ren.ResetCameraClippingRange() |
443 | 490 | |
491 | + def SetVolumeCamera(self, pubsub_evt): | |
492 | + | |
493 | + coord_camera = pubsub_evt.data | |
494 | + coord_camera = numpy.array(bases.FlipX(coord_camera)) | |
495 | + | |
496 | + cam = self.ren.GetActiveCamera() | |
497 | + | |
498 | + if self.initial_foco is None: | |
499 | + self.initial_foco = numpy.array(cam.GetFocalPoint()) | |
500 | + | |
501 | + cam_initialposition = numpy.array(cam.GetPosition()) | |
502 | + cam_initialfoco = numpy.array(cam.GetFocalPoint()) | |
503 | + | |
504 | + cam_sub = cam_initialposition - cam_initialfoco | |
505 | + cam_sub_norm = numpy.linalg.norm(cam_sub) | |
506 | + vet1 = cam_sub/cam_sub_norm | |
507 | + | |
508 | + cam_sub_novo = coord_camera - self.initial_foco | |
509 | + cam_sub_novo_norm = numpy.linalg.norm(cam_sub_novo) | |
510 | + vet2 = cam_sub_novo/cam_sub_novo_norm | |
511 | + vet2 = vet2*cam_sub_norm + coord_camera | |
512 | + | |
513 | + cam.SetFocalPoint(coord_camera) | |
514 | + cam.SetPosition(vet2) | |
515 | + | |
444 | 516 | def OnExportSurface(self, pubsub_evt): |
445 | 517 | filename, filetype = pubsub_evt.data |
446 | 518 | fileprefix = filename.split(".")[-2] | ... | ... |
invesalius/gui/task_navigator.py
... | ... | @@ -20,8 +20,26 @@ |
20 | 20 | import os |
21 | 21 | import sys |
22 | 22 | |
23 | +import serial | |
23 | 24 | import wx |
24 | 25 | import wx.lib.hyperlink as hl |
26 | +import wx.lib.masked.numctrl | |
27 | +import wx.lib.platebtn as pbtn | |
28 | +import wx.lib.pubsub as ps | |
29 | + | |
30 | +import data.bases as db | |
31 | +import data.co_registration as dcr | |
32 | +import project | |
33 | + | |
34 | +IR1 = wx.NewId() | |
35 | +IR2 = wx.NewId() | |
36 | +IR3 = wx.NewId() | |
37 | +PR1 = wx.NewId() | |
38 | +PR2 = wx.NewId() | |
39 | +PR3 = wx.NewId() | |
40 | +Neuronavigate = wx.NewId() | |
41 | +Corregistration = wx.NewId() | |
42 | +GetPoint = wx.NewId() | |
25 | 43 | |
26 | 44 | class TaskPanel(wx.Panel): |
27 | 45 | """ |
... | ... | @@ -36,7 +54,7 @@ class TaskPanel(wx.Panel): |
36 | 54 | |
37 | 55 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
38 | 56 | sizer.Add(inner_panel, 1, wx.EXPAND | wx.GROW | wx.BOTTOM | wx.RIGHT | |
39 | - wx.LEFT, 7) | |
57 | + wx.LEFT, 8) | |
40 | 58 | sizer.Fit(self) |
41 | 59 | |
42 | 60 | self.SetSizer(sizer) |
... | ... | @@ -46,51 +64,387 @@ class TaskPanel(wx.Panel): |
46 | 64 | class InnerTaskPanel(wx.Panel): |
47 | 65 | |
48 | 66 | def __init__(self, parent): |
49 | - wx.Panel.__init__(self, parent) | |
50 | - self.SetBackgroundColour(wx.Colour(255,255,255)) | |
67 | + wx.Panel.__init__(self, parent, size=wx.Size(320,300)) | |
68 | + self.SetBackgroundColour(wx.Colour(221, 221, 221, 255)) | |
51 | 69 | self.SetAutoLayout(1) |
70 | + self.__bind_events() | |
71 | + | |
72 | + self.aux_img_ref1 = 0 | |
73 | + self.aux_img_ref2 = 0 | |
74 | + self.aux_img_ref3 = 0 | |
75 | + self.flagpoint = 0 | |
76 | + self.aux_plh_ref1 = 1 | |
77 | + self.aux_plh_ref2 = 1 | |
78 | + self.aux_plh_ref3 = 1 | |
79 | + self.a = 0, 0, 0 | |
80 | + self.coord1a = (0, 0, 0) | |
81 | + self.coord2a = (0, 0, 0) | |
82 | + self.coord3a = (0, 0, 0) | |
83 | + self.coord1b = (0, 0, 0) | |
84 | + self.coord2b = (0, 0, 0) | |
85 | + self.coord3b = (0, 0, 0) | |
86 | + self.correg = None | |
87 | + | |
88 | + | |
89 | + self.button_img_ref1 = wx.ToggleButton(self, IR1, label = 'TEI', size = wx.Size(30,23)) | |
90 | + self.button_img_ref1.Bind(wx.EVT_TOGGLEBUTTON, self.Img_Ref_ToggleButton1) | |
91 | + | |
92 | + self.button_img_ref2 = wx.ToggleButton(self, IR2, label = 'TDI', size = wx.Size(30,23)) | |
93 | + self.button_img_ref2.Bind(wx.EVT_TOGGLEBUTTON, self.Img_Ref_ToggleButton2) | |
52 | 94 | |
53 | - # Build GUI | |
54 | - self.__init_gui() | |
95 | + self.button_img_ref3 = wx.ToggleButton(self, IR3, label = 'FNI', size = wx.Size(30,23)) | |
96 | + self.button_img_ref3.Bind(wx.EVT_TOGGLEBUTTON, self.Img_Ref_ToggleButton3) | |
55 | 97 | |
56 | - # Bind events | |
57 | - self.__bind_events() | |
58 | - self.__bind_wx_events() | |
59 | - | |
60 | - def __init_gui(self): | |
61 | - """ | |
62 | - Build widgets in current panel | |
63 | - """ | |
64 | - # Create widgets to be inserted in this panel | |
65 | - link_test = hl.HyperLinkCtrl(self, -1, _("Testing...")) | |
66 | - link_test.SetUnderlines(False, False, False) | |
67 | - link_test.SetColours("BLACK", "BLACK", "BLACK") | |
68 | - link_test.AutoBrowse(False) | |
69 | - link_test.UpdateLink() | |
70 | - self.link_test = link_test | |
71 | - | |
72 | - # Add line sizers into main sizer | |
73 | - sizer = wx.BoxSizer(wx.VERTICAL) | |
74 | - sizer.Add(link_test, 0, wx.GROW|wx.EXPAND) | |
75 | - self.SetSizer(sizer) | |
98 | + self.button_plh_ref1 = wx.Button(self, PR1, label = 'TEP', size = wx.Size(30,23)) | |
99 | + self.button_plh_ref2 = wx.Button(self, PR2, label = 'TDP', size = wx.Size(30,23)) | |
100 | + self.button_plh_ref3 = wx.Button(self, PR3, label = 'FNP', size = wx.Size(30,23)) | |
101 | + self.button_crg = wx.Button(self, Corregistration, label = 'Corregistrate') | |
102 | + self.button_getpoint = wx.Button(self, GetPoint, label = 'GP', size = wx.Size(23,23)) | |
103 | + self.Bind(wx.EVT_BUTTON, self.Buttons) | |
104 | + | |
105 | + self.button_neuronavigate = wx.ToggleButton(self, Neuronavigate, "Neuronavigate") | |
106 | + self.button_neuronavigate.Bind(wx.EVT_TOGGLEBUTTON, self.Neuronavigate_ToggleButton) | |
107 | + | |
108 | + self.numCtrl1a = wx.lib.masked.numctrl.NumCtrl( | |
109 | + name='numCtrl1a', parent=self, integerWidth = 4, fractionWidth = 1) | |
110 | + self.numCtrl2a = wx.lib.masked.numctrl.NumCtrl( | |
111 | + name='numCtrl2a', parent=self, integerWidth = 4, fractionWidth = 1) | |
112 | + self.numCtrl3a = wx.lib.masked.numctrl.NumCtrl( | |
113 | + name='numCtrl3a', parent=self, integerWidth = 4, fractionWidth = 1) | |
114 | + self.numCtrl1b = wx.lib.masked.numctrl.NumCtrl( | |
115 | + name='numCtrl1b', parent=self, integerWidth = 4, fractionWidth = 1) | |
116 | + self.numCtrl2b = wx.lib.masked.numctrl.NumCtrl( | |
117 | + name='numCtrl2b', parent=self, integerWidth = 4, fractionWidth = 1) | |
118 | + self.numCtrl3b = wx.lib.masked.numctrl.NumCtrl( | |
119 | + name='numCtrl3b', parent=self, integerWidth = 4, fractionWidth = 1) | |
120 | + self.numCtrl1c = wx.lib.masked.numctrl.NumCtrl( | |
121 | + name='numCtrl1c', parent=self, integerWidth = 4, fractionWidth = 1) | |
122 | + self.numCtrl2c = wx.lib.masked.numctrl.NumCtrl( | |
123 | + name='numCtrl2c', parent=self, integerWidth = 4, fractionWidth = 1) | |
124 | + self.numCtrl3c = wx.lib.masked.numctrl.NumCtrl( | |
125 | + name='numCtrl3c', parent=self, integerWidth = 4, fractionWidth = 1) | |
126 | + self.numCtrl1d = wx.lib.masked.numctrl.NumCtrl( | |
127 | + name='numCtrl1d', parent=self, integerWidth = 4, fractionWidth = 1) | |
128 | + self.numCtrl2d = wx.lib.masked.numctrl.NumCtrl( | |
129 | + name='numCtrl2d', parent=self, integerWidth = 4, fractionWidth = 1) | |
130 | + self.numCtrl3d = wx.lib.masked.numctrl.NumCtrl( | |
131 | + name='numCtrl3d', parent=self, integerWidth = 4, fractionWidth = 1) | |
132 | + self.numCtrl1e = wx.lib.masked.numctrl.NumCtrl( | |
133 | + name='numCtrl1e', parent=self, integerWidth = 4, fractionWidth = 1) | |
134 | + self.numCtrl2e = wx.lib.masked.numctrl.NumCtrl( | |
135 | + name='numCtrl2e', parent=self, integerWidth = 4, fractionWidth = 1) | |
136 | + self.numCtrl3e = wx.lib.masked.numctrl.NumCtrl( | |
137 | + name='numCtrl3e', parent=self, integerWidth = 4, fractionWidth = 1) | |
138 | + self.numCtrl1f = wx.lib.masked.numctrl.NumCtrl( | |
139 | + name='numCtrl1f', parent=self, integerWidth = 4, fractionWidth = 1) | |
140 | + self.numCtrl2f = wx.lib.masked.numctrl.NumCtrl( | |
141 | + name='numCtrl2f', parent=self, integerWidth = 4, fractionWidth = 1) | |
142 | + self.numCtrl3f = wx.lib.masked.numctrl.NumCtrl( | |
143 | + name='numCtrl3f', parent=self, integerWidth = 4, fractionWidth = 1) | |
144 | + self.numCtrl1g = wx.lib.masked.numctrl.NumCtrl( | |
145 | + name='numCtrl1g', parent=self, integerWidth = 4, fractionWidth = 1) | |
146 | + self.numCtrl2g = wx.lib.masked.numctrl.NumCtrl( | |
147 | + name='numCtrl2g', parent=self, integerWidth = 4, fractionWidth = 1) | |
148 | + self.numCtrl3g = wx.lib.masked.numctrl.NumCtrl( | |
149 | + name='numCtrl3g', parent=self, integerWidth = 4, fractionWidth = 1) | |
150 | + | |
151 | + RefImg_sizer1 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5) | |
152 | + RefImg_sizer1.AddMany([ (self.button_img_ref1), | |
153 | + (self.numCtrl1a), | |
154 | + (self.numCtrl2a), | |
155 | + (self.numCtrl3a)]) | |
156 | + | |
157 | + RefImg_sizer2 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5) | |
158 | + RefImg_sizer2.AddMany([ (self.button_img_ref2), | |
159 | + (self.numCtrl1b), | |
160 | + (self.numCtrl2b), | |
161 | + (self.numCtrl3b)]) | |
162 | + | |
163 | + RefImg_sizer3 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5) | |
164 | + RefImg_sizer3.AddMany([ (self.button_img_ref3), | |
165 | + (self.numCtrl1c), | |
166 | + (self.numCtrl2c), | |
167 | + (self.numCtrl3c)]) | |
168 | + | |
169 | + RefPlh_sizer1 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5) | |
170 | + RefPlh_sizer1.AddMany([ (self.button_plh_ref1, 0, wx.GROW|wx.EXPAND), | |
171 | + (self.numCtrl1d, wx.RIGHT), | |
172 | + (self.numCtrl2d), | |
173 | + (self.numCtrl3d, wx.LEFT)]) | |
174 | + | |
175 | + RefPlh_sizer2 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5) | |
176 | + RefPlh_sizer2.AddMany([ (self.button_plh_ref2, 0, wx.GROW|wx.EXPAND), | |
177 | + (self.numCtrl1e, 0, wx.RIGHT), | |
178 | + (self.numCtrl2e), | |
179 | + (self.numCtrl3e, 0, wx.LEFT)]) | |
180 | + | |
181 | + RefPlh_sizer3 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5) | |
182 | + RefPlh_sizer3.AddMany([ (self.button_plh_ref3, 0, wx.GROW|wx.EXPAND), | |
183 | + (self.numCtrl1f, wx.RIGHT), | |
184 | + (self.numCtrl2f), | |
185 | + (self.numCtrl3f, wx.LEFT)]) | |
186 | + | |
187 | + Buttons_sizer4 = wx.FlexGridSizer(rows=1, cols=3, hgap=5, vgap=5) | |
188 | + Buttons_sizer4.AddMany([ (self.button_crg, wx.RIGHT), | |
189 | + (self.button_neuronavigate, wx.LEFT)]) | |
190 | + | |
191 | + GetPoint_sizer5 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5) | |
192 | + GetPoint_sizer5.AddMany([ (self.button_getpoint, 0, wx.GROW|wx.EXPAND), | |
193 | + (self.numCtrl1g, wx.RIGHT), | |
194 | + (self.numCtrl2g), | |
195 | + (self.numCtrl3g, wx.LEFT)]) | |
196 | + | |
197 | + text = wx.StaticText(self, -1, 'Neuronavigator') | |
198 | + | |
199 | + Ref_sizer = wx.FlexGridSizer(rows=9, cols=1, hgap=5, vgap=5) | |
200 | + Ref_sizer.AddGrowableCol(0, 1) | |
201 | + Ref_sizer.AddGrowableRow(0, 1) | |
202 | + Ref_sizer.AddGrowableRow(1, 1) | |
203 | + Ref_sizer.AddGrowableRow(2, 1) | |
204 | + Ref_sizer.AddGrowableRow(3, 1) | |
205 | + Ref_sizer.AddGrowableRow(4, 1) | |
206 | + Ref_sizer.AddGrowableRow(5, 1) | |
207 | + Ref_sizer.AddGrowableRow(6, 1) | |
208 | + Ref_sizer.AddGrowableRow(7, 1) | |
209 | + Ref_sizer.AddGrowableRow(8, 1) | |
210 | + Ref_sizer.SetFlexibleDirection(wx.BOTH) | |
211 | + Ref_sizer.AddMany([ (text, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
212 | + (RefImg_sizer1, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
213 | + (RefImg_sizer2, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
214 | + (RefImg_sizer3, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
215 | + (RefPlh_sizer1, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
216 | + (RefPlh_sizer2, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
217 | + (RefPlh_sizer3, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
218 | + (Buttons_sizer4, 0, wx.ALIGN_CENTER_HORIZONTAL), | |
219 | + (GetPoint_sizer5, 0, wx.ALIGN_CENTER_HORIZONTAL)]) | |
220 | + | |
221 | + main_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
222 | + main_sizer.Add(Ref_sizer, 1, wx.ALIGN_CENTER_HORIZONTAL, 10) | |
223 | + self.sizer = main_sizer | |
224 | + self.SetSizer(main_sizer) | |
76 | 225 | self.Fit() |
77 | 226 | |
227 | + tooltip = wx.ToolTip("Pick the coordinates x, y, z in the image") | |
228 | + self.button_img_ref1.SetToolTip(tooltip) | |
229 | + tooltip = wx.ToolTip("Pick the coordinates x, y, z in the image") | |
230 | + self.button_img_ref2.SetToolTip(tooltip) | |
231 | + tooltip = wx.ToolTip("Pick the coordinates x, y, z in the image") | |
232 | + self.button_img_ref3.SetToolTip(tooltip) | |
233 | + tooltip = wx.ToolTip("Pick the coordinates x, y, z in the space") | |
234 | + self.button_plh_ref1.SetToolTip(tooltip) | |
235 | + tooltip = wx.ToolTip("Pick the coordinates x, y, z in the space") | |
236 | + self.button_plh_ref2.SetToolTip(tooltip) | |
237 | + tooltip = wx.ToolTip("Pick the coordinates x, y, z in the space") | |
238 | + self.button_plh_ref3.SetToolTip(tooltip) | |
239 | + tooltip = wx.ToolTip("X Coordinate") | |
240 | + self.numCtrl1a.SetToolTip(tooltip) | |
241 | + tooltip = wx.ToolTip("X Coordinate") | |
242 | + self.numCtrl1b.SetToolTip(tooltip) | |
243 | + tooltip = wx.ToolTip("X Coordinate") | |
244 | + self.numCtrl1c.SetToolTip(tooltip) | |
245 | + tooltip = wx.ToolTip("X Coordinate") | |
246 | + self.numCtrl1d.SetToolTip(tooltip) | |
247 | + tooltip = wx.ToolTip("X Coordinate") | |
248 | + self.numCtrl1e.SetToolTip(tooltip) | |
249 | + tooltip = wx.ToolTip("X Coordinate") | |
250 | + self.numCtrl1f.SetToolTip(tooltip) | |
251 | + tooltip = wx.ToolTip("X Coordinate") | |
252 | + self.numCtrl1g.SetToolTip(tooltip) | |
253 | + tooltip = wx.ToolTip("Y Coordinate") | |
254 | + self.numCtrl2a.SetToolTip(tooltip) | |
255 | + tooltip = wx.ToolTip("Y Coordinate") | |
256 | + self.numCtrl2b.SetToolTip(tooltip) | |
257 | + tooltip = wx.ToolTip("Y Coordinate") | |
258 | + self.numCtrl2c.SetToolTip(tooltip) | |
259 | + tooltip = wx.ToolTip("Y Coordinate") | |
260 | + self.numCtrl2d.SetToolTip(tooltip) | |
261 | + tooltip = wx.ToolTip("Y Coordinate") | |
262 | + self.numCtrl2e.SetToolTip(tooltip) | |
263 | + tooltip = wx.ToolTip("Y Coordinate") | |
264 | + self.numCtrl2f.SetToolTip(tooltip) | |
265 | + tooltip = wx.ToolTip("Y Coordinate") | |
266 | + self.numCtrl2g.SetToolTip(tooltip) | |
267 | + tooltip = wx.ToolTip("Z Coordinate") | |
268 | + self.numCtrl3a.SetToolTip(tooltip) | |
269 | + tooltip = wx.ToolTip("Z Coordinate") | |
270 | + self.numCtrl3b.SetToolTip(tooltip) | |
271 | + tooltip = wx.ToolTip("Z Coordinate") | |
272 | + self.numCtrl3c.SetToolTip(tooltip) | |
273 | + tooltip = wx.ToolTip("Z Coordinate") | |
274 | + self.numCtrl3d.SetToolTip(tooltip) | |
275 | + tooltip = wx.ToolTip("Z Coordinate") | |
276 | + self.numCtrl3e.SetToolTip(tooltip) | |
277 | + tooltip = wx.ToolTip("Z Coordinate") | |
278 | + self.numCtrl3f.SetToolTip(tooltip) | |
279 | + tooltip = wx.ToolTip("Z Coordinate") | |
280 | + self.numCtrl3g.SetToolTip(tooltip) | |
281 | + tooltip = wx.ToolTip("Corregistration of the real position with the image position") | |
282 | + self.button_crg.SetToolTip(tooltip) | |
283 | + tooltip = wx.ToolTip("Neuronavigation") | |
284 | + self.button_neuronavigate.SetToolTip(tooltip) | |
285 | + tooltip = wx.ToolTip("Get Cross Center Coordinates") | |
286 | + self.button_getpoint.SetToolTip(tooltip) | |
287 | + | |
78 | 288 | def __bind_events(self): |
79 | - """ | |
80 | - Bind pubsub events | |
81 | - """ | |
82 | - # Example: ps.Publisher().subscribe("Test") | |
83 | - pass | |
84 | - | |
85 | - def __bind_wx_events(self): | |
86 | - """ | |
87 | - Bind wx general events | |
88 | - """ | |
89 | - # Example: self.Bind(wx.EVT_BUTTON, self.OnButton) | |
90 | - self.link_test.Bind(hl.EVT_HYPERLINK_LEFT, self.OnTest) | |
289 | + ps.Publisher().subscribe(self.__update_points_img, 'Update cross position') | |
290 | + ps.Publisher().subscribe(self.__update_points_plh, 'Update plh position') | |
291 | + | |
292 | + def __update_points_img(self, pubsub_evt): | |
293 | + x, y, z = pubsub_evt.data[1] | |
294 | + self.a = x, y, z | |
295 | + if self.aux_img_ref1 == 0: | |
296 | + self.numCtrl1a.SetValue(x) | |
297 | + self.numCtrl2a.SetValue(y) | |
298 | + self.numCtrl3a.SetValue(z) | |
299 | + if self.aux_img_ref2 == 0: | |
300 | + self.numCtrl1b.SetValue(x) | |
301 | + self.numCtrl2b.SetValue(y) | |
302 | + self.numCtrl3b.SetValue(z) | |
303 | + if self.aux_img_ref3 == 0: | |
304 | + self.numCtrl1c.SetValue(x) | |
305 | + self.numCtrl2c.SetValue(y) | |
306 | + self.numCtrl3c.SetValue(z) | |
307 | + | |
308 | + | |
309 | + def __update_points_plh(self, pubsub_evt): | |
310 | + coord = pubsub_evt.data | |
311 | + if self.aux_plh_ref1 == 0: | |
312 | + self.numCtrl1d.SetValue(coord[0]) | |
313 | + self.numCtrl2d.SetValue(coord[1]) | |
314 | + self.numCtrl3d.SetValue(coord[2]) | |
315 | + self.aux_plh_ref1 = 1 | |
316 | + if self.aux_plh_ref2 == 0: | |
317 | + self.numCtrl1e.SetValue(coord[0]) | |
318 | + self.numCtrl2e.SetValue(coord[1]) | |
319 | + self.numCtrl3e.SetValue(coord[2]) | |
320 | + self.aux_plh_ref2 = 1 | |
321 | + if self.aux_plh_ref3 == 0: | |
322 | + self.numCtrl1f.SetValue(coord[0]) | |
323 | + self.numCtrl2f.SetValue(coord[1]) | |
324 | + self.numCtrl3f.SetValue(coord[2]) | |
325 | + self.aux_plh_ref3 = 1 | |
326 | + | |
327 | + def Buttons(self, evt): | |
328 | + id = evt.GetId() | |
329 | + x, y, z = self.a | |
330 | + if id == PR1: | |
331 | + self.aux_plh_ref1 = 0 | |
332 | + self.coord1b = self.Coordinates() | |
333 | + coord = self.coord1b | |
334 | + elif id == PR2: | |
335 | + self.aux_plh_ref2 = 0 | |
336 | + self.coord2b = self.Coordinates() | |
337 | + coord = self.coord2b | |
338 | + elif id == PR3: | |
339 | + self.aux_plh_ref3 = 0 | |
340 | + self.coord3b = self.Coordinates() | |
341 | + coord = self.coord3b | |
342 | + elif id == GetPoint: | |
343 | + x, y, z = self.a | |
344 | + self.numCtrl1g.SetValue(x) | |
345 | + self.numCtrl2g.SetValue(y) | |
346 | + self.numCtrl3g.SetValue(z) | |
347 | + info = self.a, self.flagpoint | |
348 | + self.SaveCoordinates(info) | |
349 | + self.flagpoint = 1 | |
350 | + elif id == Corregistration and self.aux_img_ref1 == 1 and self.aux_img_ref2 == 1 and self.aux_img_ref3 == 1: | |
351 | + print "Coordenadas Imagem: ", self.coord1a, self.coord2a, self.coord3a | |
352 | + print "Coordenadas Polhemus: ", self.coord1b, self.coord2b, self.coord3b | |
353 | + | |
354 | + self.M, self.q1, self.Minv = db.Bases(self.coord1a, self.coord2a, self.coord3a).Basecreation() | |
355 | + self.N, self.q2, self.Ninv = db.Bases(self.coord1b, self.coord2b, self.coord3b).Basecreation() | |
356 | + | |
357 | + if self.aux_plh_ref1 == 0 or self.aux_plh_ref2 == 0 or self.aux_plh_ref3 == 0: | |
358 | + ps.Publisher().sendMessage('Update plh position', coord) | |
359 | + | |
360 | + def Coordinates(self): | |
361 | + #Get Polhemus points for base creation | |
362 | + ser = serial.Serial(0) | |
363 | + ser.write("Y") | |
364 | + ser.write("P") | |
365 | + str = ser.readline() | |
366 | + ser.write("Y") | |
367 | + str = str.replace("\r\n","") | |
368 | + str = str.replace("-"," -") | |
369 | + aostr = [s for s in str.split()] | |
370 | + #aoflt -> 0:letter 1:x 2:y 3:z | |
371 | + aoflt = [float(aostr[1]), float(aostr[2]), float(aostr[3]), | |
372 | + float(aostr[4]), float(aostr[5]), float(aostr[6])] | |
373 | + ser.close() | |
374 | + #Unit change: inches to millimeters | |
375 | + x = 25.4 | |
376 | + y = 25.4 | |
377 | + z = -25.4 | |
378 | + | |
379 | + coord = (aoflt[0]*x, aoflt[1]*y, aoflt[2]*z) | |
380 | + return coord | |
91 | 381 | |
92 | - def OnTest(self, event): | |
93 | - """ | |
94 | - Describe what this method does | |
95 | - """ | |
96 | - event.Skip() | |
382 | + def Img_Ref_ToggleButton1(self, evt): | |
383 | + id = evt.GetId() | |
384 | + flag1 = self.button_img_ref1.GetValue() | |
385 | + x, y, z = self.a | |
386 | + if flag1 == True: | |
387 | + self.coord1a = x, y, z | |
388 | + self.aux_img_ref1 = 1 | |
389 | + elif flag1 == False: | |
390 | + self.aux_img_ref1 = 0 | |
391 | + self.coord1a = (0, 0, 0) | |
392 | + self.numCtrl1a.SetValue(x) | |
393 | + self.numCtrl2a.SetValue(y) | |
394 | + self.numCtrl3a.SetValue(z) | |
395 | + | |
396 | + def Img_Ref_ToggleButton2(self, evt): | |
397 | + id = evt.GetId() | |
398 | + flag2 = self.button_img_ref2.GetValue() | |
399 | + x, y, z = self.a | |
400 | + if flag2 == True: | |
401 | + self.coord2a = x, y, z | |
402 | + self.aux_img_ref2 = 1 | |
403 | + elif flag2 == False: | |
404 | + self.aux_img_ref2 = 0 | |
405 | + self.coord2a = (0, 0, 0) | |
406 | + self.numCtrl1b.SetValue(x) | |
407 | + self.numCtrl2b.SetValue(y) | |
408 | + self.numCtrl3b.SetValue(z) | |
409 | + | |
410 | + def Img_Ref_ToggleButton3(self, evt): | |
411 | + id = evt.GetId() | |
412 | + flag3 = self.button_img_ref3.GetValue() | |
413 | + x, y, z = self.a | |
414 | + if flag3 == True: | |
415 | + self.coord3a = x, y, z | |
416 | + self.aux_img_ref3 = 1 | |
417 | + elif flag3 == False: | |
418 | + self.aux_img_ref3 = 0 | |
419 | + self.coord3a = (0, 0, 0) | |
420 | + self.numCtrl1c.SetValue(x) | |
421 | + self.numCtrl2c.SetValue(y) | |
422 | + self.numCtrl3c.SetValue(z) | |
423 | + | |
424 | + def Neuronavigate_ToggleButton(self, evt): | |
425 | + id = evt.GetId() | |
426 | + flag4 = self.button_neuronavigate.GetValue() | |
427 | + bases = self.Minv, self.N, self.q1, self.q2 | |
428 | + if flag4 == True: | |
429 | + self.correg = dcr.Corregister(bases, flag4) | |
430 | + elif flag4 == False: | |
431 | + self.correg.stop() | |
432 | + | |
433 | + def SaveCoordinates(self, info): | |
434 | + #Create a file and write the points given by getpoint's button | |
435 | + x, y, z = info[0] | |
436 | + flag = info[1] | |
437 | + | |
438 | + if flag == 0: | |
439 | + text_file = open("points.txt", "w") | |
440 | + line = str('%.2f' %x) + "\t" + str('%.2f' %y) + "\t" + str('%.2f' %z) + "\n" | |
441 | + text_file.writelines(line) | |
442 | + text_file.close() | |
443 | + else: | |
444 | + text_file = open("points.txt", "r") | |
445 | + filedata = text_file.read() | |
446 | + line = filedata + str('%.2f' %x) + "\t" + str('%.2f' %y) + "\t" + str('%.2f' %z) + "\n" | |
447 | + text_file = open("points.txt", "w") | |
448 | + text_file.write(line) | |
449 | + text_file.close() | |
450 | + | ... | ... |