Commit a3665303aa23d4b54484c496d5cbb8c5dae2f857
1 parent
d3779482
Exists in
master
and in
6 other branches
ENH: A box in each slice_data
Showing
2 changed files
with
74 additions
and
2 deletions
Show diff stats
invesalius/data/slice_data.py
@@ -29,6 +29,7 @@ class SliceData(object): | @@ -29,6 +29,7 @@ class SliceData(object): | ||
29 | self.orientation = 'AXIAL' | 29 | self.orientation = 'AXIAL' |
30 | self.renderer = None | 30 | self.renderer = None |
31 | self.__create_text() | 31 | self.__create_text() |
32 | + self.__create_box() | ||
32 | 33 | ||
33 | def __create_text(self): | 34 | def __create_text(self): |
34 | colour = const.ORIENTATION_COLOUR[self.orientation] | 35 | colour = const.ORIENTATION_COLOUR[self.orientation] |
@@ -41,6 +42,42 @@ class SliceData(object): | @@ -41,6 +42,42 @@ class SliceData(object): | ||
41 | text.SetValue(self.number) | 42 | text.SetValue(self.number) |
42 | self.text = text | 43 | self.text = text |
43 | 44 | ||
45 | + def __create_box(self): | ||
46 | + xi = yi = 0.1 | ||
47 | + xf = yf = 200 | ||
48 | + line_i = vtk.vtkLineSource() | ||
49 | + line_i.SetPoint1((xi, yi, 0)) | ||
50 | + line_i.SetPoint2((xf, yi, 0)) | ||
51 | + self.line_i = line_i | ||
52 | + | ||
53 | + line_s = vtk.vtkLineSource() | ||
54 | + line_s.SetPoint1((xi, yf, 0)) | ||
55 | + line_s.SetPoint2((xf, yf, 0)) | ||
56 | + self.line_s = line_s | ||
57 | + | ||
58 | + line_l = vtk.vtkLineSource() | ||
59 | + line_l.SetPoint1((xi, yi, 0)) | ||
60 | + line_l.SetPoint2((xi, yf, 0)) | ||
61 | + self.line_l = line_l | ||
62 | + | ||
63 | + line_r = vtk.vtkLineSource() | ||
64 | + line_r.SetPoint1((xf, yi, 0)) | ||
65 | + line_r.SetPoint2((xf, yf, 0)) | ||
66 | + self.line_r = line_r | ||
67 | + | ||
68 | + box = vtk.vtkAppendPolyData() | ||
69 | + box.AddInput(line_i.GetOutput()) | ||
70 | + box.AddInput(line_s.GetOutput()) | ||
71 | + box.AddInput(line_l.GetOutput()) | ||
72 | + box.AddInput(line_r.GetOutput()) | ||
73 | + | ||
74 | + box_mapper = vtk.vtkPolyDataMapper2D() | ||
75 | + box_mapper.SetInput(box.GetOutput()) | ||
76 | + | ||
77 | + box_actor = vtk.vtkActor2D() | ||
78 | + box_actor.SetMapper(box_mapper) | ||
79 | + self.box_actor = box_actor | ||
80 | + | ||
44 | def SetCursor(self, cursor): | 81 | def SetCursor(self, cursor): |
45 | if self.cursor: | 82 | if self.cursor: |
46 | self.renderer.RemoveActor(self.cursor.actor) | 83 | self.renderer.RemoveActor(self.cursor.actor) |
@@ -55,11 +92,32 @@ class SliceData(object): | @@ -55,11 +92,32 @@ class SliceData(object): | ||
55 | self.orientation = orientation | 92 | self.orientation = orientation |
56 | colour = const.ORIENTATION_COLOUR[self.orientation] | 93 | colour = const.ORIENTATION_COLOUR[self.orientation] |
57 | self.text.SetColour(colour) | 94 | self.text.SetColour(colour) |
95 | + self.box_actor.GetProperty().SetColor(colour) | ||
96 | + | ||
97 | + def SetSize(self, size): | ||
98 | + w, h = size | ||
99 | + xi = yi = 0.1 | ||
100 | + xf = w - 0.1 | ||
101 | + yf = h - 0.1 | ||
102 | + | ||
103 | + self.line_i.SetPoint1((xi, yi, 0)) | ||
104 | + self.line_i.SetPoint2((xf, yi, 0)) | ||
105 | + | ||
106 | + self.line_s.SetPoint1((xi, yf, 0)) | ||
107 | + self.line_s.SetPoint2((xf, yf, 0)) | ||
108 | + | ||
109 | + self.line_l.SetPoint1((xi, yi, 0)) | ||
110 | + self.line_l.SetPoint2((xi, yf, 0)) | ||
111 | + | ||
112 | + self.line_r.SetPoint1((xf, yi, 0)) | ||
113 | + self.line_r.SetPoint2((xf, yf, 0)) | ||
58 | 114 | ||
59 | def Hide(self): | 115 | def Hide(self): |
60 | self.renderer.RemoveActor(self.actor) | 116 | self.renderer.RemoveActor(self.actor) |
61 | self.renderer.RemoveActor(self.text.actor) | 117 | self.renderer.RemoveActor(self.text.actor) |
118 | + self.renderer.RemoveActor(self.box_actor) | ||
62 | 119 | ||
63 | def Show(self): | 120 | def Show(self): |
64 | self.renderer.AddActor(self.actor) | 121 | self.renderer.AddActor(self.actor) |
65 | self.renderer.AddActor(self.text.actor) | 122 | self.renderer.AddActor(self.text.actor) |
123 | + self.renderer.AddActor(self.box_actor) |
invesalius/data/viewer_slice.py
@@ -45,8 +45,8 @@ class Viewer(wx.Panel): | @@ -45,8 +45,8 @@ class Viewer(wx.Panel): | ||
45 | def __init__(self, prnt, orientation='AXIAL'): | 45 | def __init__(self, prnt, orientation='AXIAL'): |
46 | wx.Panel.__init__(self, prnt, size=wx.Size(320, 300)) | 46 | wx.Panel.__init__(self, prnt, size=wx.Size(320, 300)) |
47 | 47 | ||
48 | - colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]] | ||
49 | - self.SetBackgroundColour(colour) | 48 | + #colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]] |
49 | + #self.SetBackgroundColour(colour) | ||
50 | 50 | ||
51 | # Interactor additional style | 51 | # Interactor additional style |
52 | self.modes = []#['DEFAULT'] | 52 | self.modes = []#['DEFAULT'] |
@@ -830,6 +830,7 @@ class Viewer(wx.Panel): | @@ -830,6 +830,7 @@ class Viewer(wx.Panel): | ||
830 | #self.scroll.Bind(wx.EVT_SCROLL_ENDSCROLL, self.OnScrollBarRelease) | 830 | #self.scroll.Bind(wx.EVT_SCROLL_ENDSCROLL, self.OnScrollBarRelease) |
831 | self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) | 831 | self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
832 | self.interactor.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu) | 832 | self.interactor.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu) |
833 | + self.Bind(wx.EVT_SIZE, self.OnSize) | ||
833 | 834 | ||
834 | def LoadImagedata(self, pubsub_evt): | 835 | def LoadImagedata(self, pubsub_evt): |
835 | imagedata, mask_dict = pubsub_evt.data | 836 | imagedata, mask_dict = pubsub_evt.data |
@@ -853,6 +854,9 @@ class Viewer(wx.Panel): | @@ -853,6 +854,9 @@ class Viewer(wx.Panel): | ||
853 | proportion_y = 1.0 / self.layout[1] | 854 | proportion_y = 1.0 / self.layout[1] |
854 | # The (0,0) in VTK is in bottom left. So the creation from renderers | 855 | # The (0,0) in VTK is in bottom left. So the creation from renderers |
855 | # must be # in inverted order, from the top left to bottom right | 856 | # must be # in inverted order, from the top left to bottom right |
857 | + w, h = self.interactor.GetRenderWindow().GetSize() | ||
858 | + w *= proportion_x | ||
859 | + h *= proportion_y | ||
856 | n = 0 | 860 | n = 0 |
857 | for j in xrange(self.layout[1]-1, -1, -1): | 861 | for j in xrange(self.layout[1]-1, -1, -1): |
858 | for i in xrange(self.layout[0]): | 862 | for i in xrange(self.layout[0]): |
@@ -868,6 +872,7 @@ class Viewer(wx.Panel): | @@ -868,6 +872,7 @@ class Viewer(wx.Panel): | ||
868 | x, y = const.TEXT_POS_LEFT_DOWN | 872 | x, y = const.TEXT_POS_LEFT_DOWN |
869 | slice_data.text.SetPosition((x+slice_xi,y+slice_yi)) | 873 | slice_data.text.SetPosition((x+slice_xi,y+slice_yi)) |
870 | slice_data.SetCursor(self.__create_cursor()) | 874 | slice_data.SetCursor(self.__create_cursor()) |
875 | + slice_data.SetSize((w, h)) | ||
871 | self.__update_camera(slice_data) | 876 | self.__update_camera(slice_data) |
872 | n += 1 | 877 | n += 1 |
873 | 878 | ||
@@ -1097,6 +1102,7 @@ class Viewer(wx.Panel): | @@ -1097,6 +1102,7 @@ class Viewer(wx.Panel): | ||
1097 | slice_data.actor = actor | 1102 | slice_data.actor = actor |
1098 | renderer.AddActor(actor) | 1103 | renderer.AddActor(actor) |
1099 | renderer.AddActor(slice_data.text.actor) | 1104 | renderer.AddActor(slice_data.text.actor) |
1105 | + renderer.AddActor(slice_data.box_actor) | ||
1100 | return slice_data | 1106 | return slice_data |
1101 | 1107 | ||
1102 | def __update_camera(self, slice_data): | 1108 | def __update_camera(self, slice_data): |
@@ -1205,6 +1211,14 @@ class Viewer(wx.Panel): | @@ -1205,6 +1211,14 @@ class Viewer(wx.Panel): | ||
1205 | if evt: | 1211 | if evt: |
1206 | evt.Skip() | 1212 | evt.Skip() |
1207 | 1213 | ||
1214 | + def OnSize(self, evt): | ||
1215 | + w, h = self.interactor.GetRenderWindow().GetSize() | ||
1216 | + w = float(w) / self.layout[0] | ||
1217 | + h = float(h) / self.layout[1] | ||
1218 | + for slice_data in self.slice_data_list: | ||
1219 | + slice_data.SetSize((w, h)) | ||
1220 | + evt.Skip() | ||
1221 | + | ||
1208 | def set_slice_number(self, index): | 1222 | def set_slice_number(self, index): |
1209 | self.slice_number = index | 1223 | self.slice_number = index |
1210 | for n, slice_data in enumerate(self.slice_data_list): | 1224 | for n, slice_data in enumerate(self.slice_data_list): |