Commit 49f7db8118515aa56f5673fd0f8532c7eb029ea1
1 parent
7e582d99
Exists in
master
and in
6 other branches
ENH: The intern borders in the slice data are white
Showing
2 changed files
with
89 additions
and
19 deletions
Show diff stats
invesalius/data/slice_data.py
... | ... | @@ -21,6 +21,14 @@ import vtk |
21 | 21 | import constants as const |
22 | 22 | import vtk_utils as vu |
23 | 23 | |
24 | +BORDER_UP = 1 | |
25 | +BORDER_DOWN = 2 | |
26 | +BORDER_LEFT = 4 | |
27 | +BORDER_RIGHT = 8 | |
28 | +BORDER_ALL = BORDER_UP | BORDER_DOWN | BORDER_LEFT | BORDER_RIGHT | |
29 | +BORDER_NONE = 0 | |
30 | + | |
31 | + | |
24 | 32 | class SliceData(object): |
25 | 33 | def __init__(self): |
26 | 34 | self.actor = None |
... | ... | @@ -42,6 +50,14 @@ class SliceData(object): |
42 | 50 | text.SetValue(self.number) |
43 | 51 | self.text = text |
44 | 52 | |
53 | + def __create_line_actor(self, line): | |
54 | + line_mapper = vtk.vtkPolyDataMapper2D() | |
55 | + line_mapper.SetInput(line.GetOutput()) | |
56 | + | |
57 | + line_actor = vtk.vtkActor2D() | |
58 | + line_actor.SetMapper(line_mapper) | |
59 | + return line_actor | |
60 | + | |
45 | 61 | def __create_box(self): |
46 | 62 | xi = yi = 0.1 |
47 | 63 | xf = yf = 200 |
... | ... | @@ -49,35 +65,68 @@ class SliceData(object): |
49 | 65 | line_i.SetPoint1((xi, yi, 0)) |
50 | 66 | line_i.SetPoint2((xf, yi, 0)) |
51 | 67 | self.line_i = line_i |
68 | + self.line_i_actor = self.__create_line_actor(line_i) | |
52 | 69 | |
53 | 70 | line_s = vtk.vtkLineSource() |
54 | 71 | line_s.SetPoint1((xi, yf, 0)) |
55 | 72 | line_s.SetPoint2((xf, yf, 0)) |
56 | 73 | self.line_s = line_s |
74 | + self.line_s_actor = self.__create_line_actor(line_s) | |
57 | 75 | |
58 | 76 | line_l = vtk.vtkLineSource() |
59 | 77 | line_l.SetPoint1((xi, yi, 0)) |
60 | 78 | line_l.SetPoint2((xi, yf, 0)) |
61 | 79 | self.line_l = line_l |
62 | - | |
80 | + self.line_l_actor = self.__create_line_actor(line_l) | |
81 | + | |
63 | 82 | line_r = vtk.vtkLineSource() |
64 | 83 | line_r.SetPoint1((xf, yi, 0)) |
65 | 84 | line_r.SetPoint2((xf, yf, 0)) |
66 | 85 | 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) | |
86 | + self.line_r_actor = self.__create_line_actor(line_r) | |
87 | + | |
88 | + box_actor = vtk.vtkPropAssembly() | |
89 | + box_actor.AddPart(self.line_i_actor) | |
90 | + box_actor.AddPart(self.line_s_actor) | |
91 | + box_actor.AddPart(self.line_l_actor) | |
92 | + box_actor.AddPart(self.line_r_actor) | |
79 | 93 | self.box_actor = box_actor |
80 | 94 | |
95 | + def __set_border_colours(self, colours_borders): | |
96 | + for colour, actors in colours_borders.items(): | |
97 | + for actor in actors: | |
98 | + actor.GetProperty().SetColor(colour) | |
99 | + | |
100 | + def SetBorderStyle(self, style=BORDER_NONE): | |
101 | + colour_e = const.ORIENTATION_COLOUR[self.orientation] | |
102 | + colour_i = (1, 1, 1) | |
103 | + | |
104 | + extern_borders = [] | |
105 | + intern_borders = [] | |
106 | + | |
107 | + if style & BORDER_UP: | |
108 | + extern_borders.append(self.line_s_actor) | |
109 | + else: | |
110 | + intern_borders.append(self.line_s_actor) | |
111 | + | |
112 | + if style & BORDER_DOWN: | |
113 | + extern_borders.append(self.line_i_actor) | |
114 | + else: | |
115 | + intern_borders.append(self.line_i_actor) | |
116 | + | |
117 | + if style & BORDER_LEFT: | |
118 | + extern_borders.append(self.line_l_actor) | |
119 | + else: | |
120 | + intern_borders.append(self.line_l_actor) | |
121 | + | |
122 | + if style & BORDER_RIGHT: | |
123 | + extern_borders.append(self.line_r_actor) | |
124 | + else: | |
125 | + intern_borders.append(self.line_r_actor) | |
126 | + | |
127 | + self.__set_border_colours({colour_i: intern_borders, | |
128 | + colour_e: extern_borders}) | |
129 | + | |
81 | 130 | def SetCursor(self, cursor): |
82 | 131 | if self.cursor: |
83 | 132 | self.renderer.RemoveActor(self.cursor.actor) |
... | ... | @@ -92,7 +141,8 @@ class SliceData(object): |
92 | 141 | self.orientation = orientation |
93 | 142 | colour = const.ORIENTATION_COLOUR[self.orientation] |
94 | 143 | self.text.SetColour(colour) |
95 | - self.box_actor.GetProperty().SetColor(colour) | |
144 | + #self.box_actor.GetProperty().SetColor(colour) | |
145 | + | |
96 | 146 | |
97 | 147 | def SetSize(self, size): |
98 | 148 | w, h = size |
... | ... | @@ -115,9 +165,7 @@ class SliceData(object): |
115 | 165 | def Hide(self): |
116 | 166 | self.renderer.RemoveActor(self.actor) |
117 | 167 | self.renderer.RemoveActor(self.text.actor) |
118 | - self.renderer.RemoveActor(self.box_actor) | |
119 | 168 | |
120 | 169 | def Show(self): |
121 | 170 | self.renderer.AddActor(self.actor) |
122 | 171 | self.renderer.AddActor(self.text.actor) |
123 | - self.renderer.AddActor(self.box_actor) | ... | ... |
invesalius/data/viewer_slice.py
... | ... | @@ -35,7 +35,7 @@ import data.slice_ as sl |
35 | 35 | import data.vtk_utils as vtku |
36 | 36 | import mode as md |
37 | 37 | import project |
38 | -from slice_data import SliceData | |
38 | +import slice_data as sd | |
39 | 39 | |
40 | 40 | ID_TO_TOOL_ITEM = {} |
41 | 41 | STR_WL = "WL: %d WW: %d" |
... | ... | @@ -860,8 +860,24 @@ class Viewer(wx.Panel): |
860 | 860 | slice_data.SetCursor(self.__create_cursor()) |
861 | 861 | slice_data.SetSize((w, h)) |
862 | 862 | self.__update_camera(slice_data) |
863 | + | |
864 | + style = 0 | |
865 | + if j == 0: | |
866 | + style = style | sd.BORDER_DOWN | |
867 | + if j == self.layout[1] - 1: | |
868 | + style = style | sd.BORDER_UP | |
869 | + | |
870 | + if i == 0: | |
871 | + style = style | sd.BORDER_LEFT | |
872 | + if i == self.layout[0] - 1: | |
873 | + style = style | sd.BORDER_RIGHT | |
874 | + | |
875 | + print "->Style", style | |
876 | + | |
877 | + slice_data.SetBorderStyle(style) | |
863 | 878 | n += 1 |
864 | 879 | |
880 | + | |
865 | 881 | def __create_cursor(self): |
866 | 882 | cursor = ca.CursorCircle() |
867 | 883 | cursor.SetOrientation(self.orientation) |
... | ... | @@ -1082,13 +1098,14 @@ class Viewer(wx.Panel): |
1082 | 1098 | self.interactor.GetRenderWindow().AddRenderer(renderer) |
1083 | 1099 | actor = vtk.vtkImageActor() |
1084 | 1100 | actor.SetInput(imagedata) |
1085 | - slice_data = SliceData() | |
1101 | + slice_data = sd.SliceData() | |
1086 | 1102 | slice_data.SetOrientation(self.orientation) |
1087 | 1103 | slice_data.renderer = renderer |
1088 | 1104 | slice_data.actor = actor |
1105 | + slice_data.SetBorderStyle(sd.BORDER_UP | sd.BORDER_DOWN) | |
1089 | 1106 | renderer.AddActor(actor) |
1090 | 1107 | renderer.AddActor(slice_data.text.actor) |
1091 | - renderer.AddActor(slice_data.box_actor) | |
1108 | + renderer.AddViewProp(slice_data.box_actor) | |
1092 | 1109 | return slice_data |
1093 | 1110 | |
1094 | 1111 | def __update_camera(self, slice_data): |
... | ... | @@ -1199,6 +1216,11 @@ class Viewer(wx.Panel): |
1199 | 1216 | |
1200 | 1217 | def OnSize(self, evt): |
1201 | 1218 | w, h = self.interactor.GetRenderWindow().GetSize() |
1219 | + print "OnSize" | |
1220 | + print w, h | |
1221 | + print evt.GetSize() | |
1222 | + print self.interactor.GetRenderWindow().GetPosition() | |
1223 | ||
1202 | 1224 | w = float(w) / self.layout[0] |
1203 | 1225 | h = float(h) / self.layout[1] |
1204 | 1226 | for slice_data in self.slice_data_list: | ... | ... |