Esempio 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);
        }
        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);
        }
Esempio n. 3
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);
        }