Commit ff84d81a1e96318375aa18e90217ab6272dc9c3e
1 parent
a07959c7
Exists in
master
and in
6 other branches
ADD: Measurement write/load into inv3
Showing
3 changed files
with
44 additions
and
3 deletions
Show diff stats
invesalius/control.py
... | ... | @@ -359,6 +359,9 @@ class Controller(): |
359 | 359 | mask_index = len(proj.mask_dict) -1 |
360 | 360 | ps.Publisher().sendMessage('Show mask', (mask_index, True)) |
361 | 361 | |
362 | + ps.Publisher().sendMessage('Load measurement dict', | |
363 | + proj.measurement_dict) | |
364 | + | |
362 | 365 | proj.presets.thresh_ct[_('Custom')] = proj.threshold_range |
363 | 366 | ps.Publisher().sendMessage('End busy cursor') |
364 | 367 | ... | ... |
invesalius/data/measures.py
... | ... | @@ -117,13 +117,24 @@ class Measurement(): |
117 | 117 | self.index = Measurement.general_index |
118 | 118 | self.name = const.MEASURE_NAME_PATTERN %(self.index+1) |
119 | 119 | self.colour = random.choice(const.MASK_COLOUR) |
120 | - self.value = None | |
120 | + self.value = 0 | |
121 | 121 | self.location = const.SURFACE # AXIAL, CORONAL, SAGITTAL |
122 | 122 | self.type = const.LINEAR # ANGULAR |
123 | 123 | self.slice_number = 0 |
124 | 124 | self.points = [] |
125 | 125 | self.is_shown = False |
126 | 126 | |
127 | + def Load(self, info): | |
128 | + self.index = info["index"] | |
129 | + self.name = info["name"] | |
130 | + self.colour = info["colour"] | |
131 | + self.value = info["value"] | |
132 | + self.location = info["location"] | |
133 | + self.type = info["type"] | |
134 | + self.slice_number = info["slice_number"] | |
135 | + self.points = info["points"] | |
136 | + self.is_shown = info["is_shown"] | |
137 | + | |
127 | 138 | class CirclePointRepresentation(object): |
128 | 139 | """ |
129 | 140 | This class represents a circle that indicate a point in the surface | ... | ... |
invesalius/project.py
... | ... | @@ -185,6 +185,24 @@ class Project(object): |
185 | 185 | preset = plistlib.readPlist(path) |
186 | 186 | ps.Publisher.sendMessage('Set raycasting preset', preset) |
187 | 187 | |
188 | + def GetMeasuresDict(self): | |
189 | + measures = {} | |
190 | + d = self.measurement_dict | |
191 | + for i in d: | |
192 | + m = d[i] | |
193 | + item = {} | |
194 | + item["index"] = m.index | |
195 | + item["name"] = m.name | |
196 | + item["colour"] = m.colour | |
197 | + item["value"] = m.value | |
198 | + item["location"] = m.location | |
199 | + item["type"] = m.type | |
200 | + item["slice_number"] = m.slice_number | |
201 | + item["points"] = m.points | |
202 | + item["is_shown"] = m.is_shown | |
203 | + measures[str(m.index)] = item | |
204 | + return measures | |
205 | + | |
188 | 206 | def SavePlistProject(self, dir_, filename): |
189 | 207 | |
190 | 208 | # Some filenames have non-ascii characters and encoded in a strange |
... | ... | @@ -218,9 +236,10 @@ class Project(object): |
218 | 236 | for index in self.surface_dict: |
219 | 237 | surfaces[str(index)] = {'#surface':\ |
220 | 238 | self.surface_dict[index].SavePlist(filename_tmp)} |
221 | - | |
239 | + | |
222 | 240 | project['surface_dict'] = surfaces |
223 | 241 | project['mask_dict'] = masks |
242 | + project['measurement_dict'] = self.GetMeasuresDict() | |
224 | 243 | img_file = '%s_%s.vti' % (filename_tmp, 'imagedata') |
225 | 244 | iu.Export(self.imagedata, img_file, bin=True) |
226 | 245 | project['imagedata'] = {'$vti':os.path.split(img_file)[1].decode('utf-8')} |
... | ... | @@ -232,7 +251,8 @@ class Project(object): |
232 | 251 | shutil.rmtree(dir_temp) |
233 | 252 | |
234 | 253 | def OpenPlistProject(self, filename): |
235 | - | |
254 | + import data.measures as ms | |
255 | + | |
236 | 256 | if not const.VTK_WARNING: |
237 | 257 | log_path = os.path.join(const.LOG_FOLDER, 'vtkoutput.txt') |
238 | 258 | fow = vtk.vtkFileOutputWindow() |
... | ... | @@ -281,6 +301,13 @@ class Project(object): |
281 | 301 | s = srf.Surface() |
282 | 302 | s.OpenPList(path) |
283 | 303 | self.surface_dict[s.index] = s |
304 | + elif key == 'measurement_dict': | |
305 | + self.measurement_dict = {} | |
306 | + d = project['measurement_dict'] | |
307 | + for index in d: | |
308 | + measure = ms.Measurement() | |
309 | + measure.Load(d[index]) | |
310 | + self.measurement_dict[int(index)] = measure | |
284 | 311 | else: |
285 | 312 | setattr(self, key, project[key]) |
286 | 313 | ... | ... |