// load the map (terrain parameters) from the given file
        public void LoadTerrain(string filename)
        {
            if (filename != null)
            {
                // remember the filename
                mapFilename = filename;

                ReadSavedMap(filename);

                Text = "TerrainGenerator: " + filename;

                if (terrainGenerator.SeedMap != null)
                {
                    editableHeightField = new EditableHeightField(terrainGenerator.SeedMap,
                                                                  terrainGenerator.SeedMapWidth,
                                                                  terrainGenerator.SeedMapHeight);
                    editableHeightField.YScale = terrainGenerator.HeightScale * oneMeter;
                    editableHeightField.XZScale = SeedMapMetersPerSample * oneMeter;
                    editableHeightField.OffsetX = SeedMapOriginX * oneMeter;
                    editableHeightField.OffsetZ = SeedMapOriginZ * oneMeter;

                    SeedMapLoaded = true;
                    UseSeedMap = AlgorithmUsesSeedMap();
                }
                else
                {
                    editableHeightField = null;
                }

                InitControlValues();
                InitHeightFieldEditorControlValues();

                fractalParamChanged = true;
            }
        }
        public void NewSeedMap(int w, int h, float defHeight, int mps, bool centered)
        {
            SeedMapMetersPerSample = mps;
            if (centered)
            {
                SeedMapOriginX = -w * mps / 2;
                SeedMapOriginZ = -h * mps / 2;
            }

            editableHeightField = new EditableHeightField(w, h, defHeight);
            editableHeightField.YScale = terrainGenerator.HeightScale * oneMeter;
            editableHeightField.XZScale = SeedMapMetersPerSample * oneMeter;
            editableHeightField.OffsetX = SeedMapOriginX * oneMeter;
            editableHeightField.OffsetZ = SeedMapOriginZ * oneMeter;

            terrainGenerator.BitsPerSample = 16;
            terrainGenerator.SetSeedMap(editableHeightField.Map, editableHeightField.Width, editableHeightField.Height);
            SeedMapLoaded = true;
            UseSeedMap = true;

            InitHeightFieldEditorControlValues();
        }
        private void loadSeedMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Open Seed Map File";
            dlg.Filter = "Seed Files (*.csv)|*.csv|PNG files (*.png)|*.png|All files (*.*)|*.*";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string filename = dlg.FileName;
                // terrainGenerator.LoadSeedMap(filename);

                int bitsPerSampleRead;
                editableHeightField = new EditableHeightField(filename, out bitsPerSampleRead);
                editableHeightField.YScale = terrainGenerator.HeightScale * oneMeter;
                editableHeightField.XZScale = SeedMapMetersPerSample * oneMeter;
                editableHeightField.OffsetX = SeedMapOriginX * oneMeter;
                editableHeightField.OffsetZ = SeedMapOriginZ * oneMeter;

                terrainGenerator.BitsPerSample = bitsPerSampleRead;
                terrainGenerator.SetSeedMap(editableHeightField.Map, editableHeightField.Width, editableHeightField.Height);
                SeedMapLoaded = true;

                InitHeightFieldEditorControlValues();
            }
            dlg.Dispose();
        }