/// <summary> /// Create the grid with rectangluar cells /// </summary> /// <param name="mapmeta"></param> private static void BuildMapGrid(MapMetaData mapmeta) { PosX = PosX = (int)mapmeta.CoordOriginX; PosY = PosY = (int)mapmeta.CoordOriginY; MapWidth = (int)mapmeta.Width; MapHeight = (int)mapmeta.Height; CellEdgeLength = (int)Math.Ceiling((double)MapWidth / Cellamount); var currentx = PosX; var currenty = PosY; var cells = (MapHeight / CellEdgeLength) * (MapWidth / CellEdgeLength); MapGrid = new MapGridCell[MapHeight / CellEdgeLength][]; for (int k = 0; k < MapGrid.Length; k++) { MapGrid[k] = new MapGridCell[MapWidth / CellEdgeLength]; for (int l = 0; l < MapGrid[k].Length; l++) { MapGrid[k][l] = new MapGridCell { Index_X = k, Index_Y = l, Bounds = new Rectangle2D(new Point2D(currentx, currenty), CellEdgeLength, CellEdgeLength), Blocked = false }; currentx += CellEdgeLength; } currentx = PosX; currenty -= CellEdgeLength; } }
/// <summary> /// Reads a map info file "<mapname>".txt and extracts the relevant data about the map /// </summary> /// <param name="path"></param> public static MapMetaData ReadProperties(string path) { string line; var fmt = new NumberFormatInfo(); fmt.NegativeSign = "-"; MapMetaData metadata = new MapMetaData(); using (var file = new StreamReader(path)) { while ((line = file.ReadLine()) != null) { var resultString = Regex.Match(line, @"-?\d+").Value; //Match negative and positive int numbers if (line.Contains("pos_x")) { metadata.CoordOriginX = double.Parse(resultString, fmt); } else if (line.Contains("pos_y")) { metadata.CoordOriginY = double.Parse(resultString, fmt); } else if (line.Contains("scale")) { metadata.scale = Double.Parse(resultString); } else if (line.Contains("rotate")) { metadata.rotate = Int32.Parse(resultString); } else if (line.Contains("zoom")) { metadata.zoom = Double.Parse(resultString); } else if (line.Contains("width")) { metadata.Width = double.Parse(resultString, fmt); } else if (line.Contains("height")) { metadata.Height = double.Parse(resultString, fmt); } } file.Close(); } return(metadata); }
/// <summary> /// This function takes a list of all registered points on the map and tries to /// reconstruct a polygonal represenatation of the map with serveral levels /// </summary> /// <param name="ps"></param> public static Map CreateMap(MapMetaData mapmeta, List <Point3D> ps) { PosX = (int)mapmeta.CoordOriginX; PosY = (int)mapmeta.CoordOriginY; MapWidth = (int)mapmeta.Width; MapHeight = (int)mapmeta.Height; CellEdgeLength = (int)Math.Ceiling((double)MapWidth / Cellamount); var currentx = PosX; var currenty = PosY; var cells = (MapHeight / CellEdgeLength) * (MapWidth / CellEdgeLength); MapGrid = new MapGridCell[MapHeight / CellEdgeLength][]; for (int k = 0; k < MapGrid.Length; k++) { MapGrid[k] = new MapGridCell[MapWidth / CellEdgeLength]; for (int l = 0; l < MapGrid[k].Length; l++) { MapGrid[k][l] = new MapGridCell { Index_X = k, Index_Y = l, Bounds = new Rectangle2D(new Point2D(currentx, currenty), CellEdgeLength, CellEdgeLength), Blocked = false }; currentx += CellEdgeLength; } currentx = PosX; currenty -= CellEdgeLength; } // Create the map levels MapLevel[] maplevels = CreateMapLevels(ps); var map_width_x = ps.Max(point => point.X) - ps.Min(point => point.X); var map_width_y = ps.Max(point => point.Y) - ps.Min(point => point.Y); Console.WriteLine("Max x: " + ps.Max(point => point.X) + " Min x: " + ps.Min(point => point.X)); Console.WriteLine("Mapwidth in x-Range: " + map_width_x + " Mapwidth in y-Range: " + map_width_y); return(new Map(map_width_x, map_width_y, maplevels)); }
/// <summary> /// This function takes a list of all registered points on the map and tries to /// reconstruct a polygonal represenatation of the map with serveral levels /// </summary> /// <param name="ps"></param> public static Map CreateMap(MapMetaData mapmeta, List <Point3D> ps) { BuildMapGrid(mapmeta); var min_z = ps.Min(point => point.Z); var max_z = ps.Max(point => point.Z); var maplevel = new MapLevel(0, min_z, max_z); AssignCellTypes(maplevel, ps.ToArray()); MapLevel[] maplevels = new MapLevel[] { maplevel }; // This constructor only creates one maplevel var map_width_x = ps.Max(point => point.X) - ps.Min(point => point.X); var map_width_y = ps.Max(point => point.Y) - ps.Min(point => point.Y); Console.WriteLine("Mapwidth in x-Range: " + map_width_x + " Mapwidth in y-Range: " + map_width_y); return(new Map(map_width_x, map_width_y, maplevels)); }