Esempio n. 1
0
        internal void Init(DnaDrawing drawing, JobInfo info)
        {
            Points = new List<DnaPoint>();

            //int count = info.GetRandomNumber(3, 3);
            var origin = new DnaPoint();
            origin.Init(drawing, info);

            if (drawing.Polygons.Count < 1)
            {
                origin.X = info.SourceImage.Width / 2;
                origin.Y = info.SourceImage.Height / 2;
            }

            for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++)
            {
                var point = new DnaPoint
                                {
                                    X =
                                        Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Width),
                                    Y =
                                        Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Height)
                                };

                Points.Add(point);
            }

            Brush = new DnaBrush();
            Brush.Init(info);
        }
Esempio n. 2
0
        public void Mutate(JobInfo info)
        {
            IsDirty = false;
            while (!IsDirty)
            {
                if (!info.Settings.MuteAddPolygonNew)
                    if (info.WillMutate(info.Settings.AddPolygonMutationRate))
                        AddPolygon(info);

                if (!info.Settings.MuteAddPolygonClone)
                    if (info.WillMutate(info.Settings.AddPolygonCloneMutationRate))
                        AddPolygonClone(info);

                if (!info.Settings.MuteRemovePolygon)
                    if (info.WillMutate(info.Settings.RemovePolygonMutationRate))
                        RemovePolygon(info);

                if (!info.Settings.MuteMovePolygon)
                    if (info.WillMutate(info.Settings.MovePolygonMutationRate))
                        MovePolygon(info);

                foreach (DnaPolygon polygon in Polygons)
                    polygon.Mutate(this, info);
            }
        }
Esempio n. 3
0
 internal void Init(JobInfo info)
 {
     Red = info.GetRandomNumber(0, 255);
     Green = info.GetRandomNumber(0, 255);
     Blue = info.GetRandomNumber(0, 255);
     Alpha = info.GetRandomNumber(10, 60);
 }
Esempio n. 4
0
        internal void Mutate(JobInfo info)
        {
            IsDirty = false;
            while (!IsDirty)
            {
                if (!info.Settings.MuteAddPolygonNew)
                    if (info.WillMutate(info.Settings.AddPolygonMutationRate))
                        AddPolygon(info);

                if (!info.Settings.MuteAddPolygonClone)
                    if (info.WillMutate(info.Settings.AddPolygonCloneMutationRate))
                        AddPolygonClone(info);

                if (!info.Settings.MuteRemovePolygon)
                    if (info.WillMutate(info.Settings.RemovePolygonMutationRate))
                        RemovePolygon(info);

                if (!info.Settings.MuteMovePolygon)
                    if (info.WillMutate(info.Settings.MovePolygonMutationRate))
                        MovePolygon(info);

                unchecked
                {
                    for (int i = 0; i < Polygons.Count; i++)
                    {
                        DnaPolygon polygon = Polygons[i];
                        polygon.Mutate(this, info);
                    }
                }
            }
        }
Esempio n. 5
0
        internal void Mutate(DnaDrawing drawing, JobInfo info)
        {
            if (info.WillMutate(info.Settings.ColorMutationRate))
            {
                Red = info.GetRandomNumber(0, 255);

                drawing.SetDirty();
            }

            if (info.WillMutate(info.Settings.ColorMutationRate))
            {
                Green = info.GetRandomNumber(0, 255);

                drawing.SetDirty();
            }
            if (info.WillMutate(info.Settings.ColorMutationRate))
            {
                Blue = info.GetRandomNumber(0, 255);

                drawing.SetDirty();
            }

            if (info.WillMutate(info.Settings.ColorMutationRate))
            {
                Alpha = info.GetRandomNumber(info.Settings.AlphaRangeMin, info.Settings.AlphaRangeMax);

                drawing.SetDirty();
            }
        }
Esempio n. 6
0
        public void Init(JobInfo info)
        {
            Polygons = new List<DnaPolygon>();

            for (int i = 0; i < info.Settings.PolygonsMin; i++)
                AddPolygon(info);

            SetDirty();
        }
Esempio n. 7
0
 internal WorkerInstance(int randomSeed, JobInfo info)
 {
     this.randomSeed = randomSeed;
     this.info = info;
     info.InitRandom(randomSeed);
     parentDrawing = new DnaDrawing
                         {
                             Polygons = new List<DnaPolygon>(),
                         };
 }
Esempio n. 8
0
        private void StartEvolution()
        {
            var sourceImage = new SourceImage
                                  {
                                      Pixels = SetupSourceColorMatrix(picPattern.Image as Bitmap),
                                      Width = picPattern.Width,
                                      Height = picPattern.Height
                                  };

            var info = new JobInfo
                           {
                               Settings = Project.Settings,
                               SourceImage = sourceImage,
                           };
            //IEvolutionJob job = new LayeredEvolutionJob(sourceImage, 4);

            //DefaultEvolutionJob job = new DefaultEvolutionJob(sourceImage, currentDrawing);
            //IEvolutionJob job = new DefaultEvolutionJob(info);
            IEvolutionJob job = new ClusteredEvolutionJob(info);

            while (Project.IsRunning)
            {
                double newErrorLevel = job.GetNextErrorLevel();
                var defJob = job as DefaultEvolutionJob;
                if (defJob != null)
                    Project.Generations += defJob.Generations;

                Project.Mutations++;

                if (newErrorLevel <= Project.ErrorLevel)
                {
                    Project.Selected++;

                    if (newErrorLevel < Project.ErrorLevel)
                        Project.Positive++;
                    else
                        Project.Neutral++;

                    DnaDrawing newDrawing = job.GetDrawing();
                    if (currentDrawing == null) // to make always lockable...
                        currentDrawing = new DnaDrawing();

                    lock (currentDrawing)
                    {
                        currentDrawing = newDrawing;
                        Project.Drawing = currentDrawing.Clone();
                    }

                    Project.ErrorLevel = newErrorLevel;

                    SaveAnimationImage(newDrawing);
                }
            }
        }
Esempio n. 9
0
        internal void MovePolygon(JobInfo info)
        {
            if (Polygons.Count < 1)
                return;

            int index = info.GetRandomNumber(0, Polygons.Count);
            DnaPolygon poly = Polygons[index];
            Polygons.RemoveAt(index);
            index = info.GetRandomNumber(0, Polygons.Count);
            Polygons.Insert(index, poly);
            SetDirty();
        }
Esempio n. 10
0
        public DefaultEvolutionJob(DnaDrawing drawing, JobInfo info)
        {
            this.info = info;

            if (drawing == null)
                drawing = GetNewInitializedDrawing(info);
            lock (drawing)
            {
                currentDrawing = drawing.Clone();
            }

            currentErrorLevel = FitnessCalculator.GetDrawingFitness(currentDrawing, info.SourceImage);
        }
Esempio n. 11
0
        public ClusteredWorker(int randomSeed, int partitionY, int partitionHeight, JobInfo info)
        {
            data = new WorkerData
                       {
                           randomSeed = randomSeed,
                           workerTail = new Queue<DnaPartitionResult>(),
                           workerUsedTail = new List<DnaPartitionResult>(),
                       };
 
            this.partitionY = partitionY;
            this.partitionHeight = partitionHeight;
            this.info = info;

        }
Esempio n. 12
0
        internal static void Run(Intracommunicator comm)
        {
            var info = new JobInfo
                           {
                               //hack, let every node init their own job data
                               Settings = new Settings(),
                               //should be shared and sent to all workers later
                               SourceImage = GetSourceImage() //should also be sent to all workers later
                           };

            info.Settings.PolygonsMax = 50/comm.Size;
            var instance = new WorkerInstance(comm.Rank*10, info);
            instance.WorkLoop(comm);
        }
Esempio n. 13
0
        public void Init(DnaDrawing drawing, JobInfo info)
        {
            Points = new List<DnaPoint>();

            //int count = info.GetRandomNumber(3, 3);
            var origin = new DnaPoint();
            origin.Init(drawing, info);

            if (drawing.Polygons.Count < 1)
            {
                origin.X = info.SourceImage.Width / 2;
                origin.Y = info.SourceImage.Height / 2;
            }

            for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++)
            {
                var point = new DnaPoint
                                {
                                    X =
                                        Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Width),
                                    Y =
                                        Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Height)
                                };

                Points.Add(point);
            }

            bool findNew = true;

            if (info.Settings.MuteCurvePolygon &&
                info.Settings.MuteLinePolygon &&
                info.Settings.MuteCurveFillPolygon &&
                info.Settings.MuteLineFillPolygon)
                findNew = false;

            Width = info.GetRandomNumber(1, 8);

            while (findNew)
            {
                bool splines = (info.GetRandomNumber(0, 2) == 1) ? true : false;
                bool filled = (info.GetRandomNumber(0, 2) == 1) ? true : false;
                findNew = !SetSplinesAndFilled(info.Settings, splines, filled);
            }

            Brush = new DnaBrush();
            Brush.Init(info);
        }
Esempio n. 14
0
        internal void Mutate(DnaDrawing drawing, JobInfo info)
        {
            if (!info.Settings.MuteMovePointMax)
            {
                if (info.WillMutate(info.Settings.MovePointMaxMutationRate))
                {
                    X = info.GetRandomNumber(0, info.SourceImage.Width);
                    Y = info.GetRandomNumber(0, info.SourceImage.Height);
                    drawing.SetDirty();
                }
            }

            if (!info.Settings.MuteMovePointMid)
            {
                if (info.WillMutate(info.Settings.MovePointMidMutationRate))
                {

                    X = X
                        .Randomize(info ,- info.Settings.MovePointRangeMid, info.Settings.MovePointRangeMid)
                        .Max(0)
                        .Min(info.SourceImage.Width);

                    Y = Y
                        .Randomize(info, -info.Settings.MovePointRangeMid, info.Settings.MovePointRangeMid)
                        .Max(0)
                        .Min(info.SourceImage.Height);

                    drawing.SetDirty();
                }
            }

            if (!info.Settings.MuteMovePointMin)
            {
                if (info.WillMutate(info.Settings.MovePointMinMutationRate))
                {
                    X = X
                        .Randomize(info, -info.Settings.MovePointRangeMin, info.Settings.MovePointRangeMin)
                        .Max(0)
                        .Min(info.SourceImage.Width);

                    Y = Y
                        .Randomize(info, -info.Settings.MovePointRangeMin, info.Settings.MovePointRangeMin)
                        .Max(0)
                        .Min(info.SourceImage.Height);

                    drawing.SetDirty();
                }
           }
        }
Esempio n. 15
0
        public ClusteredEvolutionJob(JobInfo info)
        {
            workers = new List<ClusteredWorker>();
            const int workerCount = 2;
            int partitionHeight = info.SourceImage.Height / workerCount;
            for (int i = 0; i < workerCount; i++)
            {
                var worker = new ClusteredWorker(1, i * partitionHeight, partitionHeight, info);
                workers.Add(worker);
            }

            foreach(ClusteredWorker worker in workers)
            {
                worker.StartWorking();
            }
        }
Esempio n. 16
0
        internal void Mutate(DnaDrawing drawing, JobInfo info)
        {
            if (info.WillMutate(info.Settings.AddPointMutationRate))
                AddPoint(drawing, info);

            if (info.WillMutate(info.Settings.RemovePointMutationRate))
                RemovePoint(drawing, info);

            Brush.Mutate(drawing, info);

            unchecked
            {
                for (int i = 0; i < Points.Count;i++)
                {
                    var point = Points[i];
                    point.Mutate(drawing, info);
                }
            }
        }
Esempio n. 17
0
 internal static int Randomize(this int self,JobInfo info, int min, int max)
 {
     return self + info.GetRandomNumber(min, max);
 }
Esempio n. 18
0
 internal void Init(DnaDrawing drawing,JobInfo info)
 {
     X = info.GetRandomNumber(0, info.SourceImage.Width);
     Y = info.GetRandomNumber(0, info.SourceImage.Height);
 }
Esempio n. 19
0
 public void RemovePolygon(JobInfo info)
 {
     if (Polygons.Count > info.Settings.PolygonsMin)
     {
         int index = info.GetRandomNumber(0, Polygons.Count);
         Polygons.RemoveAt(index);
         SetDirty();
     }
 }
Esempio n. 20
0
        public void Mutate(DnaDrawing drawing, JobInfo info)
        {
            if (info.WillMutate(info.Settings.AddPointMutationRate))
                AddPoint(drawing, info);

            if (info.WillMutate(info.Settings.RemovePointMutationRate))
                RemovePoint(drawing, info);

            if (info.WillMutate(info.Settings.FlipSplinesMutationRate))
                FlipSplines(drawing, info);

            if (info.WillMutate(info.Settings.FlipFilledMutationRate))
                FlipFilled(drawing, info);

            if (info.WillMutate(info.Settings.FlipFilledMutationRate))
                Width = info.GetRandomNumber(1, 8);

            Brush.Mutate(drawing, info);
            foreach(var point in Points)
            {
                point.Mutate(drawing, info);
            }

            //IsComplex = false;// checkComplex();
        }
Esempio n. 21
0
 public DefaultEvolutionJob(JobInfo info)
     : this(null, info)
 {
 }
Esempio n. 22
0
        public void AddPolygonClone(JobInfo info)
        {
            if (Polygons.Count < info.Settings.PolygonsMax)
            {
                if (Polygons.Count < 1)
                    AddPolygon(info);
                else
                {
                    DnaPolygon parent = Polygons[info.GetRandomNumber(0, Polygons.Count)];
                    var newPolygon = parent.Clone();
                    Polygons.Insert(Polygons.IndexOf(parent), newPolygon);

                    newPolygon.Offset(info.GetRandomNumber(-6, 6), info.GetRandomNumber(-6, 6));

                    newPolygon.Width = info.GetRandomNumber(1, 8);

                    SetDirty();
                }
            }
        }
Esempio n. 23
0
        public void AddPolygon(JobInfo info)
        {
            if (Polygons.Count < info.Settings.PolygonsMax)
            {
                var newPolygon = new DnaPolygon();
                newPolygon.Init(this, info);

                int index = info.GetRandomNumber(0, Polygons.Count);

                Polygons.Insert(index, newPolygon);

                SetDirty();
            }
        }
Esempio n. 24
0
        private void RemovePoint(DnaDrawing drawing, JobInfo info)
        {
            if (Points.Count > info.Settings.PointsPerPolygonMin)
            {
                if (drawing.PointCount > info.Settings.PointsMin)
                {
                    int index = info.GetRandomNumber(0, Points.Count);
                    Points.RemoveAt(index);

                    drawing.SetDirty();
                }
            }
        }
Esempio n. 25
0
        private void AddPoint(DnaDrawing drawing, JobInfo info)
        {
            if (Points.Count < info.Settings.PointsPerPolygonMax)
            {
                if (drawing.PointCount < info.Settings.PointsMax)
                {
                    var newPoint = new DnaPoint();

                    int index = info.GetRandomNumber(1, Points.Count - 1);

                    DnaPoint prev = Points[index - 1];
                    DnaPoint next = Points[index];

                    newPoint.X = (prev.X + next.X) / 2;
                    newPoint.Y = (prev.Y + next.Y) / 2;


                    Points.Insert(index, newPoint);

                    drawing.SetDirty();
                }
            }
        }
Esempio n. 26
0
 private void FlipSplines(DnaDrawing drawing, JobInfo info)
 {
     SetSplinesAndFilled(info.Settings, !Splines, Filled);
 }
Esempio n. 27
0
 private static DnaDrawing GetNewInitializedDrawing(JobInfo info)
 {
     var drawing = new DnaDrawing();
     drawing.Init(info);
     return drawing;
 }
Esempio n. 28
0
 internal DnaDrawing GetMutatedChild(JobInfo info)
 {
     DnaDrawing child = Clone();
     child.Mutate(info);
     return child;
 }