private void InitGrisCellule()
            {
                var nb   = 0f;
                var gris = 0;

                var enveloppe = Site.Polygon.Enveloppe;

                for (int x = 0; x < enveloppe.Width; x++)
                {
                    for (int y = 0; y < enveloppe.Height; y++)
                    {
                        var pt = new PointF(enveloppe.X + x, enveloppe.Y + y);
                        if (Site.Polygon.InPolygon(pt))
                        {
                            nb++;
                            gris += BitmapHelper.ValeurCanal((int)x, (int)y, BitmapHelper.Canal.Luminosite);
                        }
                    }
                }

                if (nb > 0)
                {
                    GrisCellule = gris / nb;
                }
            }
            private void InitFacteurGris()
            {
                var nb   = 0f;
                var gris = 0;
                var r2   = (CercleInscrit * CercleInscrit) * 0.25;

                for (int i = 0; i <= CercleInscrit; i++)
                {
                    for (int j = 0; j <= CercleInscrit; j++)
                    {
                        var x = Site.X + i; var y = Site.Y + j;
                        var dx = i - (CercleInscrit * 0.5); var dy = j - (CercleInscrit * 0.5);
                        if (x > 0 && x < Settings.Dimensions.Width && y > 0 && y < Settings.Dimensions.Height && ((dx * dx) + (dy * dy)) <= r2)
                        {
                            nb++;
                            gris += BitmapHelper.ValeurCanal((int)x, (int)y, BitmapHelper.Canal.Luminosite);
                        }
                    }
                }

                if (nb > 0)
                {
                    GrisCercleInscrit = gris / nb;
                }
            }
Esempio n. 3
0
            public void InitFacteurGris()
            {
                var nb   = 0f;
                var gris = 0;
                var r2   = Settings.MinimumDistance * Settings.MinimumDistance;

                for (int i = 0; i <= (Settings.MinimumDistance * 2); i++)
                {
                    for (int j = 0; j <= (Settings.MinimumDistance * 2); j++)
                    {
                        var x = X + i; var y = Y + j;
                        var dx = i - Settings.MinimumDistance; var dy = j - Settings.MinimumDistance;
                        if (x > 0 && x < Settings.Dimensions.Width && y > 0 && y < Settings.Dimensions.Height && ((dx * dx) + (dy * dy)) <= r2)
                        {
                            nb++;
                            gris += BitmapHelper.ValeurCanal((int)x, (int)y, BitmapHelper.Canal.Luminosite);
                        }
                    }
                }

                if (nb > 0)
                {
                    Gris = gris / nb;
                }

                // On calcul l'inverse pour augment la taille dans les noirs et diminuer dans les blancs
                var f = (255 - Gris) / 255f;

                FacteurGris     = f;
                MinimumDistance = Settings.MinimumDistance + Settings.MinimumDistance * f;
            }
Esempio n. 4
0
        public static List <PointF> Run(DraftSight.Interop.dsAutomation.ReferenceImage img, int nbPoint, int niveauGrisMini = 2)
        {
            var sites = new List <PointF>();

            try
            {
                int LgMM = (int)img.Width;
                int HtMM = (int)img.Height;
                int LgPx = LgMM + 1;
                int HtPx = HtMM + 1;
                var bmp  = new Bitmap(img.GetPath());
                var Bmp  = bmp.Redimensionner(new Size(LgPx, HtPx));
                bmp.Dispose();

                int   decal  = 4;
                float decal2 = decal / 2f;

                BitmapHelper.Verrouiller(Bmp);

                int i = 0;

                while (i < nbPoint)
                {
                    float fx = RandomHelper.Random.Next(LgMM - decal);
                    float fy = RandomHelper.Random.Next(HtMM - decal);

                    int gris = BitmapHelper.ValeurCanal(MathHelper.FloorToInt(fx), MathHelper.FloorToInt(fy), Canal.Luminosite);

                    if (gris > niveauGrisMini && RandomHelper.Random.Next(255) <= gris)
                    {
                        sites.Add(new PointF(fx + decal2, fy + decal2));
                        i++;
                    }
                }

                BitmapHelper.Liberer();

                Bmp.Dispose();
            }
            catch (Exception ex) { Log.Message(ex); }

            return(sites);
        }
        private static List <PointF> Equilibrer()
        {
            var liste = new List <PointF>();

            foreach (var site in Settings.Graph.Sites)
            {
                var    enveloppe = site.Polygon.Enveloppe;
                double xSum = 0, ySum = 0, pSum = 0;

                for (int x = 0; x < enveloppe.Width; x++)
                {
                    for (int y = 0; y < enveloppe.Height; y++)
                    {
                        var pt = new PointF(enveloppe.X + x, enveloppe.Y + y);
                        if (site.Polygon.InPolygon(pt))
                        {
                            var gris = BitmapHelper.ValeurCanal((int)pt.X, (int)pt.Y, Canal.Luminosite);

                            xSum += gris * x;
                            ySum += gris * y;
                            pSum += gris;
                        }
                    }
                }

                if (pSum > 0)
                {
                    xSum /= pSum;
                    ySum /= pSum;
                }

                liste.Add(new PointF((float)(enveloppe.X + xSum), (float)(enveloppe.Y + ySum)));
            }

            return(liste);
        }