Example #1
0
        public List <Cellule> GetVoisinageAller(int x, int y)
        {
            List <Cellule> voisinage = new List <Cellule>();

            Cellule cell = GetVoisinage(x, y, Direction.NO);

            if (cell != null)
            {
                voisinage.Add(cell);
            }

            cell = GetVoisinage(x, y, Direction.N);

            if (cell != null)
            {
                voisinage.Add(cell);
            }

            cell = GetVoisinage(x, y, Direction.NE);

            if (cell != null)
            {
                voisinage.Add(cell);
            }

            cell = GetVoisinage(x, y, Direction.O);

            if (cell != null)
            {
                voisinage.Add(cell);
            }



            // voisinage.Add(GetVoisinage(x, y, Direction.NO));
            //  voisinage.Add(GetVoisinage(x, y, Direction.N));
            // voisinage.Add(GetVoisinage(x, y, Direction.NE));
            //  voisinage.Add(GetVoisinage(x, y, Direction.O));

            return(voisinage);
        }
Example #2
0
        public List <Cellule> GetVoisinageRetour(int x, int y)
        {
            Cellule        cell      = null;
            List <Cellule> voisinage = new List <Cellule>();

            cell = GetVoisinage(x, y, Direction.SO);
            if (cell != null)
            {
                voisinage.Add(cell);
            }

            cell = GetVoisinage(x, y, Direction.S);
            if (cell != null)
            {
                voisinage.Add(cell);
            }

            cell = GetVoisinage(x, y, Direction.SE);
            if (cell != null)
            {
                voisinage.Add(cell);
            }

            cell = GetVoisinage(x, y, Direction.E);
            if (cell != null)
            {
                voisinage.Add(cell);
            }

            //voisinage.Add(GetVoisinage(x, y, Direction.S));
            //voisinage.Add(GetVoisinage(x, y, Direction.SE));
            //voisinage.Add(GetVoisinage(x, y, Direction.E));



            return(voisinage);
        }
Example #3
0
        public Boolean MarqueRegionAller(out SetList equivalentRegions)
        {
            string str            = "";
            int    RegionCourante = 1;

            equivalentRegions = null;

            try
            {
                rect      = new Dictionary <string, Structure>();
                FinalRect = new Dictionary <string, Structure>();

                equivalentRegions = new SetList();

                //equivalentRegions = new List<int>();
                structures = new List <Structure>();
                listRegion = new ArrayList();

                for (int y = 0; y < matrix.Hauteur; y++)
                {
                    for (int x = 0; x < matrix.Largeur; x++)
                    {
                        if (y == 128 && x == 313)
                        {
                            str = "";
                        }
                        // Si on est sur une forme
                        if (matrix.Values[x, y] == 0)
                        {
                            List <Cellule> voisinage = null;
                            voisinage = matrix.GetVoisinageAller(x, y);

                            //int matchNombre = 0;

                            //foreach (Cellule elem in voisinage)
                            //{
                            //    if (elem.Value > 0)
                            //        matchNombre++;
                            //}


                            int matchNombre = voisinage.Count(cellule => cellule.Value == 0);

                            // Si pas de pixels labelises
                            if (matchNombre == 0)
                            {
                                regionMatrix.Values[x, y] = RegionCourante;

                                equivalentRegions.Add(RegionCourante, new Set()
                                {
                                    RegionCourante
                                });
                                //equivalentRegions.Add(RegionCourante);
                                //structures.Add(new Structure(x, y, RegionCourante));
                                rect.Add(RegionCourante.ToString(), new Structure(x, y));

                                //equivalentRegions.Add(RegionCourante, new Set() { RegionCourante });
                                RegionCourante++;
                            }
                            else if (matchNombre == 1)
                            {
                                Cellule oneCell = voisinage.First(cellule => cellule.Value == 0);
                                regionMatrix.Values[x, y] = regionMatrix.Values[oneCell.X, oneCell.Y];;
                            }
                            else if (matchNombre > 1)
                            {
                                List <int> distinctRegions = voisinage.Select(cellule => regionMatrix.Values[cellule.X, cellule.Y]).Distinct().ToList();
                                while (distinctRegions.Remove(0))
                                {
                                    ;
                                }

                                if (distinctRegions.Count == 1) //step5
                                {
                                    regionMatrix.Values[x, y] = distinctRegions[0];
                                }
                                else if (distinctRegions.Count > 1)
                                {
                                    // Equivalence tout de suite

                                    int firstRegion = distinctRegions[0];
                                    regionMatrix.Values[x, y] = firstRegion;

                                    foreach (int region in distinctRegions)
                                    {
                                        if (!equivalentRegions[firstRegion].Contains(region))
                                        {
                                            equivalentRegions[firstRegion].Add(region);
                                        }
                                    }

                                    //foreach (Cellule voisi in voisinage)
                                    //{
                                    //    if (voisi.Value == 0)
                                    //        regionMatrix.Values[voisi.X, voisi.Y] = firstRegion;

                                    //}
                                }
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                return(false);
            }
            finally
            {
            }
        }