Beispiel #1
0
        /// <summary>
        /// Erodes plates.
        /// </summary>
        private static void GenerateErosion()
        {
            var rulesLocation      = InputFileName("Erosion Rule");
            var inHeightLocation   = InputFileName("Height Data");
            var inRainLocation     = InputFileName("Rainfall Data");
            var outErosionLocation = InputFileName("Erosion Data");
            var outIsWaterLocation = InputFileName("Is Water Data");
            var rules       = (ErosionMapRules)RulesIO.Load(rulesLocation.Name, nameof(ErosionMapRules));
            var heightMap   = PointIO.OpenDoubleData(inHeightLocation.Name + ".bin", 2 * rules.xHalfSize, rules.ySize);
            var rainfallMap = new double[2 * rules.xHalfSize, rules.ySize];

            for (int i = 0; i < rules.numberSeasons; i++)
            {
                var rainfallMapTemp = PointIO.OpenDoubleData(inHeightLocation.Name + ".bin", 2 * rules.xHalfSize, rules.ySize);
                for (int x = 0; x < 2 * rules.xHalfSize; x++)
                {
                    for (int y = 0; y < rules.ySize; y++)
                    {
                        rainfallMap[x, y] += rainfallMapTemp[x, y];
                    }
                }
            }
            GenerateErosionMap.Run(heightMap, rainfallMap, rules, out bool[,] isWater, out double[,] erosionMap);
            PointIO.SaveHeightImage(outErosionLocation.Name, erosionMap);
            PointIO.SaveMapData(outErosionLocation.Name + ".bin", erosionMap);
            CheapBinaryIO.WriteBinary(outIsWaterLocation.Name + ".bin", isWater);
        }
Beispiel #2
0
        /// <summary>
        /// Saves point plate data to the given file.
        /// </summary>
        /// <param name="fileName">File to open.</param>
        /// <param name="pointPlateData">Data to save.</param>
        public static void SavePointPlateData(string fileName, int[,] pointPlateData)
        {
            var plateCount = 0;

            for (int x = 0; x < pointPlateData.GetLength(0); x++)
            {
                for (int y = 0; y < pointPlateData.GetLength(1); y++)
                {
                    if (pointPlateData[x, y] > plateCount)
                    {
                        plateCount = pointPlateData[x, y];
                    }
                }
            }
            CheapBinaryIO.Write(fileName + plateNumberExtension, pointPlateData, plateCount);
        }
Beispiel #3
0
        /// <summary>
        /// Saves point data to the given file.
        /// </summary>
        /// <param name="fileName">File to open.</param>
        /// <param name="rules">Rules for how data will be written.</param>
        /// <param name="pointData">Data to save.</param>
        public static void SavePointData(string fileName, GeneralRules rules, PlatePoint[,] pointData)
        {
            var plateNumbers       = new int[2 * rules.xHalfSize, rules.ySize];
            var xBirthPlace        = new int[2 * rules.xHalfSize, rules.ySize];
            var yBirthPlace        = new int[2 * rules.xHalfSize, rules.ySize];
            var birthDate          = new int[2 * rules.xHalfSize, rules.ySize];
            var isContinental      = new bool[2 * rules.xHalfSize, rules.ySize];
            var continentalBuildup = new int[2 * rules.xHalfSize, rules.ySize];
            var continentalRecency = new int[2 * rules.xHalfSize, rules.ySize];
            var oceanicBuildup     = new int[2 * rules.xHalfSize, rules.ySize];
            var oceanicRecency     = new int[2 * rules.xHalfSize, rules.ySize];

            for (int x = 0; x < 2 * rules.xHalfSize; x++)
            {
                for (int y = 0; y < rules.ySize; y++)
                {
                    plateNumbers[x, y]       = pointData[x, y].PlateNumber;
                    xBirthPlace[x, y]        = pointData[x, y]._birthPlace.X;
                    yBirthPlace[x, y]        = pointData[x, y]._birthPlace.Y;
                    birthDate[x, y]          = pointData[x, y]._birthDate;
                    isContinental[x, y]      = pointData[x, y].IsContinental;
                    continentalBuildup[x, y] = pointData[x, y].History.ContinentalBuildup;
                    continentalRecency[x, y] = pointData[x, y].History.ContinentalRecency;
                    oceanicBuildup[x, y]     = pointData[x, y].History.OceanicBuildup;
                    oceanicRecency[x, y]     = pointData[x, y].History.OceanicRecency;
                }
            }
            CheapBinaryIO.Write(fileName + plateNumberExtension, plateNumbers, rules.plateCount);
            CheapBinaryIO.Write(fileName + xBirthPlaceExtension, xBirthPlace, 2 * rules.xHalfSize);
            CheapBinaryIO.Write(fileName + yBirthPlaceExtension, yBirthPlace, rules.ySize);
            CheapBinaryIO.Write(fileName + birthTimeExtension, birthDate, rules.ySize);
            CheapBinaryIO.WriteBinary(fileName + isContinentalExtension, isContinental);
            CheapBinaryIO.Write(fileName + continentalBuildupExtension, continentalBuildup, rules.maxBuildup);
            CheapBinaryIO.Write(fileName + continentalRecencyExtension, continentalRecency, rules.currentTime);
            CheapBinaryIO.Write(fileName + oceanicBuildupExtension, oceanicBuildup, rules.maxBuildup);
            CheapBinaryIO.Write(fileName + oceanicRecencyExtension, oceanicRecency, rules.currentTime);
        }
Beispiel #4
0
        /// <summary>
        /// Opens point data located at given file.
        /// </summary>
        /// <param name="fileName">File to open.</param>
        /// <param name="rules">Rules for how data will be read.</param>
        /// <returns>Data to output.</returns>
        /// <exception cref="InvalidDataException">File is not formatted correctly.</exception>
        /// <exception cref="FileNotFoundException">File could not be found.</exception>
        public static PlatePoint[,] OpenPointData(string fileName, GeneralRules rules)
        {
            var pointData = new PlatePoint[2 * rules.xHalfSize, rules.ySize];

            try
            {
                var plateNumbers       = CheapBinaryIO.Read(fileName + plateNumberExtension, rules.plateCount, 2 * rules.xHalfSize, rules.ySize);
                var isContinental      = CheapBinaryIO.ReadBinary(fileName + isContinentalExtension, 2 * rules.xHalfSize, rules.ySize);
                var birthTime          = CheapBinaryIO.Read(fileName + birthTimeExtension, rules.currentTime, 2 * rules.xHalfSize, rules.ySize);
                var xBirthPlace        = CheapBinaryIO.Read(fileName + xBirthPlaceExtension, 2 * rules.xHalfSize, 2 * rules.xHalfSize, rules.ySize);
                var yBirthPlace        = CheapBinaryIO.Read(fileName + yBirthPlaceExtension, rules.ySize, 2 * rules.xHalfSize, rules.ySize);
                var continentalBuildup = CheapBinaryIO.Read(fileName + continentalBuildupExtension, rules.maxBuildup, 2 * rules.xHalfSize, rules.ySize);
                var continentalRecency = CheapBinaryIO.Read(fileName + continentalRecencyExtension, rules.currentTime, 2 * rules.xHalfSize, rules.ySize);
                var oceanicBuildup     = CheapBinaryIO.Read(fileName + oceanicBuildupExtension, rules.maxBuildup, 2 * rules.xHalfSize, rules.ySize);
                var oceanicRecency     = CheapBinaryIO.Read(fileName + oceanicRecencyExtension, rules.currentTime, 2 * rules.xHalfSize, rules.ySize);

                for (int x = 0; x < 2 * rules.xHalfSize; x++)
                {
                    for (int y = 0; y < rules.ySize; y++)
                    {
                        var point      = new KeyPoint(x, y);
                        var birthPoint = new KeyPoint(xBirthPlace[x, y], yBirthPlace[x, y]);
                        var history    = new BoundaryHistory(continentalBuildup[x, y], continentalRecency[x, y], oceanicBuildup[x, y], oceanicRecency[x, y]);
                        pointData[x, y] = new PlatePoint(point, birthPoint, birthTime[x, y], plateNumbers[x, y], history, isContinental[x, y]);
                    }
                }
                return(pointData);
            }
            catch (FileNotFoundException e)
            {
                throw new FileNotFoundException("Data file missing. Can't find: " + e.Message, e.InnerException);
            }
            catch (Exception e) when(e is NullReferenceException || e is EndOfStreamException)
            {
                throw new InvalidDataException("Data file not formatted correctly. See: " + e.Message, e.InnerException);
            }
        }