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 | 51 | Publisher.subscribe(self.OnFlipVolume, 'Flip volume') |
| 52 | 52 | Publisher.subscribe(self.OnSwapVolumeAxes, 'Swap volume axes') |
| 53 | 53 | |
| 54 | - def SavePlist(self, dir_temp): | |
| 54 | + def SavePlist(self, dir_temp, filelist): | |
| 55 | 55 | mask = {} |
| 56 | 56 | filename = u'mask_%d' % self.index |
| 57 | 57 | mask_filename = u'%s.dat' % filename |
| 58 | 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 | 62 | mask['index'] = self.index |
| 62 | 63 | mask['name'] = self.name |
| ... | ... | @@ -69,8 +70,13 @@ class Mask(): |
| 69 | 70 | mask['mask_shape'] = self.matrix.shape |
| 70 | 71 | |
| 71 | 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 | 80 | return plist_filename |
| 75 | 81 | |
| 76 | 82 | def OpenPList(self, filename): | ... | ... |
invesalius/data/surface.py
| ... | ... | @@ -21,6 +21,7 @@ import multiprocessing |
| 21 | 21 | import os |
| 22 | 22 | import plistlib |
| 23 | 23 | import random |
| 24 | +import tempfile | |
| 24 | 25 | import weakref |
| 25 | 26 | |
| 26 | 27 | import vtk |
| ... | ... | @@ -62,11 +63,14 @@ class Surface(): |
| 62 | 63 | else: |
| 63 | 64 | self.name = name |
| 64 | 65 | |
| 65 | - def SavePlist(self, dir_temp): | |
| 66 | + def SavePlist(self, dir_temp, filelist): | |
| 66 | 67 | filename = 'surface_%d' % self.index |
| 67 | 68 | vtp_filename = filename + '.vtp' |
| 68 | 69 | vtp_filepath = os.path.join(dir_temp, vtp_filename) |
| 69 | 70 | pu.Export(self.polydata, vtp_filepath, bin=True) |
| 71 | + | |
| 72 | + filelist[vtp_filepath] = vtp_filename | |
| 73 | + | |
| 70 | 74 | surface = {'colour': self.colour, |
| 71 | 75 | 'index': self.index, |
| 72 | 76 | 'name': self.name, |
| ... | ... | @@ -76,8 +80,12 @@ class Surface(): |
| 76 | 80 | 'volume': self.volume, |
| 77 | 81 | } |
| 78 | 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 | 89 | return plist_filename |
| 82 | 90 | |
| 83 | 91 | def OpenPList(self, filename): | ... | ... |