From ff84d81a1e96318375aa18e90217ab6272dc9c3e Mon Sep 17 00:00:00 2001 From: tatiana Date: Fri, 5 Mar 2010 18:40:33 +0000 Subject: [PATCH] ADD: Measurement write/load into inv3 --- invesalius/control.py | 3 +++ invesalius/data/measures.py | 13 ++++++++++++- invesalius/project.py | 31 +++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index e3b1c94..90c66cf 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -359,6 +359,9 @@ class Controller(): mask_index = len(proj.mask_dict) -1 ps.Publisher().sendMessage('Show mask', (mask_index, True)) + ps.Publisher().sendMessage('Load measurement dict', + proj.measurement_dict) + proj.presets.thresh_ct[_('Custom')] = proj.threshold_range ps.Publisher().sendMessage('End busy cursor') diff --git a/invesalius/data/measures.py b/invesalius/data/measures.py index 50622f7..994cdae 100644 --- a/invesalius/data/measures.py +++ b/invesalius/data/measures.py @@ -117,13 +117,24 @@ class Measurement(): self.index = Measurement.general_index self.name = const.MEASURE_NAME_PATTERN %(self.index+1) self.colour = random.choice(const.MASK_COLOUR) - self.value = None + self.value = 0 self.location = const.SURFACE # AXIAL, CORONAL, SAGITTAL self.type = const.LINEAR # ANGULAR self.slice_number = 0 self.points = [] self.is_shown = False + def Load(self, info): + self.index = info["index"] + self.name = info["name"] + self.colour = info["colour"] + self.value = info["value"] + self.location = info["location"] + self.type = info["type"] + self.slice_number = info["slice_number"] + self.points = info["points"] + self.is_shown = info["is_shown"] + class CirclePointRepresentation(object): """ This class represents a circle that indicate a point in the surface diff --git a/invesalius/project.py b/invesalius/project.py index 49999e2..bc565ac 100755 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -185,6 +185,24 @@ class Project(object): preset = plistlib.readPlist(path) ps.Publisher.sendMessage('Set raycasting preset', preset) + def GetMeasuresDict(self): + measures = {} + d = self.measurement_dict + for i in d: + m = d[i] + item = {} + item["index"] = m.index + item["name"] = m.name + item["colour"] = m.colour + item["value"] = m.value + item["location"] = m.location + item["type"] = m.type + item["slice_number"] = m.slice_number + item["points"] = m.points + item["is_shown"] = m.is_shown + measures[str(m.index)] = item + return measures + def SavePlistProject(self, dir_, filename): # Some filenames have non-ascii characters and encoded in a strange @@ -218,9 +236,10 @@ class Project(object): for index in self.surface_dict: surfaces[str(index)] = {'#surface':\ self.surface_dict[index].SavePlist(filename_tmp)} - + project['surface_dict'] = surfaces project['mask_dict'] = masks + project['measurement_dict'] = self.GetMeasuresDict() img_file = '%s_%s.vti' % (filename_tmp, 'imagedata') iu.Export(self.imagedata, img_file, bin=True) project['imagedata'] = {'$vti':os.path.split(img_file)[1].decode('utf-8')} @@ -232,7 +251,8 @@ class Project(object): shutil.rmtree(dir_temp) def OpenPlistProject(self, filename): - + import data.measures as ms + if not const.VTK_WARNING: log_path = os.path.join(const.LOG_FOLDER, 'vtkoutput.txt') fow = vtk.vtkFileOutputWindow() @@ -281,6 +301,13 @@ class Project(object): s = srf.Surface() s.OpenPList(path) self.surface_dict[s.index] = s + elif key == 'measurement_dict': + self.measurement_dict = {} + d = project['measurement_dict'] + for index in d: + measure = ms.Measurement() + measure.Load(d[index]) + self.measurement_dict[int(index)] = measure else: setattr(self, key, project[key]) -- libgit2 0.21.2