#============================================================================== # # Project: SharpImage # Module: ImageToImageScript.py # Language: IronPython # Author: Dan Mueller # Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ # Revision: $Revision: 2 $ # # Copyright (c) Queensland University of Technology (QUT) 2007. # All rights reserved. # # This software is distributed WITHOUT ANY WARRANTY; without even # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the above copyright notices for more information. # #============================================================================== # Import the base script class import ThreadedScript from ThreadedScript import * from System import String class ImageToImageScriptObject(ThreadedScriptObject): Renderer = None Input = None Output = None def Initialise(self): """ Initialise the environment for running this script. """ """ NOTE: This function is invoked on the main UI thread. """ try: ThreadedScriptObject.Initialise( self ) self.Renderer = self.ParentApplication.CurrentRenderer self.Input = self.Renderer.Inputs[0] self.Output = itkImage.New( self.Input ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) ScriptObject.Finalise( self ) def Finalise(self): """ Finalise the environment after running this script. """ """ NOTE: This function is invoked on the main UI thread. """ try: if (self.Output != None): self.Output.DisconnectPipeline( ) self.ParentApplication.ShowImageInNewRenderer( self.Output ) ThreadedScriptObject.Finalise( self ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) ScriptObject.Finalise( self ) def DisconnectInputAndOutput(self): """ Disconnect both the input and output images from the pipeline. """ if (self.Input != None and not self.Input.IsDisposed): self.Input.DisconnectPipeline() if (self.Output != None and not self.Output.IsDisposed): self.Output.DisconnectPipeline() def WriteOutputName(self): """ Set and write the output name to the console. """ self.WriteOutputNameWithSuffix( self.Name ) def WriteOutputNameWithSuffix(self, suffix): """ Set and write the output name to the console. """ pathInput = Path.GetDirectoryName( self.Input.Name ) nameInput = Path.GetFileNameWithoutExtension( self.Input.Name ) extInput = Path.GetExtension( self.Input.Name ) fileOutput = Path.Combine( pathInput, nameInput + "_" + suffix + extInput ) self.WriteGivenOutputName( fileOutput ) def WriteGivenOutputName(self, name): """ Set and write the output name to the console. """ self.Output.Name = name self.WriteImageName( "Output=", self.Output ) def WriteInputName(self): """ Write the name of the input image to the console. """ self.WriteImageName( "Input=", self.Input )