コード例 #1
0
        public void Calculate(Wiring wiring)
        {
            var sourceMutuals = DatabaseManager.Instance.GetCalculatedMutualActionOfBCSAndBA();

            if (sourceMutuals == null)
            {
                return;
            }

            Remove();

            var wires = wiring.Wires;

            var influences = new List <(int a, int b, float value)>();

            var maxValue = sourceMutuals.Max(m => Math.Abs(m.value));
            var mutuals  = sourceMutuals.Select(m => (wire: wires.First(w => w.Name == m.name), wiresInfluences: m.influences.Select(i => (wires.First(w => w.Name == i.name), i.frequency, i.value)).ToList(), m.blocksInfluences, m.exceeded, m.value, color: _gradient.Evaluate((float)(Math.Abs(m.value) / maxValue)))).ToList();

            _wires = Wire.Factory.Create(mutuals, transform);

            foreach (var wire in _wires)
            {
                wire.Clicked += Wire_Clicked;
            }

            IsCalculated = true;
            Calculated.Invoke();

            FilterMaxValue = maxValue;
        }
コード例 #2
0
ファイル: Sky.cs プロジェクト: Astrarium/Astrarium
 public void Calculate()
 {
     foreach (var calc in Calculators)
     {
         calc.Calculate(Context);
     }
     Calculated?.Invoke();
 }
コード例 #3
0
        public async static void ComputeAsync(uint numberOfPoints)
        {
            var task = new Task <double>(new Func <object, double> ((n) => Compute(n)), numberOfPoints);

            task.Start();
            double result = await task;

            //var awaiter = task.GetAwaiter();
            //awaiter.OnCompleted(new Action(() => { result =  awaiter.GetResult();Console.WriteLine(""+result); }));
            Console.WriteLine("" + result);
            Calculated?.Invoke(result);
        }
コード例 #4
0
        public async static void ComputeAsyncMultasks(int numberOfTasks, uint numberOfPoints)
        {
            var tasks   = new Task <double> [numberOfTasks];
            var results = new double[numberOfTasks];

            for (int i = 0; i < numberOfTasks; i++)
            {
                tasks[i] = new Task <double>(new Func <object, double>((n) => Compute(n)), numberOfPoints);
                tasks[i].Start();
            }
            for (int i = 0; i < numberOfTasks; i++)
            {
                results[i] = await tasks[i];
            }
            var result = 0.0;

            foreach (var r in results)
            {
                result += r;
            }
            Calculated?.Invoke(result / numberOfTasks);
        }
コード例 #5
0
 private void OnCalculated(int result)
 {
     Calculated?.Invoke(this, result);
 }
コード例 #6
0
 protected override void Calculate()
 {
     base.Calculate();
     Value = CharacteristicsCalculator.CalculateCombatStat(this);
     Calculated?.Invoke((this), new CombatStatCalculatedEventArgs(this));
 }
コード例 #7
0
 private void OnCalculated(decimal result)
 {
     Calculated?.Invoke(this, result);
 }
コード例 #8
0
        /// <summary>
        /// Perform all the calculations necessary to determine the
        /// usable text area from the given template and stationary image.
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        protected Rectangle[] Calculate()
        {
            Rectangle[] CalculateRet = default;
            Bitmap      bmp;

            // what we're going to do is map every possible rectangular region in the image.
            // we will accept a certain percentage of white space to add that rectangle to the image.

            double minX;
            double minY;
            int    x;
            int    y;
            int    cx;
            int    cy;
            int    l;
            int    c = 0;
            int    d = 0;

            var rcCol     = new List <Rectangle>();
            var lineParts = new LineSegments();

            var ceArgs = new CalculatedEventArgs(null, 0, DateTime.MinValue, DateTime.MinValue);

            ceArgs.StartTimer();

            // Dim sMult As Double = 1.0#
            // Dim maxImg As Integer = 2400

            bmp = _img;

            // If _img.Width > maxImg OrElse _img.Height > maxImg Then

            // If _img.Width > _img.Height Then
            // x = maxImg
            // y = _img.Height * (maxImg / _img.Width)
            // sMult = maxImg / _img.Width
            // Else
            // y = maxImg
            // x = _img.Width * (maxImg / _img.Height)
            // sMult = maxImg / _img.Height
            // End If

            // bmp = New Bitmap(x, y, PixelFormat.Format32bppArgb)
            // Dim g As Graphics = Graphics.FromImage(bmp)

            // g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
            // g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
            // g.SmoothingMode = Drawing2D.SmoothingMode.None

            // g.DrawImage(_img, 0, 0, x, y)

            // g.Dispose()
            // _img = bmp
            // Else
            // bmp = _img
            // End If

            cx   = bmp.Width;
            cy   = bmp.Height;
            minX = _minUsableX * cx;
            minY = _minUsableY * cy;
            var    bm = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            MemPtr mm = bm.Scan0;

            ceArgs.TotalCalculations = cx * cy * 2;

            for (y = 0; y < cy; y++)
            {
                c = -1;
                d = -1;

                for (x = 0; x < cx; x++)
                {
                    l = (y * cx + x) * 4;
                    if (mm.ByteAt(l) >= 250 && mm.ByteAt(l + 1) >= 250 && mm.ByteAt(l + 2) >= 250)

                    {
                        if (c == -1)
                        {
                            c = x;
                            d = 0;
                        }
                        else
                        {
                            d += 1;
                        }
                    }
                    else if (d != -1)
                    {
                        if (d > minX)
                        {
                            lineParts.Add(new LineSegment(c, d, y));
                        }

                        c = -1;
                        d = -1;
                    }
                }

                if (d > minX)
                {
                    lineParts.Add(new LineSegment(c, d, y));
                }
            }

            lineParts.Sort();
            _rawData = lineParts;
            var          experiment = new List <LineSegments>();
            LineSegments temp;
            // Dim temp2 As LineSegments

            double minArea = minX * minY;

            minArea *= 0.5d;
            ceArgs.TotalCalculations += cx * cy;

            var loopTo2 = cx - 1;

            for (x = 0; (int)(cx * 0.0375d) >= 0 ? x <= loopTo2 : x >= loopTo2; x += (int)(cx * 0.0375d))
            {
                var loopTo3 = cy - 1;

                for (y = 0; (int)(cy * 0.0375d) >= 0 ? y <= loopTo3 : y >= loopTo3; y += (int)(cy * 0.0375d))
                {
                    l    = (y * cx + x) * 4;
                    temp = _rawData.FindSet(x, cx - x, y, false);
                    if (temp is null || temp.Area < minArea)
                    {
                        continue;
                    }
                    for (l = temp.Count - 2; l >= 1; l -= 1)
                    {
                        if (temp[l].Index - temp[l - 1].Index > temp.OriginContinuityThreshold)
                        {
                            temp.RemoveAt(l - 1);
                        }
                    }

                    ceArgs.TotalCalculations += temp.Count + _rawData.Count;
                    experiment.Add(temp);
                }
            }

            experiment.Sort(new SortByArea());
            experiment.Reverse();
            LineSegments[] pps; // = lineParts.FindAllContiguousRegions
            pps = experiment.ToArray();
            Clear();
            bmp.UnlockBits(bm);
            ceArgs.TotalCalculations += pps.Count() + _rawData.Count;
            _Regions.Clear();
            foreach (var px in pps)
            {
                var rc = px.Bounds;
                temp = _rawData.FindSet(rc.Left, rc.Right, rc.Top, true, false);
                if (temp is null)
                {
                    continue;
                }
                rc = temp.Bounds;
                if (rc.Width < minX)
                {
                    continue;
                }
                if (rc.Height < minY)
                {
                    continue;
                }
                rc.Inflate(-20, -20);
                if (_purgeOverlaps)
                {
refor:
                    ;
                    foreach (var rcChk in rcCol)
                    {
                        if (rcChk.IntersectsWith(rc))
                        {
                            if (rcChk.Width * rcChk.Height > rc.Width * rc.Height) // AndAlso (rcChk.Width > rc.Width) Then
                            {
                                rc = rcChk;
                            }
                            else if (TestSquareness(rcChk) < TestSquareness(rc)) // AndAlso (rc.Width >= rcChk.Width) Then
                            {
                                rcCol.Remove(rcChk);
                                goto refor;
                            }
                            else
                            {
                                rc = Rectangle.Empty;
                            }

                            break;
                        }
                    }
                }

                if (temp is object)
                {
                    Add(temp);
                }
                if (rc != Rectangle.Empty)
                {
                    // If CheckRect(rc, cx, cy, mm) = False Then Continue For
                    rcCol.Add(rc);
                    _Regions.Add(rc);
                }
            }

            ceArgs.StopTimer();
            CalculateRet   = rcCol.ToArray();
            ceArgs.Regions = _Regions;
            OnPropertyChanged("Regions");
            OnPropertyChanged("RawOutput");
            Calculated?.Invoke(this, ceArgs);
            return(CalculateRet);
        }
コード例 #9
0
 protected virtual void OnCalculated(double result)
 {
     Calculated?.Invoke(this, result);
 }