Commit 2abd1cd3debfbe8beb713a367f1f09159bb3a754
1 parent
35e84cbf
Exists in
measure_improvements
Improvements
Showing
3 changed files
with
42 additions
and
16 deletions
Show diff stats
invesalius/data/measures.py
... | ... | @@ -22,13 +22,19 @@ LOCATION = {const.SURFACE: _(u"3D"), |
22 | 22 | const.SAGITAL: _(u"Sagittal") |
23 | 23 | } |
24 | 24 | |
25 | -map_locations = { | |
25 | +map_locations_id = { | |
26 | 26 | "3D": const.SURFACE, |
27 | 27 | "AXIAL": const.AXIAL, |
28 | 28 | "CORONAL": const.CORONAL, |
29 | 29 | "SAGITAL": const.SAGITAL, |
30 | 30 | } |
31 | 31 | |
32 | +map_id_locations = {const.SURFACE: "3D", | |
33 | + const.AXIAL: "AXIAL", | |
34 | + const.CORONAL: "CORONAL", | |
35 | + const.SAGITAL: "SAGITAL", | |
36 | + } | |
37 | + | |
32 | 38 | class MeasureData: |
33 | 39 | """ |
34 | 40 | Responsible to keep measures data. |
... | ... | @@ -49,17 +55,30 @@ class MeasureData: |
49 | 55 | |
50 | 56 | self._list_measures.append(m) |
51 | 57 | |
52 | - def pop(self, idx): | |
53 | - m = self._list_measures.pop(idx) | |
58 | + def get(self, location, slice_number): | |
59 | + return self.measures[map_locations_id[location]].get(slice_number, []) | |
60 | + | |
61 | + def pop(self, idx=None): | |
62 | + if idx is None: | |
63 | + m = self._list_measures.pop() | |
64 | + else: | |
65 | + m = self._list_measures.pop(idx) | |
54 | 66 | self.measures[m[0].location][m[0].slice_number].remove(m) |
55 | 67 | return m |
56 | 68 | |
69 | + def remove(self, m): | |
70 | + self._list_measures.remove(m) | |
71 | + self.measures[m[0].location][m[0].slice_number].remove(m) | |
72 | + | |
73 | + def __contains__(self, m): | |
74 | + return m in self._list_measures | |
75 | + | |
76 | + def __getitem__(self, idx): | |
77 | + return self._list_measures[idx] | |
78 | + | |
57 | 79 | def __len__(self): |
58 | 80 | return len(self._list_measures) |
59 | 81 | |
60 | - def __getitem__(self, key): | |
61 | - return self.measures[map_locations[key]] | |
62 | - | |
63 | 82 | |
64 | 83 | class MeasurementManager(object): |
65 | 84 | """ |
... | ... | @@ -126,6 +145,7 @@ class MeasurementManager(object): |
126 | 145 | position = pubsub_evt.data[0] |
127 | 146 | type = pubsub_evt.data[1] # Linear or Angular |
128 | 147 | location = pubsub_evt.data[2] # 3D, AXIAL, SAGITAL, CORONAL |
148 | + renderer = pubsub_evt.data[-1] | |
129 | 149 | |
130 | 150 | if location == const.SURFACE: |
131 | 151 | slice_number = 0 |
... | ... | @@ -173,16 +193,18 @@ class MeasurementManager(object): |
173 | 193 | mr = LinearMeasure(m.colour, representation) |
174 | 194 | else: |
175 | 195 | mr = AngularMeasure(m.colour, representation) |
196 | + mr.renderer = renderer | |
176 | 197 | if to_remove: |
177 | 198 | print "---To REMOVE" |
178 | - actors = self.current[1].GetActors() | |
179 | - slice_number = self.current[0].slice_number | |
180 | - Publisher.sendMessage(('Remove actors ' + str(self.current[0].location)), | |
181 | - (actors, slice_number)) | |
199 | + # actors = self.current[1].GetActors() | |
200 | + # slice_number = self.current[0].slice_number | |
201 | + # Publisher.sendMessage(('Remove actors ' + str(self.current[0].location)), | |
202 | + # (actors, slice_number)) | |
203 | + self.measures.pop()[1].Remove() | |
182 | 204 | if self.current[0].location == const.SURFACE: |
183 | 205 | Publisher.sendMessage('Render volume viewer') |
184 | 206 | else: |
185 | - Publisher.sendMessage('Update slice viewer') | |
207 | + Publisher.sendMessage('Reload actual slice') | |
186 | 208 | |
187 | 209 | session = ses.Session() |
188 | 210 | session.ChangeProject() |
... | ... | @@ -198,10 +220,12 @@ class MeasurementManager(object): |
198 | 220 | # Publisher.sendMessage("Add actors " + str(location), |
199 | 221 | # (actors, m.slice_number)) |
200 | 222 | |
223 | + if self.current not in self.measures: | |
224 | + self.measures.append(self.current) | |
225 | + | |
201 | 226 | if mr.IsComplete(): |
202 | 227 | index = prj.Project().AddMeasurement(m) |
203 | 228 | #m.index = index # already done in proj |
204 | - self.measures.append(self.current) | |
205 | 229 | name = m.name |
206 | 230 | colour = m.colour |
207 | 231 | m.value = mr.GetValue() |
... | ... | @@ -222,7 +246,7 @@ class MeasurementManager(object): |
222 | 246 | |
223 | 247 | def _change_name(self, pubsub_evt): |
224 | 248 | index, new_name = pubsub_evt.data |
225 | - self.measures[index][0].name = new_name | |
249 | + self.measures[index].name = new_name | |
226 | 250 | |
227 | 251 | def _remove_measurements(self, pubsub_evt): |
228 | 252 | indexes = pubsub_evt.data |
... | ... | @@ -257,6 +281,7 @@ class MeasurementManager(object): |
257 | 281 | print "RM INC M", self.current, mr.IsComplete() |
258 | 282 | if not mr.IsComplete(): |
259 | 283 | print "---To REMOVE" |
284 | + self.measures.pop() | |
260 | 285 | actors = mr.GetActors() |
261 | 286 | slice_number = self.current[0].slice_number |
262 | 287 | Publisher.sendMessage(('Remove actors ' + str(self.current[0].location)), | ... | ... |
invesalius/data/styles.py
... | ... | @@ -385,10 +385,11 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): |
385 | 385 | self.selected = selected |
386 | 386 | else: |
387 | 387 | if self.picker.GetViewProp(): |
388 | + renderer = self.viewer.slice_data.renderer | |
388 | 389 | Publisher.sendMessage("Add measurement point", |
389 | 390 | ((x, y,z), const.LINEAR, |
390 | 391 | ORIENTATIONS[self.orientation], |
391 | - slice_number, self.radius)) | |
392 | + slice_number, self.radius, renderer)) | |
392 | 393 | Publisher.sendMessage('Reload actual slice %s' % self.orientation) |
393 | 394 | |
394 | 395 | def OnReleaseMeasurePoint(self, obj, evt): | ... | ... |
invesalius/data/viewer_slice.py
... | ... | @@ -1184,11 +1184,11 @@ class Viewer(wx.Panel): |
1184 | 1184 | for actor in self.actors_by_slice_number[index]: |
1185 | 1185 | self.slice_data.renderer.AddActor(actor) |
1186 | 1186 | |
1187 | - for (m, mr) in self.measures[self.orientation].get(self.slice_data.number, []): | |
1187 | + for (m, mr) in self.measures.get(self.orientation, self.slice_data.number): | |
1188 | 1188 | for actor in mr.GetActors(): |
1189 | 1189 | self.slice_data.renderer.RemoveActor(actor) |
1190 | 1190 | |
1191 | - for (m, mr) in self.measures[self.orientation].get(index, []): | |
1191 | + for (m, mr) in self.measures.get(self.orientation, index): | |
1192 | 1192 | for actor in mr.GetActors(): |
1193 | 1193 | self.slice_data.renderer.AddActor(actor) |
1194 | 1194 | ... | ... |