def fileName2xml(filename): """Here we create the XML string to be passed to the EDNA plugin from the input filename This can / should be modified by the final user @param filename: full path of the input file @type filename: python string representing the path @rtype: XML string @return: python string """ if filename.endswith(".jpg"): xm = None else: upperDir = os.path.dirname(os.path.dirname(filename)) if not os.path.isdir(os.path.join(upperDir, "Thumbnail")): os.makedirs(os.path.join(upperDir, "Thumbnail"), int("775", 8)) destinationPath = os.path.join(upperDir, "Thumbnail") xsd = XSDataInputExecThumbnail() xsdFile = XSDataFile() xsdFile.setPath(XSDataString(filename)) xsd.setInputImagePath(xsdFile) xsdPath = XSDataFile() xsdPath.setPath(XSDataString(destinationPath)) xsd.setOutputPath(xsdPath) xsd.setLevelsColorize(XSDataBoolean(True)) xsd.setLevelsNormalize(XSDataBoolean(True)) xsd.setLevelsGamma(XSDataFloat(gamma)) xml = xsd.marshal() return xml
def process(self, _edObject=None): """ """ for i in range(2): execPlugin = self.loadPlugin(self.__strControlledPluginThumbnail) xsdin = XSDataInputExecThumbnail() xsdin.setInputArray(self.xsdImages[i]) xsdFile = XSDataFile() xsdFile.setPath(XSDataString(os.path.join(self.getWorkingDirectory(), "image%i.jpg" % self.xsdIdx[i].getValue()))) xsdin.setOutputPath(xsdFile) xsdin.setLevelsColorize(XSDataBoolean(1)) xsdin.setLevelsEqualize(XSDataBoolean(1)) execPlugin.setDataInput(xsdin) execPlugin.connectSUCCESS(self.doSuccessThumb) execPlugin.connectFAILURE(self.doFailureThumb) self.ACThumbnail.addAction(execPlugin) self.ACThumbnail.execute() while len(self.xsdThumb) < 2: time.sleep(1) for oneImage in self.xsdThumb: execPlugin = self.loadPlugin(self.__strControlledPluginSift) xsdin = XSDataInputSiftDescriptor() xsdin.setImage(oneImage) execPlugin.setDataInput(xsdin) execPlugin.connectSUCCESS(self.doSuccessSift) execPlugin.connectFAILURE(self.doFailureSift) self.ACSift.addAction(execPlugin) self.ACSift.execute() # # else: # strError = "There are only %s images in self.xsdThumb" % len(self.xsdThumb) # EDVerbose.ERROR(strError) # self.setFailure() # raise RuntimeError(strError) ################################################################################ # This should be executed only after the Sift actions cluster finishes ################################################################################ while len(self.xsdKeys) < 2: time.sleep(1) execPlugin = self.loadPlugin(self.__strControlledPluginAutopano) xsdin = XSDataInputMeasureOffsetSift() xsdin.setDescriptorFile(self.xsdKeys) execPlugin.setDataInput(xsdin) execPlugin.connectSUCCESS(self.doSuccessAutopano) execPlugin.connectFAILURE(self.doFailureAutopano) execPlugin.executeSynchronous()
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) EDVerbose.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess") # Check that the input image exists and is of the expected type strPathToDiffractionImage = self.getDataInput().getDiffractionImage().getPath().getValue() strImageFileNameExtension = os.path.splitext(strPathToDiffractionImage)[1] if not strImageFileNameExtension in [".img", ".marccd", ".mccd", ".cbf"]: print strImageFileNameExtension EDVerbose.error("Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage) self.setFailure() else: # Load the waitFile plugin xsDataInputWaitFile = XSDataInputWaitFile() xsDataInputWaitFile.setExpectedSize(XSDataInteger(self.__iExpectedSize)) xsDataInputWaitFile.setExpectedFile(self.getDataInput().getDiffractionImage()) if self.getDataInput().getWaitForFileTimeOut(): xsDataInputWaitFile.setTimeOut(self.getDataInput().getWaitForFileTimeOut()) self.__edPluginWaitFile = EDPluginWaitFile() self.__edPluginWaitFile.setDataInput(xsDataInputWaitFile) # Load the execution plugin self.__edPluginExecThumbnail = self.loadPlugin(self.__strExecThumbnailPluginName) xsDataInputExecThumbnail = XSDataInputExecThumbnail() xsDataInputExecThumbnail.setInputImagePath(self.getDataInput().getDiffractionImage()) xsDataInputExecThumbnail.setLevelsInvert(XSDataBoolean(True)) xsDataInputExecThumbnail.setLevelsMin(XSDataDoubleWithUnit(0.0)) xsDataDoubleWithUnitLevelsMax = XSDataDoubleWithUnit(99.95) xsDataDoubleWithUnitLevelsMax.setUnit(XSDataString("%")) xsDataInputExecThumbnail.setLevelsMax(xsDataDoubleWithUnitLevelsMax) xsDataInputExecThumbnail.setFilterDilatation([XSDataInteger(4)]) xsDataInputExecThumbnail.setLevelsColorize(XSDataBoolean(False)) xsDataInputExecThumbnail.setThumbHeight(XSDataInteger(1024)) xsDataInputExecThumbnail.setThumbWidth(XSDataInteger(1024)) xsDataInputExecThumbnail.setKeepRatio(XSDataBoolean(False)) # Output path strImageNameWithoutExt = os.path.basename(os.path.splitext(strPathToDiffractionImage)[0]) strImageDirname = os.path.dirname(strPathToDiffractionImage) if self.getDataInput().getForcedOutputDirectory(): strForcedOutputDirectory = self.getDataInput().getForcedOutputDirectory().getPath().getValue() if not os.access(strForcedOutputDirectory, os.W_OK): EDVerbose.error("Cannot write to forced output directory : %s" % strForcedOutputDirectory) self.setFailure() else: self.strOutputPathWithoutExtension = os.path.join(strForcedOutputDirectory, strImageNameWithoutExt) else: # Try to store in the ESRF pyarch directory strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath(strImageDirname) # Check that output pyarch path exists and is writeable: bIsOk = False if strOutputDirname: if not os.path.exists(strOutputDirname): # Try to create the directory try: os.makedirs(strOutputDirname) bIsOk = True except BaseException, e: EDVerbose.WARNING("Couldn't create the directory %s" % strOutputDirname) elif os.access(strOutputDirname, os.W_OK): bIsOk = True if not bIsOk: EDVerbose.warning("Cannot write to pyarch directory: %s" % strOutputDirname) strOutputDirname = tempfile.mkdtemp("", "EDPluginPyarchThumbnailv10_", "/tmp") EDVerbose.warning("Writing thumbnail images to: %s" % strOutputDirname) self.strOutputPathWithoutExtension = os.path.join(strOutputDirname, strImageNameWithoutExt) self.strOutputPath = os.path.join(self.strOutputPathWithoutExtension + ".jpeg") xsDataInputExecThumbnail.setOutputPath(XSDataFile(XSDataString(self.strOutputPath))) self.__edPluginExecThumbnail.setDataInput(xsDataInputExecThumbnail)