From: <mva...@us...> - 2011-09-08 18:24:26
|
Revision: 377 http://mevislabmodules.svn.sourceforge.net/mevislabmodules/?rev=377&view=rev Author: mvanstralen Date: 2011-09-08 18:24:20 +0000 (Thu, 08 Sep 2011) Log Message: ----------- Added option to save resulting transformation file at different location Modified Paths: -------------- trunk/Community/General/Modules/Macros/Elastix/CallElastix.py trunk/Community/General/Modules/Macros/Elastix/CallElastix.script trunk/Community/General/Modules/Macros/Elastix/Elastix.script Modified: trunk/Community/General/Modules/Macros/Elastix/CallElastix.py =================================================================== --- trunk/Community/General/Modules/Macros/Elastix/CallElastix.py 2011-09-08 18:21:30 UTC (rev 376) +++ trunk/Community/General/Modules/Macros/Elastix/CallElastix.py 2011-09-08 18:24:20 UTC (rev 377) @@ -232,7 +232,74 @@ print "Error: path contains spaces!"; if (len(ctx.field("outputDirectory").value) > 0 and ctx.field("outputDirectory").value[-1] != '/'): ctx.field("outputDirectory").value += '/'; + +def saveResultingTransformationFileAs(): + origFn = ctx.field("resultingTransformationFile").value; + if len(origFn)>0: + if MLABFileManager.exists(origFn): + newFn = MLABFileDialog.getSaveFileName("", "*.txt", "Save transformation file as..."); + saveTransformationFileAs(origFn, newFn); + else : + print "Error: file does not exist (anymore)."; + else : + print "Nothing to save!"; + +def saveTransformationFileAs(origFn, newFn): + # collect initial transform parameter files recursively + initFiles = []; + initFn = getInitialTransformParameters(origFn); + while len(initFn) >0: + initFiles += [initFn]; + initFn = getInitialTransformParameters(initFn); + parentFile = newFn; + # save transformation file + MLABFileManager.copy(origFn, newFn); + # save initial transformation files with numbering [0,...> in order of application + parentFn = newFn; + for i in range(len(initFiles)): + newExt = "." + str(len(initFiles)-i-1) + ".txt"; + newInitFn = newFn.replace(".txt", newExt); + MLABFileManager.copy(initFiles[i], newInitFn); + fileStringReplace(parentFn, initFiles[i], newInitFn); + parentFn = newInitFn; + # save transformation file, also with consistent numbering + newExt = "." + str(len(initFiles)) + ".txt"; + MLABFileManager.copy(newFn, newFn.replace(".txt", newExt)); + + +# look for initial transform parameters, like (InitialTransformParametersFileName "C:/Temp/reg3/TransformParameters.0.txt") +def getInitialTransformParameters(fn): + if MLABFileManager.exists(fn): + with open(fn) as f: + for l in f: + if l.find("InitialTransformParametersFileName") >=0: + #print l; + t = l.replace("(", ""); + t = t.replace(")", ""); + parts = t.split(); + #print "File = " + parts[1]; + tf = parts[1].replace("\"", ""); #remove quotes + if tf != "NoInitialTransform": + return tf; + else : + return ""; + return ""; + else : + print "Error: could not open transformation file " + fn; + return ""; +def fileStringReplace(fn, src, dst): + if MLABFileManager.exists(fn): + lines = []; + with open(fn, 'r') as f: + for l in f: + lines += [l.replace(src, dst)]; + with open(fn, 'w') as f: + for l in lines: + f.write(l); + else : + print "Error: could not open file for replacement, " + fn; + #//# MeVis signature v1 #//# key: MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANEfsmYse2e1dRhkQ9AQbreCq9uxwzWLoGom13MNYmyfwoJqQOEXljLFAgw2eEjaT12G4CdqKWhRxh9ANP6n7GMCARE=:VI/mB8bT4u+mRtf/ru8yUQi8BzpaS3UeL2x62YxsUYnVqCWuLrVNLiukIIjnJMKQXlc8ezmgOIcVAV7pgvgKpQ== #//# owner: MeVis Modified: trunk/Community/General/Modules/Macros/Elastix/CallElastix.script =================================================================== --- trunk/Community/General/Modules/Macros/Elastix/CallElastix.script 2011-09-08 18:21:30 UTC (rev 376) +++ trunk/Community/General/Modules/Macros/Elastix/CallElastix.script 2011-09-08 18:24:20 UTC (rev 377) @@ -72,6 +72,7 @@ Field succeeded { type = Bool value = False persistent = No} Field transformParameterFile { type = string } + Field saveResultingTransformationFile { type = Trigger } } } @@ -91,6 +92,7 @@ command = clearLog } FieldListener outputDirectory { command = checkTemporaryDirectory } + FieldListener saveResultingTransformationFile { command = saveResultingTransformationFileAs } } Window { @@ -107,7 +109,10 @@ Field parameterFile3 { browseButton = True browseMode = open browseFilter = "\*.txt" } //Horizontal { alignGroupX = parameterFile3 Label { title = "Number of threads:"} ButtonBar numberOfThreads { } } Field initialTransformationFile { browseButton = True browseFilter = "\*.txt" browseMode = open expandX = True} - Field resultingTransformationFile { edit = False expandX = True} + Horizontal { + Field resultingTransformationFile { edit = False expandX = True} + Button saveResultingTransformationFile { title = "Save as..."} + } Field numberOfThreads { expandX = 1} Field otherArguments { expandY = True } Field createDeformationImage { enabled = True } Modified: trunk/Community/General/Modules/Macros/Elastix/Elastix.script =================================================================== --- trunk/Community/General/Modules/Macros/Elastix/Elastix.script 2011-09-08 18:21:30 UTC (rev 376) +++ trunk/Community/General/Modules/Macros/Elastix/Elastix.script 2011-09-08 18:24:20 UTC (rev 377) @@ -82,6 +82,7 @@ Field resultingTransformationFile {internalName = CallElastix.resultingTransformationFile persistent = No} Field outputImageDataType {internalName = itkImageFileReader1.fileDataType value = "float"} Field succeeded { internalName = CallElastix.succeeded persistent = No} + Field saveResultingTransformationFile { internalName = CallElastix.saveResultingTransformationFile } } } @@ -104,7 +105,10 @@ Field parameterFile2 { browseButton = True browseFilter = "\*.txt" browseMode = open expandX = True} Field parameterFile3 { browseButton = True browseFilter = "\*.txt" browseMode = open expandX = True} Field initialTransformationFile { browseButton = True browseFilter = "\*.txt" browseMode = open expandX = True} - Field resultingTransformationFile { edit = False expandX = True} + Horizontal { + Field resultingTransformationFile { edit = False expandX = True} + Button saveResultingTransformationFile { title = "Save as..." } + } Field numberOfThreads { expandX = 1} Field otherArguments { expandX = True} Field outputImageDataType { expandX = 1} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |