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