Commit ff84d81a1e96318375aa18e90217ab6272dc9c3e

Authored by tatiana
1 parent a07959c7

ADD: Measurement write/load into inv3

invesalius/control.py
@@ -359,6 +359,9 @@ class Controller(): @@ -359,6 +359,9 @@ class Controller():
359 mask_index = len(proj.mask_dict) -1 359 mask_index = len(proj.mask_dict) -1
360 ps.Publisher().sendMessage('Show mask', (mask_index, True)) 360 ps.Publisher().sendMessage('Show mask', (mask_index, True))
361 361
  362 + ps.Publisher().sendMessage('Load measurement dict',
  363 + proj.measurement_dict)
  364 +
362 proj.presets.thresh_ct[_('Custom')] = proj.threshold_range 365 proj.presets.thresh_ct[_('Custom')] = proj.threshold_range
363 ps.Publisher().sendMessage('End busy cursor') 366 ps.Publisher().sendMessage('End busy cursor')
364 367
invesalius/data/measures.py
@@ -117,13 +117,24 @@ class Measurement(): @@ -117,13 +117,24 @@ class Measurement():
117 self.index = Measurement.general_index 117 self.index = Measurement.general_index
118 self.name = const.MEASURE_NAME_PATTERN %(self.index+1) 118 self.name = const.MEASURE_NAME_PATTERN %(self.index+1)
119 self.colour = random.choice(const.MASK_COLOUR) 119 self.colour = random.choice(const.MASK_COLOUR)
120 - self.value = None 120 + self.value = 0
121 self.location = const.SURFACE # AXIAL, CORONAL, SAGITTAL 121 self.location = const.SURFACE # AXIAL, CORONAL, SAGITTAL
122 self.type = const.LINEAR # ANGULAR 122 self.type = const.LINEAR # ANGULAR
123 self.slice_number = 0 123 self.slice_number = 0
124 self.points = [] 124 self.points = []
125 self.is_shown = False 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 class CirclePointRepresentation(object): 138 class CirclePointRepresentation(object):
128 """ 139 """
129 This class represents a circle that indicate a point in the surface 140 This class represents a circle that indicate a point in the surface
invesalius/project.py
@@ -185,6 +185,24 @@ class Project(object): @@ -185,6 +185,24 @@ class Project(object):
185 preset = plistlib.readPlist(path) 185 preset = plistlib.readPlist(path)
186 ps.Publisher.sendMessage('Set raycasting preset', preset) 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 def SavePlistProject(self, dir_, filename): 206 def SavePlistProject(self, dir_, filename):
189 207
190 # Some filenames have non-ascii characters and encoded in a strange 208 # Some filenames have non-ascii characters and encoded in a strange
@@ -218,9 +236,10 @@ class Project(object): @@ -218,9 +236,10 @@ class Project(object):
218 for index in self.surface_dict: 236 for index in self.surface_dict:
219 surfaces[str(index)] = {'#surface':\ 237 surfaces[str(index)] = {'#surface':\
220 self.surface_dict[index].SavePlist(filename_tmp)} 238 self.surface_dict[index].SavePlist(filename_tmp)}
221 - 239 +
222 project['surface_dict'] = surfaces 240 project['surface_dict'] = surfaces
223 project['mask_dict'] = masks 241 project['mask_dict'] = masks
  242 + project['measurement_dict'] = self.GetMeasuresDict()
224 img_file = '%s_%s.vti' % (filename_tmp, 'imagedata') 243 img_file = '%s_%s.vti' % (filename_tmp, 'imagedata')
225 iu.Export(self.imagedata, img_file, bin=True) 244 iu.Export(self.imagedata, img_file, bin=True)
226 project['imagedata'] = {'$vti':os.path.split(img_file)[1].decode('utf-8')} 245 project['imagedata'] = {'$vti':os.path.split(img_file)[1].decode('utf-8')}
@@ -232,7 +251,8 @@ class Project(object): @@ -232,7 +251,8 @@ class Project(object):
232 shutil.rmtree(dir_temp) 251 shutil.rmtree(dir_temp)
233 252
234 def OpenPlistProject(self, filename): 253 def OpenPlistProject(self, filename):
235 - 254 + import data.measures as ms
  255 +
236 if not const.VTK_WARNING: 256 if not const.VTK_WARNING:
237 log_path = os.path.join(const.LOG_FOLDER, 'vtkoutput.txt') 257 log_path = os.path.join(const.LOG_FOLDER, 'vtkoutput.txt')
238 fow = vtk.vtkFileOutputWindow() 258 fow = vtk.vtkFileOutputWindow()
@@ -281,6 +301,13 @@ class Project(object): @@ -281,6 +301,13 @@ class Project(object):
281 s = srf.Surface() 301 s = srf.Surface()
282 s.OpenPList(path) 302 s.OpenPList(path)
283 self.surface_dict[s.index] = s 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 else: 311 else:
285 setattr(self, key, project[key]) 312 setattr(self, key, project[key])
286 313