예제 #1
0
        private void AddCirularInclusion(Scope scope, Point coordinates)
        {
            var pointsInside = GetPointsInsideCircle(inclusionsProperties.Size, coordinates);

            foreach (var point in pointsInside)
            {
                if (point.X < scope.Width && point.X > 0 && point.Y < scope.Height && point.Y > 0)
                {
                    if (!StructureHelpers.IsIdSpecial(scope.StructureArray[point.X, point.Y].Id) || scope.StructureArray[point.X, point.Y].Id == 0)
                    {
                        scope.StructureArray[point.X, point.Y].Color = Color.Black;
                        scope.StructureArray[point.X, point.Y].Id    = Convert.ToInt32(SpecialIds.Inclusion);
                    }
                }
            }
        }
        private IList <int> GetNRandomGrainIds()
        {
            var        grainsIds    = new List <int>();
            Point      actRandCoord = new Point(0, 0);
            List <int> prevRandIds  = new List <int>();

            for (int i = 0; i < grainBoundariesProperties.NumberOfGrainsToSelectBoundaries; i++)
            {
                prevRandIds.Add(baseScope.StructureArray[actRandCoord.X, actRandCoord.Y].Id);
                do
                {
                    actRandCoord = StructureHelpers.RandomCoordinates(baseScope.Width, baseScope.Height, random);
                }while (prevRandIds.IndexOf(baseScope.StructureArray[actRandCoord.X, actRandCoord.Y].Id) != -1);
                grainsIds.Add(baseScope.StructureArray[actRandCoord.X, actRandCoord.Y].Id);
            }
            return(grainsIds);
        }
예제 #3
0
        private void AddSquareInclusion(Scope scope, Point coordinates)
        {
            int a     = (int)(inclusionsProperties.Size / Math.Sqrt(2));
            int halfA = (a / 2);

            for (int x = coordinates.X - halfA; (x <= coordinates.X + halfA && x < scope.Width && x > 0); x++)
            {
                for (int y = coordinates.Y - halfA; (y <= coordinates.Y + halfA && y < scope.Height && y > 0); y++)
                {
                    if (!StructureHelpers.IsIdSpecial(scope.StructureArray[x, y].Id) || scope.StructureArray[x, y].Id == 0)
                    {
                        scope.StructureArray[x, y].Color = Color.Black;
                        scope.StructureArray[x, y].Id    = Convert.ToInt32(SpecialIds.Inclusion);
                    }
                }
            }
        }
        public Scope ClearBackground()
        {
            for (int i = 1; i < baseScope.Width - 1; i++)
            {
                for (int j = 1; j < baseScope.Height - 1; j++)
                {
                    if (baseScope.StructureArray[i, j].Id != Convert.ToInt32(SpecialIds.Boundaries))
                    {
                        baseScope.StructureArray[i, j].Id    = Convert.ToInt32(SpecialIds.Empty);
                        baseScope.StructureArray[i, j].Color = Color.White;
                    }
                }
            }

            baseScope.IsFull = true;
            StructureHelpers.UpdateBitmap(baseScope);

            return(baseScope);
        }
예제 #5
0
        public Scope AddInclusionsAfterGrainGrowth(Scope scope)
        {
            for (int inclusionNumber = 0; inclusionNumber < inclusionsProperties.Amount; inclusionNumber++)
            {
                Point coordinates;
                do
                {
                    coordinates = StructureHelpers.RandomCoordinates(scope.Width, scope.Height, random);
                }while (!IsCoordinateOnGrainBoundaries(scope, coordinates));

                switch (inclusionsProperties.InclusionsType)
                {
                case InclusionsType.Square:
                    AddSquareInclusion(scope, coordinates);
                    break;

                case InclusionsType.Circular:
                    AddCirularInclusion(scope, coordinates);
                    break;
                }
            }

            return(scope);
        }
예제 #6
0
        public Scope AddInclusionsAtTheBegining(Scope scope)
        {
            for (int inclusionNumber = 0; inclusionNumber < inclusionsProperties.Amount; inclusionNumber++)
            {
                Point coordinates;
                do
                {
                    coordinates = StructureHelpers.RandomCoordinates(scope.Width, scope.Height, random);
                }while (scope.StructureArray[coordinates.X, coordinates.Y].Id != 0);

                switch (inclusionsProperties.InclusionsType)
                {
                case InclusionsType.Square:
                    AddSquareInclusion(scope, coordinates);
                    break;

                case InclusionsType.Circular:
                    AddCirularInclusion(scope, coordinates);
                    break;
                }
            }

            return(scope);
        }
예제 #7
0
        private bool IsCoordinateOnGrainBoundaries(Scope scope, Point coordinates)
        {
            var centerId      = scope.StructureArray[coordinates.X, coordinates.Y].Id;
            var neighboursIds = new List <int>
            {
                scope.StructureArray[coordinates.X - 1, coordinates.Y].Id,
                scope.StructureArray[coordinates.X + 1, coordinates.Y].Id,
                scope.StructureArray[coordinates.X, coordinates.Y - 1].Id,
                scope.StructureArray[coordinates.X, coordinates.Y + 1].Id,
                scope.StructureArray[coordinates.X - 1, coordinates.Y - 1].Id,
                scope.StructureArray[coordinates.X - 1, coordinates.Y + 1].Id,
                scope.StructureArray[coordinates.X + 1, coordinates.Y - 1].Id,
                scope.StructureArray[coordinates.X + 1, coordinates.Y + 1].Id
            };

            foreach (var neighbourId in neighboursIds)
            {
                if (centerId != neighbourId && !StructureHelpers.IsIdSpecial(neighbourId))
                {
                    return(true);
                }
            }
            return(false);
        }
        private Scope SelectAllGrainsBoundaries()
        {
            var grainBoungarySize = grainBoundariesProperties.GrainBoundarySize;

            for (int i = 2; i < baseScope.Width - 2; i++)
            {
                for (int j = 2; j < baseScope.Height - 2; j++)
                {
                    if (((baseScope.StructureArray[i, j].Id != baseScope.StructureArray[i + 1, j].Id &&
                          !StructureHelpers.IsIdSpecial(baseScope.StructureArray[i + 1, j].Id)) ||
                         (baseScope.StructureArray[i, j].Id != baseScope.StructureArray[i - 1, j].Id &&
                          !StructureHelpers.IsIdSpecial(baseScope.StructureArray[i - 1, j].Id))) &&
                        !StructureHelpers.IsIdSpecial(baseScope.StructureArray[i, j].Id))
                    {
                        if (grainBoungarySize == 1)
                        {
                            baseScope.StructureArray[i, j].Id    = Convert.ToInt32(SpecialIds.Boundaries);
                            baseScope.StructureArray[i, j].Color = boundaryColor;
                        }
                        else
                        {
                            int halfSize = (grainBoungarySize - 1) / 2;
                            if (halfSize == 0)
                            {
                                baseScope.StructureArray[i, j].Id    = Convert.ToInt32(SpecialIds.Boundaries);
                                baseScope.StructureArray[i, j].Color = boundaryColor;
                            }
                            else
                            {
                                for (int w = i - halfSize; w < i + halfSize; w++)
                                {
                                    if (w > 0 && w < baseScope.Width - 1)
                                    {
                                        baseScope.StructureArray[w, j].Id    = Convert.ToInt32(SpecialIds.Boundaries);
                                        baseScope.StructureArray[w, j].Color = boundaryColor;
                                    }
                                }
                            }
                        }
                    }
                    if (((baseScope.StructureArray[i, j].Id != baseScope.StructureArray[i, j + 1].Id &&
                          !StructureHelpers.IsIdSpecial(baseScope.StructureArray[i, j + 1].Id)) ||
                         (baseScope.StructureArray[i, j].Id != baseScope.StructureArray[i, j - 1].Id &&
                          !StructureHelpers.IsIdSpecial(baseScope.StructureArray[i, j - 1].Id))) &&
                        !StructureHelpers.IsIdSpecial(baseScope.StructureArray[i, j].Id))
                    {
                        if (grainBoungarySize == 1)
                        {
                            baseScope.StructureArray[i, j].Id    = Convert.ToInt32(SpecialIds.Boundaries);
                            baseScope.StructureArray[i, j].Color = boundaryColor;
                        }
                        else
                        {
                            int halfSize = (grainBoungarySize - 1) / 2;
                            if (halfSize == 0)
                            {
                                baseScope.StructureArray[i, j].Id    = Convert.ToInt32(SpecialIds.Boundaries);
                                baseScope.StructureArray[i, j].Color = boundaryColor;
                            }
                            else
                            {
                                for (int h = j - halfSize; h < j + halfSize; h++)
                                {
                                    if (h > 0 && h < baseScope.Height - 1)
                                    {
                                        baseScope.StructureArray[i, h].Id    = Convert.ToInt32(SpecialIds.Boundaries);
                                        baseScope.StructureArray[i, h].Color = boundaryColor;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            baseScope.IsFull = true;
            StructureHelpers.UpdateBitmap(baseScope);

            return(baseScope);
        }