예제 #1
0
        public InitBoundaries(MainProperties properties)
        {
            ClearBoundaries        = new Range(properties.RangeWidth, properties.RangeHeight);
            BoundariesAll          = new Range(properties.RangeWidth, properties.RangeHeight);
            BoundariesSelected     = new Range(properties.RangeWidth, properties.RangeHeight);
            BoundariesSingleSelect = new Range(properties.RangeWidth, properties.RangeHeight);

            InitStructures.AddBlackBorder(ClearBoundaries);
            InitStructures.AddBlackBorder(BoundariesAll);
            InitStructures.AddBlackBorder(BoundariesSelected);
            InitStructures.AddBlackBorder(BoundariesSingleSelect);

            // init grains array by default values
            for (int i = 1; i < properties.RangeWidth - 1; i++)
            {
                for (int j = 1; j < properties.RangeHeight - 1; j++)
                {
                    ClearBoundaries.GrainsArray[i, j] = new Grain()
                    {
                        Id       = 0,
                        Color    = Color.White,
                        Energy_H = 0
                    };
                    BoundariesAll.GrainsArray[i, j] = new Grain()
                    {
                        Id       = 0,
                        Color    = Color.White,
                        Energy_H = 0
                    };
                    BoundariesSelected.GrainsArray[i, j] = new Grain()
                    {
                        Id       = 0,
                        Color    = Color.White,
                        Energy_H = 0
                    };
                    BoundariesSingleSelect.GrainsArray[i, j] = new Grain()
                    {
                        Id       = 0,
                        Color    = Color.White,
                        Energy_H = 0
                    };
                }
            }
        }
        public Range UpdateSubstructuresMC(Range tempRange, MainProperties properties)
        {
            bool change;

            for (int i = 1; i < tempRange.Width - 1; i++)
            {
                for (int j = 1; j < tempRange.Height - 1; j++)
                {
                    change = false;
                    foreach (var point in SubStrucrtuePointsList)
                    {
                        if (tempRange.GrainsArray[i, j].Color == tempRange.StructureBitmap.GetPixel(point.X, point.Y))
                        {
                            if (properties.SubstructuresType == SubstructuresType.Substructure)
                            {
                                tempRange.GrainsArray[i, j] = new Grain
                                {
                                    Id    = (int)SpecialId.Id.Substructure,
                                    Color = tempRange.GrainsArray[i, j].Color
                                };
                            }
                            else
                            {
                                tempRange.GrainsArray[i, j] = new Grain
                                {
                                    Id    = (int)SpecialId.Id.DualPhase,
                                    Color = Color.Pink
                                };
                            }

                            change = true;
                        }
                    }
                    if (tempRange.GrainsArray[i, j].Id == -2)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Inclusion,
                            Color = Color.Black
                        };
                        change = true;
                    }
                    if (change == false)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Empty,
                            Color = Color.White
                        };
                    }
                }
            }

            InitStructures.AllGrainsTypes = new Grain[properties.AmountOfGrains];

            // set random starting coordinates [x,y] and color for grains
            for (int grainNumber = 1; grainNumber <= properties.AmountOfGrains; grainNumber++)
            {
                InitStructures.AllGrainsTypes[grainNumber - 1] = new Grain()
                {
                    Color = Color.FromArgb(Random.Next(10, 240), Random.Next(10, 240), Random.Next(10, 240)),
                    Id    = grainNumber
                };
            }

            for (int i = 1; i < tempRange.Width - 1; i++)
            {
                for (int j = 1; j < tempRange.Height - 1; j++)
                {
                    if (tempRange.GrainsArray[i, j].Id >= 0)
                    {
                        int r = Random.Next(InitStructures.AllGrainsTypes.Length);
                        tempRange.GrainsArray[i, j] = new Grain()
                        {
                            Id       = InitStructures.AllGrainsTypes[r].Id,
                            Color    = InitStructures.AllGrainsTypes[r].Color,
                            Energy_H = InitStructures.AllGrainsTypes[r].Energy_H
                        };
                    }
                }
            }

            tempRange.IsFull = false;
            return(tempRange);
        }
        public Range UpdateSubstructuresCA(Range tempRange, MainProperties properties)
        {
            bool change;

            for (int i = 1; i < tempRange.Width - 1; i++)
            {
                for (int j = 1; j < tempRange.Height - 1; j++)
                {
                    change = false;
                    foreach (var point in SubStrucrtuePointsList)
                    {
                        if (tempRange.GrainsArray[i, j].Color == tempRange.StructureBitmap.GetPixel(point.X, point.Y))
                        {
                            if (properties.SubstructuresType == SubstructuresType.Substructure)
                            {
                                tempRange.GrainsArray[i, j] = new Grain
                                {
                                    Id    = (int)SpecialId.Id.Substructure,
                                    Color = tempRange.GrainsArray[i, j].Color
                                };
                            }
                            else
                            {
                                tempRange.GrainsArray[i, j] = new Grain
                                {
                                    Id    = (int)SpecialId.Id.DualPhase,
                                    Color = Color.Pink
                                };
                            }

                            change = true;
                        }
                    }
                    if (tempRange.GrainsArray[i, j].Id == -2)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Inclusion,
                            Color = Color.Black
                        };
                        change = true;
                    }
                    if (change == false)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Empty,
                            Color = Color.White
                        };
                    }
                }
            }

            Point coordinates;

            for (int i = 1; i <= properties.AmountOfGrains; i++)
            {
                while (true)
                {
                    coordinates = RandomCoordinates.Get(tempRange.Width, tempRange.Height, Random);

                    if (tempRange.GrainsArray[coordinates.X, coordinates.Y].Id == 0)
                    {
                        tempRange.GrainsArray[coordinates.X, coordinates.Y].Color = Color.FromArgb(Random.Next(10, 240), Random.Next(10, 240), Random.Next(10, 240));
                        tempRange.GrainsArray[coordinates.X, coordinates.Y].Id    = Random.Next(1, 1000000);
                        break;
                    }
                }
            }

            tempRange.IsFull = false;
            return(tempRange);
        }
        public Range UpdateSubstructuresSRX(Range tempRange, MainProperties properties)
        {
            for (int i = 1; i < tempRange.Width - 1; i++)
            {
                for (int j = 1; j < tempRange.Height - 1; j++)
                {
                    if (tempRange.GrainsArray[i, j].Id == (int)SpecialId.Id.Nucleon)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Empty,
                            Color = Color.White
                        };
                    }
                    else if (tempRange.GrainsArray[i, j].Id > 0)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Substructure,
                            Color = tempRange.GrainsArray[i, j].Color
                        };
                    }
                }
            }

            if (properties.MethodType == MethodType.CellularAutomata)
            {
                Point coordinates;
                for (int grainNumber = 1; grainNumber <= properties.AmountOfGrains; grainNumber++)
                {
                    do
                    {
                        coordinates = RandomCoordinates.Get(tempRange.Width, tempRange.Height, Random);
                    }while (tempRange.GrainsArray[coordinates.X, coordinates.Y].Id != 0);

                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Color = InitStructures.AllGrainsTypes[grainNumber - 1].Color;
                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Id    = InitStructures.AllGrainsTypes[grainNumber - 1].Id;
                }
            }
            else
            {
                InitStructures.AllGrainsTypes = new Grain[properties.AmountOfGrains];

                // set random starting coordinates [x,y] and color for grains
                for (int grainNumber = 1; grainNumber <= properties.AmountOfGrains; grainNumber++)
                {
                    InitStructures.AllGrainsTypes[grainNumber - 1] = new Grain()
                    {
                        Color = Color.FromArgb(Random.Next(10, 240), Random.Next(10, 240), Random.Next(10, 240)),
                        Id    = grainNumber
                    };
                }
                for (int i = 1; i < tempRange.Width - 1; i++)
                {
                    for (int j = 1; j < tempRange.Height - 1; j++)
                    {
                        if (tempRange.GrainsArray[i, j].Id == 0)
                        {
                            int r = Random.Next(InitStructures.AllGrainsTypes.Length);
                            tempRange.GrainsArray[i, j] = new Grain()
                            {
                                Id    = InitStructures.AllGrainsTypes[r].Id,
                                Color = InitStructures.AllGrainsTypes[r].Color
                            };
                        }
                    }
                }
            }


            return(tempRange);
        }