def saveImage(menuitem, image, filename, format, mode): immidge = oofimage.getImage(image) if immidge and (mode == "w" or not os.path.exists(filename)): if config.dimension() == 3: # A separate file will be stored for each slice. The # filename must contain '%i', which will be replaced by an # integer to differentiate the slices. If the given name # doesn't contain '%i', '_%i' will be appended to it. If # the given name looks like "name.suffix", the new name # will be "name_%i.suffix". path, fname = os.path.split(filename) if "%i" not in fname: if not os.path.exists(path): os.makedirs(path) fn = fname.rsplit(".", 1) if len(fn) > 1: fname = fn[0] + "_%i." + fn[1] # filename = path + "/" + fn[0] + "_%i." + fn[1] else: fname = fn[0] + "_i" # filename = path + "/" + filename + "_%i" filename = os.path.join(path, fname) immidge.save(filename, format.string()) else: reporter.warn("Image was not saved!")
def Create_From_ImageFile(self): from ooflib.SWIG.image import oofimage from ooflib.common import primitives from ooflib.SWIG.common.IO import stringimage self.assertRaises( oofimage.ImageMagickError, OOF.Microstructure.Create_From_ImageFile, filename="nosuchfile", microstructure_name="nosuchfile", height=automatic, width=automatic) self.assertRaises( ooferror.ErrUserError, OOF.Microstructure.Create_From_ImageFile, filename=reference_file("ms_data","small.ppm"), microstructure_name="oops", height=-1.0, width=-1.0) OOF.Microstructure.Create_From_ImageFile( filename=reference_file("ms_data","small.ppm"), microstructure_name="small.ms", height=20.0, width=20.0) ms = getMicrostructure("small.ms") self.assertEqual(ms.size(), primitives.Point(20.0, 20.0)) self.assertEqual(ms.sizeInPixels(), primitives.iPoint(150,150)) self.assertEqual(ms.sizeOfPixels(), (20.0/150, 20.0/150)) ms_images = ms.imageNames() self.assertEqual(len(ms_images), 1) self.assert_("small.ppm" in ms_images) img = oofimage.getImage("small.ms:small.ppm") strimg = stringimage.StringImage(ms.sizeInPixels(), ms.size()) img.fillstringimage(strimg) outfile = file('hexstringimage.dat','w') print >> outfile, strimg.hexstringimage() outfile.close() assert filecmp.cmp('hexstringimage.dat', reference_file('ms_data','smallppm.hex')) os.remove("hexstringimage.dat")
def createImage(msname, imagename, origin=0): if _rank == origin: image = oofimage.getImage([msname, imagename]) destinations = range(1,_size) oofimage.Send_Image(image, destinations) else: image = oofimage.Recv_Image(origin) return image
def Create_From_ImageFile(self): from ooflib.SWIG.image import oofimage from ooflib.common import primitives from ooflib.SWIG.common.IO import stringimage self.assertRaises(oofimage.ImageMagickError, OOF.Microstructure.Create_From_ImageFile, filename="nosuchfile", microstructure_name="nosuchfile", height=automatic, width=automatic) self.assertRaises(ooferror.ErrUserError, OOF.Microstructure.Create_From_ImageFile, filename=reference_file("ms_data", "small.ppm"), microstructure_name="oops", height=-1.0, width=-1.0) OOF.Microstructure.Create_From_ImageFile( filename=reference_file("ms_data", "small.ppm"), microstructure_name="small.ms", height=20.0, width=20.0) ms = getMicrostructure("small.ms") self.assertEqual(ms.size(), primitives.Point(20.0, 20.0)) self.assertEqual(ms.sizeInPixels(), primitives.iPoint(150, 150)) self.assertEqual(ms.sizeOfPixels(), (20.0 / 150, 20.0 / 150)) ms_images = ms.imageNames() self.assertEqual(len(ms_images), 1) self.assert_("small.ppm" in ms_images) img = oofimage.getImage("small.ms:small.ppm") strimg = stringimage.StringImage(ms.sizeInPixels(), ms.size()) img.fillstringimage(strimg) outfile = file('hexstringimage.dat', 'w') print >> outfile, strimg.hexstringimage() outfile.close() assert filecmp.cmp('hexstringimage.dat', reference_file('ms_data', 'smallppm.hex')) os.remove("hexstringimage.dat")
def copyImage(menuitem, image, microstructure, name): sourceimage = oofimage.getImage(image) immidge = sourceimage.clone(name) loadImageIntoMS(immidge, microstructure)
def saveImage(menuitem, image, filename, overwrite): immidge = oofimage.getImage(image) if immidge and (overwrite or not os.path.exists(filename)): immidge.save(filename) else: reporter.warn("Image was not saved!")