Commit 3fb68523a156bc0e66b1ae0765414fc2a8acb2e5
1 parent
24de5835
Exists in
master
Using canvas renderer instead of vtkLine to show a colored box around
the renderer.
Showing
3 changed files
with
24 additions
and
116 deletions
Show diff stats
invesalius/data/slice_data.py
... | ... | @@ -35,14 +35,13 @@ class SliceData(object): |
35 | 35 | self.actor = None |
36 | 36 | self.cursor = None |
37 | 37 | self.text = None |
38 | - | |
38 | + self.layer = 99 | |
39 | 39 | self.number = 0 |
40 | 40 | self.orientation = 'AXIAL' |
41 | 41 | self.renderer = None |
42 | 42 | self.canvas_renderer = None |
43 | 43 | self.overlay_renderer = None |
44 | 44 | self.__create_text() |
45 | - self.__create_box() | |
46 | 45 | |
47 | 46 | def __create_text(self): |
48 | 47 | colour = const.ORIENTATION_COLOUR[self.orientation] |
... | ... | @@ -56,83 +55,6 @@ class SliceData(object): |
56 | 55 | text.SetValue(self.number) |
57 | 56 | self.text = text |
58 | 57 | |
59 | - def __create_line_actor(self, line): | |
60 | - line_mapper = vtk.vtkPolyDataMapper2D() | |
61 | - line_mapper.SetInputConnection(line.GetOutputPort()) | |
62 | - | |
63 | - line_actor = vtk.vtkActor2D() | |
64 | - line_actor.SetMapper(line_mapper) | |
65 | - return line_actor | |
66 | - | |
67 | - def __create_box(self): | |
68 | - xi = yi = 0.1 | |
69 | - xf = yf = 200 | |
70 | - line_i = vtk.vtkLineSource() | |
71 | - line_i.SetPoint1((xi, yi, 0)) | |
72 | - line_i.SetPoint2((xf, yi, 0)) | |
73 | - self.line_i = line_i | |
74 | - self.line_i_actor = self.__create_line_actor(line_i) | |
75 | - | |
76 | - line_s = vtk.vtkLineSource() | |
77 | - line_s.SetPoint1((xi, yf, 0)) | |
78 | - line_s.SetPoint2((xf, yf, 0)) | |
79 | - self.line_s = line_s | |
80 | - self.line_s_actor = self.__create_line_actor(line_s) | |
81 | - | |
82 | - line_l = vtk.vtkLineSource() | |
83 | - line_l.SetPoint1((xi, yi, 0)) | |
84 | - line_l.SetPoint2((xi, yf, 0)) | |
85 | - self.line_l = line_l | |
86 | - self.line_l_actor = self.__create_line_actor(line_l) | |
87 | - | |
88 | - line_r = vtk.vtkLineSource() | |
89 | - line_r.SetPoint1((xf, yi, 0)) | |
90 | - line_r.SetPoint2((xf, yf, 0)) | |
91 | - self.line_r = line_r | |
92 | - self.line_r_actor = self.__create_line_actor(line_r) | |
93 | - | |
94 | - box_actor = vtk.vtkPropAssembly() | |
95 | - box_actor.AddPart(self.line_i_actor) | |
96 | - box_actor.AddPart(self.line_s_actor) | |
97 | - box_actor.AddPart(self.line_l_actor) | |
98 | - box_actor.AddPart(self.line_r_actor) | |
99 | - self.box_actor = box_actor | |
100 | - | |
101 | - def __set_border_colours(self, colours_borders): | |
102 | - for colour, actors in colours_borders.items(): | |
103 | - for actor in actors: | |
104 | - actor.GetProperty().SetColor(colour) | |
105 | - | |
106 | - def SetBorderStyle(self, style=BORDER_NONE): | |
107 | - colour_e = const.ORIENTATION_COLOUR[self.orientation] | |
108 | - colour_i = (1, 1, 1) | |
109 | - | |
110 | - extern_borders = [] | |
111 | - intern_borders = [] | |
112 | - | |
113 | - if style & BORDER_UP: | |
114 | - extern_borders.append(self.line_s_actor) | |
115 | - else: | |
116 | - intern_borders.append(self.line_s_actor) | |
117 | - | |
118 | - if style & BORDER_DOWN: | |
119 | - extern_borders.append(self.line_i_actor) | |
120 | - else: | |
121 | - intern_borders.append(self.line_i_actor) | |
122 | - | |
123 | - if style & BORDER_LEFT: | |
124 | - extern_borders.append(self.line_l_actor) | |
125 | - else: | |
126 | - intern_borders.append(self.line_l_actor) | |
127 | - | |
128 | - if style & BORDER_RIGHT: | |
129 | - extern_borders.append(self.line_r_actor) | |
130 | - else: | |
131 | - intern_borders.append(self.line_r_actor) | |
132 | - | |
133 | - self.__set_border_colours({colour_i: intern_borders, | |
134 | - colour_e: extern_borders}) | |
135 | - | |
136 | 58 | def SetCursor(self, cursor): |
137 | 59 | if self.cursor: |
138 | 60 | self.overlay_renderer.RemoveActor(self.cursor.actor) |
... | ... | @@ -150,28 +72,6 @@ class SliceData(object): |
150 | 72 | |
151 | 73 | def SetOrientation(self, orientation): |
152 | 74 | self.orientation = orientation |
153 | - colour = const.ORIENTATION_COLOUR[self.orientation] | |
154 | - self.text.SetColour(colour) | |
155 | - #self.box_actor.GetProperty().SetColor(colour) | |
156 | - | |
157 | - | |
158 | - def SetSize(self, size): | |
159 | - w, h = size | |
160 | - xi = yi = 0.1 | |
161 | - xf = w - 0.1 | |
162 | - yf = h - 0.1 | |
163 | - | |
164 | - self.line_i.SetPoint1((xi, yi, 0)) | |
165 | - self.line_i.SetPoint2((xf, yi, 0)) | |
166 | - | |
167 | - self.line_s.SetPoint1((xi, yf, 0)) | |
168 | - self.line_s.SetPoint2((xf, yf, 0)) | |
169 | - | |
170 | - self.line_l.SetPoint1((xi, yi, 0)) | |
171 | - self.line_l.SetPoint2((xi, yf, 0)) | |
172 | - | |
173 | - self.line_r.SetPoint1((xf, yi, 0)) | |
174 | - self.line_r.SetPoint2((xf, yf, 0)) | |
175 | 75 | |
176 | 76 | def Hide(self): |
177 | 77 | self.overlay_renderer.RemoveActor(self.actor) |
... | ... | @@ -180,3 +80,8 @@ class SliceData(object): |
180 | 80 | def Show(self): |
181 | 81 | self.renderer.AddActor(self.actor) |
182 | 82 | self.renderer.AddActor(self.text.actor) |
83 | + | |
84 | + def draw_to_canvas(self, gc, canvas): | |
85 | + w, h = self.renderer.GetSize() | |
86 | + colour = const.ORIENTATION_COLOUR[self.orientation] | |
87 | + canvas.draw_rectangle((0, 0), w, h, line_colour=[255*i for i in colour] + [255], line_width=2) | ... | ... |
invesalius/data/viewer_slice.py
... | ... | @@ -232,11 +232,11 @@ class Viewer(wx.Panel): |
232 | 232 | self.mip_ctrls.Hide() |
233 | 233 | |
234 | 234 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
235 | - sizer.Add(self.interactor, 1, wx.EXPAND|wx.GROW) | |
235 | + sizer.Add(self.interactor, 1, wx.EXPAND) | |
236 | 236 | sizer.Add(scroll, 0, wx.EXPAND|wx.GROW) |
237 | 237 | |
238 | 238 | background_sizer = wx.BoxSizer(wx.VERTICAL) |
239 | - background_sizer.Add(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
239 | + background_sizer.Add(sizer, 1, wx.EXPAND) | |
240 | 240 | #background_sizer.Add(self.mip_ctrls, 0, wx.EXPAND|wx.GROW|wx.ALL, 2) |
241 | 241 | self.SetSizer(background_sizer) |
242 | 242 | background_sizer.Fit(self) |
... | ... | @@ -935,8 +935,6 @@ class Viewer(wx.Panel): |
935 | 935 | |
936 | 936 | def _export_picture(self, id, filename, filetype): |
937 | 937 | view_prop_list = [] |
938 | - view_prop_list.append(self.slice_data.box_actor) | |
939 | - self.slice_data.renderer.RemoveViewProp(self.slice_data.box_actor) | |
940 | 938 | |
941 | 939 | dict = {"AXIAL": const.AXIAL, |
942 | 940 | "CORONAL": const.CORONAL, |
... | ... | @@ -1030,7 +1028,7 @@ class Viewer(wx.Panel): |
1030 | 1028 | #self.scroll.Bind(wx.EVT_SCROLL_ENDSCROLL, self.OnScrollBarRelease) |
1031 | 1029 | self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
1032 | 1030 | self.interactor.Bind(wx.EVT_RIGHT_UP, self.OnContextMenu) |
1033 | - self.interactor.Bind(wx.EVT_SIZE, self.OnSize) | |
1031 | + # self.interactor.Bind(wx.EVT_SIZE, self.OnSize) | |
1034 | 1032 | |
1035 | 1033 | def LoadImagedata(self, mask_dict): |
1036 | 1034 | self.SetInput(mask_dict) |
... | ... | @@ -1071,7 +1069,7 @@ class Viewer(wx.Panel): |
1071 | 1069 | x, y = const.TEXT_POS_LEFT_DOWN |
1072 | 1070 | slice_data.text.SetPosition((x+slice_xi,y+slice_yi)) |
1073 | 1071 | slice_data.SetCursor(self.__create_cursor()) |
1074 | - slice_data.SetSize((w, h)) | |
1072 | + # slice_data.SetSize((w, h)) | |
1075 | 1073 | self.__update_camera(slice_data) |
1076 | 1074 | |
1077 | 1075 | style = 0 |
... | ... | @@ -1085,7 +1083,7 @@ class Viewer(wx.Panel): |
1085 | 1083 | if i == self.layout[0] - 1: |
1086 | 1084 | style = style | sd.BORDER_RIGHT |
1087 | 1085 | |
1088 | - slice_data.SetBorderStyle(style) | |
1086 | + # slice_data.SetBorderStyle(style) | |
1089 | 1087 | n += 1 |
1090 | 1088 | |
1091 | 1089 | def __create_cursor(self): |
... | ... | @@ -1112,6 +1110,7 @@ class Viewer(wx.Panel): |
1112 | 1110 | |
1113 | 1111 | self.canvas = CanvasRendererCTX(self, self.slice_data.renderer, self.slice_data.canvas_renderer, self.orientation) |
1114 | 1112 | self.canvas.draw_list.append(self.slice_data.text) |
1113 | + self.canvas.draw_list.append(self.slice_data) | |
1115 | 1114 | |
1116 | 1115 | # Set the slice number to the last slice to ensure the camera if far |
1117 | 1116 | # enough to show all slices. |
... | ... | @@ -1207,10 +1206,10 @@ class Viewer(wx.Panel): |
1207 | 1206 | slice_data.canvas_renderer = canvas_renderer |
1208 | 1207 | slice_data.overlay_renderer = overlay_renderer |
1209 | 1208 | slice_data.actor = actor |
1210 | - slice_data.SetBorderStyle(sd.BORDER_ALL) | |
1209 | + # slice_data.SetBorderStyle(sd.BORDER_ALL) | |
1211 | 1210 | renderer.AddActor(actor) |
1212 | 1211 | # renderer.AddActor(slice_data.text.actor) |
1213 | - renderer.AddViewProp(slice_data.box_actor) | |
1212 | + # renderer.AddViewProp(slice_data.box_actor) | |
1214 | 1213 | |
1215 | 1214 | return slice_data |
1216 | 1215 | ... | ... |
invesalius/gui/widgets/canvas_renderer.py
... | ... | @@ -586,7 +586,9 @@ class CanvasRendererCTX: |
586 | 586 | |
587 | 587 | return (xi, yi, xf, yf) |
588 | 588 | |
589 | - def draw_rectangle(self, pos, width, height, line_colour=(255, 0, 0, 128), fill_colour=(0, 0, 0, 0)): | |
589 | + def draw_rectangle(self, pos, width, height, line_colour=(255, 0, 0, 128), | |
590 | + fill_colour=(0, 0, 0, 0), line_width=1, pen_style=wx.PENSTYLE_SOLID, | |
591 | + brush_style=wx.BRUSHSTYLE_SOLID): | |
590 | 592 | """ |
591 | 593 | Draw a rectangle with its top left at pos and with the given width and height. |
592 | 594 | |
... | ... | @@ -603,9 +605,11 @@ class CanvasRendererCTX: |
603 | 605 | |
604 | 606 | px, py = pos |
605 | 607 | py = -py |
606 | - gc.SetPen(wx.Pen(wx.Colour(*line_colour))) | |
607 | - gc.SetBrush(wx.Brush(wx.Colour(*fill_colour))) | |
608 | - gc.DrawRectangle(px, py, width, height) | |
608 | + pen = wx.Pen(wx.Colour(*line_colour), width=line_width, style=pen_style) | |
609 | + brush = wx.Brush(wx.Colour(*fill_colour), style=brush_style) | |
610 | + gc.SetPen(pen) | |
611 | + gc.SetBrush(brush) | |
612 | + gc.DrawRectangle(px, py, width, -height) | |
609 | 613 | self._drawn = True |
610 | 614 | |
611 | 615 | def draw_text(self, text, pos, font=None, txt_colour=(255, 255, 255)): |
... | ... | @@ -666,7 +670,7 @@ class CanvasRendererCTX: |
666 | 670 | |
667 | 671 | # Drawing the box |
668 | 672 | cw, ch = w + border * 2, h + border * 2 |
669 | - self.draw_rectangle((px, py), cw, ch, bg_colour, bg_colour) | |
673 | + self.draw_rectangle((px, py - ch), cw, ch, bg_colour, bg_colour) | |
670 | 674 | |
671 | 675 | # Drawing the text |
672 | 676 | tpx, tpy = px + border, py - border |
... | ... | @@ -817,7 +821,7 @@ class TextBox(CanvasHandlerBase): |
817 | 821 | bg_colour=self.box_colour) |
818 | 822 | if self._highlight: |
819 | 823 | rw, rh = canvas.evt_renderer.GetSize() |
820 | - canvas.draw_rectangle((px, py), w, h, | |
824 | + canvas.draw_rectangle((px, py - h), w, h, | |
821 | 825 | (255, 0, 0, 25), |
822 | 826 | (255, 0, 0, 25)) |
823 | 827 | ... | ... |