public static HeightMap Load(string path)
{
HeightMap map = new HeightMap();
XmlReader r = XmlReader.Create(path);
while (r.Read())
{
if (!r.IsStartElement())
continue;
switch (r.Name)
{
case "heightmap":
map.Min = new Vector2(double.Parse(r["MinX"], Constants.DecimalParseFormat), double.Parse(r["MinY"], Constants.DecimalParseFormat));
map.Max = new Vector2(double.Parse(r["MaxX"], Constants.DecimalParseFormat), double.Parse(r["MaxY"], Constants.DecimalParseFormat));
map.SizeX = int.Parse(r["SizeX"]);
map.SizeY = int.Parse(r["SizeY"]);
map.Points = new double?[map.SizeX, map.SizeY];
break;
case "point":
int x = int.Parse(r["X"]), y = int.Parse(r["Y"]);
double height = double.Parse(r.ReadInnerXml(), Constants.DecimalParseFormat);
map.Points[x, y] = height;
if (height > map.MaxHeight)
map.MaxHeight = height;
if (height < map.MinHeight)
map.MinHeight = height;
break;
}
}
r.Dispose();
for (int x = 0; x < map.SizeX; x++)
{
for (int y = 0; y < map.SizeY; y++)
if (!map.Points[x, y].HasValue)
map.NotProbed.Enqueue(new Tuple<int, int>(x, y));
if (++x >= map.SizeX)
break;
for (int y = map.SizeY - 1; y >= 0; y--)
if (!map.Points[x, y].HasValue)
map.NotProbed.Enqueue(new Tuple<int, int>(x, y));
}
return map;
}