Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }
Example #3
0
        private void DisplayRepresentation(GARepresentation rep)
        {
            FastBitmap fb = new FastBitmap(CurrentProject.SourceImage.Width, CurrentProject.SourceImage.Height, PixelFormat.Format24bppRgb);

            CurrentProject.BestYet.DrawToFastBitmap(fb);
            DisplayImageBitmap(fb);
        }
Example #4
0
        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);
        }
Example #5
0
        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();
            }
        }
Example #6
0
        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);
        }
Example #7
0
 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;
 }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             Properties = null;
             BestYet    = null;
             SourceImage.Dispose();
         }
         _disposed = true;
     }
 }
Example #11
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             Properties = null;
             Best       = null;
             Img.Dispose();
             WorkingImg.Dispose();
             Entropy = null;
         }
         _disposed = true;
     }
 }
Example #12
0
        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;
            }
        }
Example #13
0
 public GAShapeCurve(GARepresentation owner)
 {
     Owner = owner;
 }
Example #14
0
 public abstract GAShape Duplicate(GARepresentation newowner);
Example #15
0
 private void LoadBestYet(MsgCommand mc)
 {
     Best           = mc.Best;
     BestComparison = mc.BestComparison;
 }
Example #16
0
 public GAShapeLine(GARepresentation owner)
 {
     Owner = owner;
 }
Example #17
0
 public GAShapeFilledPolycurve(GARepresentation owner, BinaryReader br)
 {
     Owner = owner;
     ReadBinary(br);
 }
Example #18
0
 public GAShapeLine(GARepresentation owner, BinaryReader br)
 {
     Owner = owner;
     ReadBinary(br);
 }
Example #19
0
 public override GAShape Duplicate(GARepresentation newowner)
 {
     return(null);
 }
Example #20
0
 public GAShapeFilledPolycurve(GARepresentation owner)
 {
     Owner = owner;
 }
Example #21
0
 public GAShapeCircle(GARepresentation owner)
 {
     Owner = owner;
     PolyPoints.Add(PointF.Empty);
 }
Example #22
0
        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);
        }
Example #23
0
 public GAShapePath(GARepresentation owner)
 {
     Owner = owner;
 }