Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public static List <Cellule> Start(DraftSight.Interop.dsAutomation.ReferenceImage img, List <PointF> liste, int nbEquilibrage, out VoronoiGraph graph)
        {
            List <Cellule> listepoincon = null;

            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());
                Settings.Bmp = bmp.Redimensionner(new Size(LgPx, HtPx));
                bmp.Dispose();
                Settings.Dimensions = new Size(LgMM, HtMM);;
                //Settings.Histogram = BitmapHelper.Histogramme(Settings.Bmp);

                BitmapHelper.Verrouiller(Settings.Bmp);


                Settings.Graph = VoronoiGraph.ComputeVoronoiGraph(liste, LgMM, HtMM, false);

                for (int k = 0; k < nbEquilibrage; k++)
                {
                    liste          = Equilibrer();
                    Settings.Graph = VoronoiGraph.ComputeVoronoiGraph(liste, LgMM, HtMM, false);
                }

                listepoincon = CalculerCellule();

                BitmapHelper.Liberer();

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

            graph = Settings.Graph;
            return(listepoincon);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public static List <PointF> Run(DraftSight.Interop.dsAutomation.ReferenceImage img, int nbPoint, double factDistanceRejection = 2, double factDistMin = 0.7)
        {
            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());
                Settings.Bmp = bmp.Redimensionner(new Size(LgPx, HtPx));
                bmp.Dispose();

                Settings.Dimensions      = new SizeF(LgMM, HtMM);
                Settings.Center          = new PointF(LgMM * 0.5f, HtMM * 0.5f);
                Settings.MinimumDistance = (float)((LgMM / Math.Sqrt(nbPoint / (HtMM / (double)LgMM))) * factDistMin);
                Log.Message("MinimumDistance : " + Settings.MinimumDistance);
                Settings.CellSize              = Settings.MinimumDistance / SquareRootTwo;
                Settings.GridWidth             = (int)(LgMM / Settings.CellSize) + 1;
                Settings.GridHeight            = (int)(HtMM / Settings.CellSize) + 1;
                Settings.FactDistanceRejection = (float)factDistanceRejection;

                State.Grid         = new VecteurV?[Settings.GridWidth, Settings.GridHeight];
                State.ActivePoints = new List <VecteurV>();
                State.Points       = new List <VecteurV>();

                BitmapHelper.Verrouiller(Settings.Bmp);

                AddFirstPoint();

                while (State.ActivePoints.Count != 0)
                {
                    var listIndex = RandomHelper.Random.Next(State.ActivePoints.Count);

                    var point = State.ActivePoints[listIndex];
                    var found = false;

                    for (var k = 0; k < DefaultPointsPerIteration; k++)
                    {
                        found |= AddNextPoint(point);
                    }

                    if (!found)
                    {
                        State.ActivePoints.RemoveAt(listIndex);
                    }
                }

                BitmapHelper.Liberer();

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

            var ListePoints = new List <PointF>();

            foreach (var pt in State.Points)
            {
                ListePoints.Add(pt.GetPointF());
            }

            return(ListePoints);
        }