/// <summary> /// Creates an Map, showing where People died in this Tick. /// </summary> /// <param name="snapshot"></param> /// <param name="palette"></param> /// <returns>savepath</returns> public unsafe string GetDeathMap(TickSnapshot snapshot, EStatField field, EColorPalette palette, string namePrefix) { Color[] pal = GetPalette(palette); Bitmap map = new Bitmap(X, Y); BitmapData bData = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.ReadWrite, map.PixelFormat); PixelData* start = (PixelData*)bData.Scan0.ToPointer(); PixelData* pixelptr = null; foreach (CellSnapshot cell in snapshot.Cells) { Point p = cell.Position.DeFlatten(X); pixelptr = start + p.X + (p.Y * map.Width); pixelptr->Alpha = 255; pixelptr->Blue = 0; pixelptr->Green = 0; pixelptr->Red = 0; } foreach (HumanSnapshot snap in (HumanSnapshotCreteriaMatcher.GetMatchingHumans(snapshot.Deaths, field))) { Point p = ExtensionMethods.DeFlatten(snap.DeathCell, X); pixelptr = start + p.X + (p.Y * map.Width); pixelptr->Alpha = pal[0].A; pixelptr->Blue = pal[0].B; pixelptr->Green = pal[0].G; pixelptr->Red = pal[0].R; } map.UnlockBits(bData); string path = Target + "/" + namePrefix + "_" + snapshot.Tick + "_D-" + (int)field + ".png"; map.Save(path, System.Drawing.Imaging.ImageFormat.Png); GenerateCaption(_steps, pal); return path; }
/// <summary> /// Creates a Graphic of the dead Humans /// </summary> /// <param name="field">The desired Field</param> /// <param name="colors">The desired ColorPalette</param> /// <param name="namePrefix">The desired Prefix</param> public string CreateDeathGraphics(EStatField field, EColorPalette colors, string namePrefix) { if (_currentArchive != null) { if (LoadedSnapshot != null) { return _creator.GetDeathMap(LoadedSnapshot, field, colors, namePrefix); } else { throw new ApplicationException("No Snapshot is opened!"); } } else { throw new ApplicationException("No File loaded"); } }
private void GenerateGraphics(string prefix, string destination, EColorPalette colorPalette, bool[] diagrams, EStatField fields, string[] entries) { // parallel run IncreaseProgressBar(); _statsManager.SnapshotAnalized += (_, __) => IncreaseProgressBar(); _statsManager.AnalyzingFinished += (_, __) => IncreaseProgressBar(); _statsManager.ReviewManager.GraphicDone += (_, __) => IncreaseProgressBar(); if (diagrams.Contains(true)) _statsManager.AnalyzeSimulation(); _statsManager.ReviewManager.SetNewDestination(destination); if (fields.HasFlag((EStatField)0x400)) _snapshotSavePaths = _statsManager.ReviewManager.CreateMultipleDeathGraphics( new List<string>(entries), (EStatField)((int)fields & ~0x400), colorPalette, prefix); else _snapshotSavePaths = _statsManager.ReviewManager.CreateMultipleGraphics( new List<string>(entries), fields, colorPalette, prefix); FinishProgressBar(); OutputTargetManager.GetInstance().WriteMessage("Done"); _secondContainer.OutputPanel.TheButton.Invoke(new Action(() => _secondContainer.OutputPanel.TheButton.Enabled = true)); }
/// <summary> /// Returns a List of Humans matching the given fields /// </summary> /// <param name="humans">The Original Array of Humans</param> /// <param name="field">The field to be matched</param> /// <returns>A (propably) smaller List of Humans</returns> public static List<HumanSnapshot> GetMatchingHumans(HumanSnapshot[] humans, EStatField field) { List<EStatField> fields = new List<EStatField>(); foreach (EStatField e in Enum.GetValues(typeof(EStatField))) { if ((e & field) == e) fields.Add(e); } List<HumanSnapshot> deceasedHumans = new List<HumanSnapshot>(); bool useCause = (fields.Contains(EStatField.Infected) != fields.Contains(EStatField.Diseased)); foreach (HumanSnapshot human in humans) { EAge age = WrapAge(human.Age); EGender gender = (EGender)human.Gender; bool fits = true; if (useCause) fits = fields.Contains(EStatField.Infected) ? !human.Cause : human.Cause; if (fits) { if (fields.Contains(EStatField.Infected) && !human.Cause) deceasedHumans.Add(human); else if (fields.Contains(EStatField.Diseased) && human.Cause) deceasedHumans.Add(human); //else // this is a much more elegant and shorter way, BUT I'm not sure, whether it works or not... //{ // for (int i = 0; i < 8; ++i) // { // if (fields.Contains((EStatField)(int)Math.Pow(2, i)) & age == (EAge)((i % 4)* 32)) // deceasedHumans.Add(human); // } //} else if (gender == EGender.Male) { if (fields.Contains(EStatField.MaleBaby) & age == EAge.Baby) deceasedHumans.Add(human); else if (fields.Contains(EStatField.MaleChild) & age == EAge.Child) deceasedHumans.Add(human); else if (fields.Contains(EStatField.MaleAdult) & age == EAge.Adult) deceasedHumans.Add(human); else if (fields.Contains(EStatField.MaleSenior) & age == EAge.Senior) deceasedHumans.Add(human); } else { if (fields.Contains(EStatField.FemaleBaby) & age == EAge.Baby) deceasedHumans.Add(human); else if (fields.Contains(EStatField.FemaleChild) & age == EAge.Child) deceasedHumans.Add(human); else if (fields.Contains(EStatField.FemaleAdult) & age == EAge.Adult) deceasedHumans.Add(human); else if (fields.Contains(EStatField.FemaleSenior) & age == EAge.Senior) deceasedHumans.Add(human); } } } return deceasedHumans; }
/// <summary> /// Creates a map with the given parameters /// </summary> /// <param name="snapshot">The Snapshot to be mapped</param> /// <param name="field">The Field to be visualised</param> /// <param name="palette">The Color Palette to be used</param> /// <returns>savepath</returns> public unsafe string GetMap(TickSnapshot snapshot, EStatField field, EColorPalette palette, string namePrefix) { Color[] pal = GetPalette(palette); Bitmap map = new Bitmap(X, Y); BitmapData bData = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.ReadWrite, map.PixelFormat); PixelData* start = (PixelData*)bData.Scan0.ToPointer(); PixelData* pixelptr = null; List<int> fields = new List<int>(); foreach (EStatField f in Enum.GetValues(typeof(EStatField))) { if ((f & field) == f) fields.Add((int)Math.Log((double)f, 2d)); } foreach (CellSnapshot cell in snapshot.Cells) { int count = 0; foreach (int i in fields) count += cell.Values[i]; Point p = cell.Position.DeFlatten(X); pixelptr = start + p.X + (p.Y * map.Width); if (count == 0) { pixelptr->Alpha = 255; pixelptr->Blue = 0; pixelptr->Green = 0; pixelptr->Red = 0; } else { for (int i = ColorPalette.RANGE - 1; i >= 0; --i) { if (_steps[i] >= count) { pixelptr->Alpha = pal[i].A; pixelptr->Blue = pal[i].B; pixelptr->Green = pal[i].G; pixelptr->Red = pal[i].R; break; } } } } map.UnlockBits(bData); string path = Target + "/" + namePrefix + "_" + snapshot.Tick + "_S-" + (int)field + ".png"; map.Save(path, ImageFormat.Png); GenerateCaption(_steps, pal); return path; }
/// <summary> /// Creates Graphics with the same Parameters for multiple Snapshots /// </summary> /// <param name="entries">The List of Snapshots</param> /// <param name="field">The desired Field</param> /// <param name="colors">The desired ColorPalette</param> /// <param name="namePrefix">The desired Prefix</param> public string[] CreateMultipleGraphics(List<string> entries, EStatField field, EColorPalette colors, string namePrefix) { int i = 1; int size = entries.Count; int sizeLength = size.ToString().Length; string[] paths = new string[size]; foreach (string entry in entries) { if(Entries.Contains(entry)) { WriteMessage("Loading " + entry + "..."); LoadTickSnapshot(entry); paths[i-1] = CreateGraphics(field, colors, namePrefix); WriteMessage(String.Format("{0," + sizeLength + "} of {1} graphics finished.", i, size)); } else { WriteMessage(entry + " could not be created"); } ++i; GraphicDone.Raise(this, null); } return paths; }