public static GAShape ReadBinary(GARepresentation owner, BinaryReader br) { GAShapeType type = (GAShapeType)br.ReadByte(); switch (type) { case GAShapeType.Circle: return(new GAShapeCircle(owner, br)); case GAShapeType.Line: return(new GAShapeLine(owner, br)); case GAShapeType.Curve: return(new GAShapeCurve(owner, br)); case GAShapeType.FilledPolygon: return(new GAShapeFilledPolygon(owner, br)); case GAShapeType.FilledPolycurve: return(new GAShapeFilledPolycurve(owner, br)); case GAShapeType.Path: return(new GAShapePath(owner, br)); default: return(null); } }
public GARepresentation Duplicate() { GARepresentation newrep = new GARepresentation(MaxX, MaxY); foreach (GAShape gp in Shapes) { GAShape newgap = gp.Duplicate(newrep); newrep.Shapes.Add(newgap); } newrep.BackgroundColour = BackgroundColour; newrep.OpChangeColour = OpChangeColour; newrep.OpLinesCurves = OpLinesCurves; newrep.OpPointAdded = OpPointAdded; newrep.OpPointMoved = OpPointMoved; newrep.OpPointRemove = OpPointRemove; newrep.OpSwapPoints = OpSwapPoints; newrep.OpShapeAdd = OpShapeAdd; newrep.OpShapeRemove = OpShapeRemove; newrep.OpShapeSplit = OpShapeSplit; newrep.OpShapeMerged = OpShapeMerged; newrep.OpShapeSwap = OpShapeSwap; newrep.Generation = Generation; newrep.Iterations = Iterations; newrep.UpdateTotalPoints(); return(newrep); }
private void DisplayRepresentation(GARepresentation rep) { FastBitmap fb = new FastBitmap(CurrentProject.SourceImage.Width, CurrentProject.SourceImage.Height, PixelFormat.Format24bppRgb); CurrentProject.BestYet.DrawToFastBitmap(fb); DisplayImageBitmap(fb); }
private bool ProcessIteration() { if (Best.Generation == 0) { Best = new GARepresentation(WorkingImg.GetBitmap().Width, WorkingImg.GetBitmap().Height); SeedRepresentation(Best); } GARepresentation nextgen = Best.Duplicate(); nextgen.Mutate(Entropy, Properties); nextgen.DrawToFastBitmap(WorkingImg); double nextcomp = FastBitmap.UltraCompare(Img, WorkingImg); if ((nextcomp < BestComparison) || ((nextcomp == BestComparison) && (nextgen.Shapes.Count < Best.Shapes.Count))) { Best = nextgen; BestComparison = nextcomp; Best.Generation++; return(true); } return(false); }
public void Load() { FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read); try { BinaryReader br = new BinaryReader(fs); string header = br.ReadString(); if (header == "GAVECTORPROJECT") { byte major = br.ReadByte(); byte minor = br.ReadByte(); if ((major < VERSIONMAJOR) || ((major == VERSIONMAJOR) && (minor <= VERSIONMINOR))) { GZipStream gz = new GZipStream(fs, CompressionMode.Decompress); br = new BinaryReader(gz); //Load The Image to a MemoryStream float resx = br.ReadSingle(); float resy = br.ReadSingle(); int bmlength = br.ReadInt32(); byte[] buffer = br.ReadBytes(bmlength); MemoryStream ms = new MemoryStream(buffer); Bitmap bt = new Bitmap(ms); bt.SetResolution(resx, resy); ms.Close(); buffer = null; // Draw the Bitmap onto a 24bpp canvas SourceImage = new FastBitmap(bt.Width, bt.Height, PixelFormat.Format24bppRgb); Graphics gp = Graphics.FromImage(SourceImage.GetBitmap()); gp.DrawImage(bt, PointF.Empty); gp.Dispose(); Properties = new GAProjectProperties(br); BestYet = new GARepresentation(br); BestComparison = br.ReadDouble(); } else { throw new Exception("Version incorrect, this version " + VERSIONMAJOR.ToString() + "." + VERSIONMINOR.ToString() + ", file version " + major.ToString() + "." + minor.ToString()); } } else { throw new Exception("Not a GAVector Project File"); } } catch (IOException) { throw new Exception("File is Corrupt"); } finally { fs.Close(); } }
public override GAShape Duplicate(GARepresentation newowner) { GAShapeCircle p = new GAShapeCircle(newowner); p.PolyPoints[0] = new PointF(PolyPoints[0].X, PolyPoints[0].Y); p.ShapeColour = ShapeColour; p.Size = Size; return(p); }
private void LoadInit(MsgCommand mc) { Best = mc.Best; BestComparison = mc.BestComparison; Properties = mc.Properties; Img = mc.Img; WorkingImg = new FastBitmap(Img.Width, Img.Height, PixelFormat.Format24bppRgb); Entropy = mc.Entropy; }
public override GAShape Duplicate(GARepresentation newowner) { GAShapeFilledPolycurve newgap = new GAShapeFilledPolycurve(newowner); newgap.ShapeColour = this.ShapeColour; foreach (PointF p in PolyPoints) { newgap.PolyPoints.Add(new PointF(p.X, p.Y)); } return(newgap); }
public GAShape Duplicate(GARepresentation newowner) { GAShape newgap = new GAShape(newowner); newgap.PolyColor = this.PolyColor; newgap.Type = this.Type; foreach (Point p in PolyPoints) { newgap.PolyPoints.Add(new Point(p.X, p.Y)); } return(newgap); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { Properties = null; BestYet = null; SourceImage.Dispose(); } _disposed = true; } }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { Properties = null; Best = null; Img.Dispose(); WorkingImg.Dispose(); Entropy = null; } _disposed = true; } }
private void SeedRepresentation(GARepresentation rep) { if (Properties.BackgroundColorFromHistogram) { rep.ComputeBackground(Img); } switch (Properties.Seeding) { case GASeeding.RandomSeed: rep.GenericSeed(Entropy, Properties); break; case GASeeding.MatrixSeed: rep.MatrixSeed(Img.GetBitmap(), Properties); break; } }
public GAShapeCurve(GARepresentation owner) { Owner = owner; }
public abstract GAShape Duplicate(GARepresentation newowner);
private void LoadBestYet(MsgCommand mc) { Best = mc.Best; BestComparison = mc.BestComparison; }
public GAShapeLine(GARepresentation owner) { Owner = owner; }
public GAShapeFilledPolycurve(GARepresentation owner, BinaryReader br) { Owner = owner; ReadBinary(br); }
public GAShapeLine(GARepresentation owner, BinaryReader br) { Owner = owner; ReadBinary(br); }
public override GAShape Duplicate(GARepresentation newowner) { return(null); }
public GAShapeFilledPolycurve(GARepresentation owner) { Owner = owner; }
public GAShapeCircle(GARepresentation owner) { Owner = owner; PolyPoints.Add(PointF.Empty); }
public static GAShape CreateRandom(ThreadSafeRandom rd, GAProjectProperties prop, GARepresentation owner) { List <GAShapeType> lt = new List <GAShapeType>(); if (prop.UsePoints) { lt.Add(GAShapeType.Circle); } if (prop.UseLines) { lt.Add(GAShapeType.Line); } if (prop.UseCurves) { lt.Add(GAShapeType.Curve); } if (prop.UseFilledPolygons) { lt.Add(GAShapeType.FilledPolygon); } if (prop.UseFilledPolycurves) { lt.Add(GAShapeType.FilledPolycurve); } //if (prop.UsePaths) lt.Add(GAShapeType.Path); if (lt.Count == 0) { throw new Exception("GASHape.CreateRandom - No Shapes Allowed"); } GAShape output = null; switch (lt[rd.Next(lt.Count)]) { case GAShapeType.Circle: output = new GAShapeCircle(owner); break; case GAShapeType.Line: output = new GAShapeLine(owner); break; case GAShapeType.Curve: output = new GAShapeCurve(owner); break; case GAShapeType.FilledPolygon: output = new GAShapeFilledPolygon(owner); break; case GAShapeType.FilledPolycurve: output = new GAShapeFilledPolycurve(owner); break; case GAShapeType.Path: output = new GAShapePath(owner); break; } output.Randomize(rd, prop); return(output); }
public GAShapePath(GARepresentation owner) { Owner = owner; }