Commit 936bc3a07f8ef2a46caae24d640a50680892fdbf
1 parent
45d38bff
Exists in
master
and in
67 other branches
ENH: reduced the number of temp files needed to save an InVesalius 3 project wha…
…t make it a little faster
Showing
2 changed files
with
21 additions
and
7 deletions
Show diff stats
invesalius/data/mask.py
@@ -51,12 +51,13 @@ class Mask(): | @@ -51,12 +51,13 @@ class Mask(): | ||
51 | Publisher.subscribe(self.OnFlipVolume, 'Flip volume') | 51 | Publisher.subscribe(self.OnFlipVolume, 'Flip volume') |
52 | Publisher.subscribe(self.OnSwapVolumeAxes, 'Swap volume axes') | 52 | Publisher.subscribe(self.OnSwapVolumeAxes, 'Swap volume axes') |
53 | 53 | ||
54 | - def SavePlist(self, dir_temp): | 54 | + def SavePlist(self, dir_temp, filelist): |
55 | mask = {} | 55 | mask = {} |
56 | filename = u'mask_%d' % self.index | 56 | filename = u'mask_%d' % self.index |
57 | mask_filename = u'%s.dat' % filename | 57 | mask_filename = u'%s.dat' % filename |
58 | mask_filepath = os.path.join(dir_temp, mask_filename) | 58 | mask_filepath = os.path.join(dir_temp, mask_filename) |
59 | - self._save_mask(mask_filepath) | 59 | + filelist[self.temp_file] = mask_filename |
60 | + #self._save_mask(mask_filepath) | ||
60 | 61 | ||
61 | mask['index'] = self.index | 62 | mask['index'] = self.index |
62 | mask['name'] = self.name | 63 | mask['name'] = self.name |
@@ -69,8 +70,13 @@ class Mask(): | @@ -69,8 +70,13 @@ class Mask(): | ||
69 | mask['mask_shape'] = self.matrix.shape | 70 | mask['mask_shape'] = self.matrix.shape |
70 | 71 | ||
71 | plist_filename = filename + '.plist' | 72 | plist_filename = filename + '.plist' |
72 | - plist_filepath = os.path.join(dir_temp, plist_filename) | ||
73 | - plistlib.writePlist(mask, plist_filepath) | 73 | + #plist_filepath = os.path.join(dir_temp, plist_filename) |
74 | + | ||
75 | + temp_plist = tempfile.mktemp() | ||
76 | + plistlib.writePlist(mask, temp_plist) | ||
77 | + | ||
78 | + filelist[temp_plist] = plist_filename | ||
79 | + | ||
74 | return plist_filename | 80 | return plist_filename |
75 | 81 | ||
76 | def OpenPList(self, filename): | 82 | def OpenPList(self, filename): |
invesalius/data/surface.py
@@ -21,6 +21,7 @@ import multiprocessing | @@ -21,6 +21,7 @@ import multiprocessing | ||
21 | import os | 21 | import os |
22 | import plistlib | 22 | import plistlib |
23 | import random | 23 | import random |
24 | +import tempfile | ||
24 | import weakref | 25 | import weakref |
25 | 26 | ||
26 | import vtk | 27 | import vtk |
@@ -62,11 +63,14 @@ class Surface(): | @@ -62,11 +63,14 @@ class Surface(): | ||
62 | else: | 63 | else: |
63 | self.name = name | 64 | self.name = name |
64 | 65 | ||
65 | - def SavePlist(self, dir_temp): | 66 | + def SavePlist(self, dir_temp, filelist): |
66 | filename = 'surface_%d' % self.index | 67 | filename = 'surface_%d' % self.index |
67 | vtp_filename = filename + '.vtp' | 68 | vtp_filename = filename + '.vtp' |
68 | vtp_filepath = os.path.join(dir_temp, vtp_filename) | 69 | vtp_filepath = os.path.join(dir_temp, vtp_filename) |
69 | pu.Export(self.polydata, vtp_filepath, bin=True) | 70 | pu.Export(self.polydata, vtp_filepath, bin=True) |
71 | + | ||
72 | + filelist[vtp_filepath] = vtp_filename | ||
73 | + | ||
70 | surface = {'colour': self.colour, | 74 | surface = {'colour': self.colour, |
71 | 'index': self.index, | 75 | 'index': self.index, |
72 | 'name': self.name, | 76 | 'name': self.name, |
@@ -76,8 +80,12 @@ class Surface(): | @@ -76,8 +80,12 @@ class Surface(): | ||
76 | 'volume': self.volume, | 80 | 'volume': self.volume, |
77 | } | 81 | } |
78 | plist_filename = filename + '.plist' | 82 | plist_filename = filename + '.plist' |
79 | - plist_filepath = os.path.join(dir_temp, filename + '.plist') | ||
80 | - plistlib.writePlist(surface, plist_filepath) | 83 | + #plist_filepath = os.path.join(dir_temp, filename + '.plist') |
84 | + temp_plist = tempfile.mktemp() | ||
85 | + plistlib.writePlist(surface, temp_plist) | ||
86 | + | ||
87 | + filelist[temp_plist] = plist_filename | ||
88 | + | ||
81 | return plist_filename | 89 | return plist_filename |
82 | 90 | ||
83 | def OpenPList(self, filename): | 91 | def OpenPList(self, filename): |