public static IEnumerable <string> GreedyEpitomeEnumerable(string patchTableAsString) { //!!!Similar to other code string scorerName = "normal"; PatchPatternFactory patchPatternFactory = PatchPatternFactory.GetFactory("strings"); VaccineMaker vaccineMaker = VaccineMaker.GetInstance("Greedy"); PatchTable patchTable = LoadPatchTable(patchTableAsString, scorerName, patchPatternFactory); patchTable.Normalize(); AssertPointsTotalOne(patchTable); //yield return VaccineMaker.DisplayHeaderString; vaccineMaker.FirstVaccine(patchTable); VaccineAsString vaccineAsString = null; while (null != (vaccineAsString = vaccineMaker.VaccineAsString)) { double rScoreOpt = patchTable.Score(vaccineAsString); yield return(vaccineMaker.DisplayString(rScoreOpt)); vaccineMaker.ChangeToNext(); } }
public static void MakeGreedyEpitomes(TextReader patchTableTextReader, TextWriter streamWriterOutputFile, int stopLength) { string scorerName = "normal"; PatchPatternFactory patchPatternFactory = PatchPatternFactory.GetFactory("strings"); VaccineMaker vaccineMaker = VaccineMaker.GetInstance("Greedy"); PatchTable patchTable = LoadPatchTable(patchTableTextReader, scorerName, patchPatternFactory); patchTable.Normalize(); AssertPointsTotalOne(patchTable); vaccineMaker.DisplayHeader(streamWriterOutputFile); vaccineMaker.FirstVaccine(patchTable); VaccineAsString vaccineAsString = null; while (null != (vaccineAsString = vaccineMaker.VaccineAsString)) { double rScoreOpt = patchTable.Score(vaccineAsString); vaccineMaker.Display(streamWriterOutputFile, rScoreOpt); streamWriterOutputFile.Flush(); if (vaccineAsString.TotalNumberOfAminoAcids > stopLength) { break; } vaccineMaker.ChangeToNext(); } }
private static PatchTable LoadPatchTable(string patchTableAsString, string scorerName, PatchPatternFactory patchPatternFactory) { using (TextReader textReader = new StringReader(patchTableAsString)) { PatchTable patchTable = PatchTable.GetInstanceFromFile(patchPatternFactory, textReader, scorerName); return(patchTable); } }
static public void AssertPointsTotalOne(PatchTable patchTable) { double rTotal = 0.0; foreach (Patch patch in patchTable.SortedPatchCollection) { rTotal += patch.Weight; } Debug.Assert(Math.Abs(rTotal - 1.0) < 1e-10); }
static public PatchTable LoadPatchTable(TextReader patchTableTextReader, string scorerName, PatchPatternFactory patchPatternFactory) { PatchTable patchTable = PatchTable.GetInstanceFromFile(patchPatternFactory, patchTableTextReader, scorerName); return(patchTable); }
public static Texture2D BuildTexture(string name, WadFile wad, TextureTable textures) { if (textureCache == null) { textureCache = new Dictionary <string, Texture2D>(); } if (textureCache.ContainsKey(name)) { return(textureCache[name]); } PatchTable pnames = new PatchTable(wad.GetLump("PNAMES")); DoomTexture texture = textures.Get(name.ToUpper()); Texture2D output = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false, true); for (int i = 0; i < texture.patches.Count; i++) { DoomPatch p = texture.patches[i]; Texture2D patch2d = DoomGraphic.BuildPatch(p.patchIndex, pnames, wad); if (patch2d == null) { return(null); } int copyX = (p.originX < 0)?-p.originX:0; int copyY = (p.originY < 0)?-p.originY:0; int pasteX = (p.originX > 0)?p.originX:0; int pasteY = (p.originY > 0)?p.originY:0; int copyWidth = patch2d.width - copyX; if (copyWidth > output.width - pasteX) { copyWidth = output.width - pasteX; } int copyHeight = patch2d.height - copyY; if (copyHeight > output.height - pasteY) { copyHeight = output.height - pasteY; } for (int a = 0; a < copyWidth; a++) { for (int b = 0; b < copyHeight; b++) { Color col = patch2d.GetPixel(copyX + a, copyY + b); if (col.a != 0f) { output.SetPixel(pasteX + a, pasteY + b, col); } } } } output.Apply(); output.wrapMode = TextureWrapMode.Repeat; output.filterMode = FilterMode.Point; textureCache.Add(name, output); return(output); }
public static Texture2D BuildPatch(int index, WadFile wad) { PatchTable pnames = new PatchTable(wad.GetLump("PNAMES")); return(BuildPatch(pnames.patches[index], wad)); }
public static Texture2D BuildPatch(int index, PatchTable pnames, WadFile wad) { return(BuildPatch(pnames.patches[index], wad)); }