Esempio n. 1
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;
 }
Esempio n. 2
0
        private void SendBestYet()
        {
            var msg = new MsgCommand(this, MsgCommandCommands.SaveBestYet)
            {
                BestComparison = BestComparison,
                Best           = Best
            };

            _output.Enqueue(msg);
        }
Esempio n. 3
0
 private void BroadcastBestYet(List <JobCompare> jobs)
 {
     foreach (JQJob job in jobs)
     {
         MsgCommand msgot = new MsgCommand(null, MsgCommandCommands.LoadBestYet);
         msgot.BestComparison = CurrentProject.BestComparison;
         msgot.Best           = CurrentProject.BestYet;
         job.Input.Clear();
         job.Input.Enqueue(msgot);
     }
 }
Esempio n. 4
0
        public override void Run()
        {
            try
            {
                while (!_stop)
                {
                    if (_input.Count > 0)
                    {
                        MsgCommand mc = (MsgCommand)_input.Dequeue();
                        switch (mc.Command)
                        {
                        case MsgCommandCommands.Init:
                            LoadInit(mc);
                            break;

                        case MsgCommandCommands.LoadBestYet:
                            LoadBestYet(mc);
                            break;

                        case MsgCommandCommands.Stop:
                            _stop = true;
                            break;
                        }
                    }

                    if (Img != null)
                    {
                        if (ProcessIteration())
                        {
                            SendBestYet();
                            Thread.Sleep(0);
                        }
                    }
                    Thread.Sleep(0);
                }

                CallFinished(new JQEventArgs(this));
            }
            catch (Exception e)
            {
                CallError(new JQEventArgs(this), e);
            }
        }
Esempio n. 5
0
        private void workerthread()
        {
            int        lastgen     = (int)CurrentProject.BestYet.Generation;
            DateTime   started     = DateTime.Now;
            FastBitmap imagebitmap = new FastBitmap(CurrentProject.SourceImage.Width, CurrentProject.SourceImage.Height, PixelFormat.Format24bppRgb);

            List <JobCompare> jobs = new List <JobCompare>();

            JQMessageQueue results = new JQMessageQueue();

            for (int i = 0; i < CurrentProject.Properties.ThreadLimit; i++)
            {
                JobCompare job = new JobCompare();
                job.Input  = new JQMessageQueue();
                job.Output = results;
                jobs.Add(job);

                MsgCommand msg = new MsgCommand(null, MsgCommandCommands.Init);
                msg.Best           = CurrentProject.BestYet;
                msg.BestComparison = CurrentProject.BestComparison;
                msg.Entropy        = rd;
                msg.Img            = CurrentProject.SourceImage.Duplicate();
                msg.Properties     = CurrentProject.Properties;

                job.Input.Enqueue(msg);
                control.ScheduleJob(job);
            }

            while (!stopthread)
            {
                results.Trigger.WaitOne(100);

                while (results.Count > 0)
                {
                    MsgCommand msg = (MsgCommand)results.Dequeue();

                    switch (msg.Command)
                    {
                    case MsgCommandCommands.SaveBestYet:
                        lastiterations++;
                        if (msg.BestComparison < CurrentProject.BestComparison)
                        {
                            ACpG.Update(CurrentProject.BestComparison - msg.BestComparison);
                            AIpG.Update((int)(lastiterations - CurrentProject.BestYet.Iterations));

                            lastjobbest = jobs.IndexOf((JobCompare)msg.Job);

                            CurrentProject.BestYet        = msg.Best;
                            CurrentProject.BestComparison = msg.BestComparison;
                            CurrentProject.Changed        = true;
                            CurrentProject.BestYet.Generation++;
                            CurrentProject.BestYet.Iterations = lastiterations;
                        }
                        break;
                    }
                }

                TimeSpan sofar = DateTime.Now - started;

                if (sofar.TotalMilliseconds > 1000)
                {
                    CurrentProject.BestYet.DrawToFastBitmap(imagebitmap);
                    DisplayImageBitmap(imagebitmap);
                    changed = true;

                    started = DateTime.Now;
                    BroadcastBestYet(jobs);

                    Gps.Update((int)CurrentProject.BestYet.Generation - lastgen);
                    lastgen = (int)CurrentProject.BestYet.Generation;
                    GC.Collect();
                }
            }

            foreach (JQJob job in jobs)
            {
                MsgCommand msgot = new MsgCommand(null, MsgCommandCommands.Stop);
                job.Input.Enqueue(msgot);
            }
            stopthread = false;
        }
Esempio n. 6
0
 private void LoadBestYet(MsgCommand mc)
 {
     Best           = mc.Best;
     BestComparison = mc.BestComparison;
 }