Exemplo n.º 1
0
 public Renderer(_3DNode cameraCenter, int scale, int renderThreads)
 {
     this.camera       = Functions._3DNodeToVector(cameraCenter).Scale(scale * earthRadius);
     this.renderCenter = cameraCenter;
     this.scale        = scale;
     this.threads      = renderThreads;
 }
Exemplo n.º 2
0
        private void tile_MouseMove(object sender, MouseEventArgs e)
        {
            Point currentWindowLocation = new Point(Cursor.Position.X - this.Location.X, Cursor.Position.Y - this.Location.Y);
            Point currentMapLocation    = new Point(currentWindowLocation.X - ((PictureBox)sender).Parent.Left - 8, currentWindowLocation.Y - ((PictureBox)sender).Parent.Top - 32);

            toolStripStatusLabel3.Text = string.Format("| Mouseposition Window x,y: {0}, {1} | Mouseposition Map x,y: {2}, {3}", currentWindowLocation.X, currentWindowLocation.Y, currentMapLocation.X, currentMapLocation.Y);

            //_3DNode mouseCoordinates = Functions._3DNodeFrom2DNode(new _2DNode(currentMapLocation.X, currentMapLocation.Y), center, scale);
            int     width            = ((PictureBox)sender).Parent.Width;
            int     height           = ((PictureBox)sender).Parent.Height;
            float   latdiff          = this.maxLat - this.minLat;
            float   londiff          = this.maxLon - this.minLon;
            _3DNode mouseCoordinates = new _3DNode(this.maxLat - (latdiff / height) * currentMapLocation.Y, this.minLon + (londiff / width) * currentMapLocation.X);

            toolStripStatusLabel4.Text = string.Format("| Lat: {0:##.#####################} Lng: {1:##.#####################}", mouseCoordinates.lat.ToString(), mouseCoordinates.lon.ToString());

            if (e.Button == MouseButtons.Left)
            {
                Cursor.Current = Cursors.Hand;
                ((PictureBox)sender).Parent.Left -= previousLocation.X - currentWindowLocation.X;
                ((PictureBox)sender).Parent.Top  -= previousLocation.Y - currentWindowLocation.Y;
                toolStripStatusLabel2.Text        = "X:" + ((PictureBox)sender).Parent.Left + ",Y:" + ((PictureBox)sender).Parent.Top;
            }
            else
            {
                Cursor.Current = Cursors.Default;
            }

            previousLocation = currentWindowLocation;
            this.Invalidate();
        }
Exemplo n.º 3
0
 public Renderer(Vector camera, _3DNode cameraCenter, int scale, int renderThreads)
 {
     this.camera       = camera;
     this.renderCenter = cameraCenter;
     this.scale        = scale;
     this.threads      = renderThreads;
 }
Exemplo n.º 4
0
 public Address(string country, string postcode, string cityname, string streetname, string housenumber, _3DNode position, ulong node)
 {
     this.steetname       = streetname;
     this.housenumber     = housenumber;
     this.postcode        = postcode;
     this.cityname        = cityname;
     this.country         = country;
     this.position        = position;
     this.assosciatedNode = node;
 }
Exemplo n.º 5
0
        public _2DNode GetCoordinatesFromCenter(_3DNode node)
        {
            Vector nodeVector = Functions._3DNodeToVector(node);

            //Intersection between line through node and camera-plane
            double factor = (Math.Pow(camera.x, 2) + Math.Pow(camera.y, 2) + Math.Pow(camera.z, 2)) /
                            (camera.x * nodeVector.x + camera.y * nodeVector.y + camera.z * nodeVector.z);
            Vector toLocation = nodeVector.Scale(factor).Subtract(camera);

            return(new _2DNode((float)toLocation.z, -(float)toLocation.y));
        }
Exemplo n.º 6
0
        public static Vector _3DNodeToVector(_3DNode node)
        {
            double radLon    = DegreesToRadians(node.lon);
            double radLat    = DegreesToRadians(node.lat);
            double cosRadLat = Math.Cos(radLat);

            //Camera Norm-Vector
            return(new Vector(
                       Math.Cos(radLon) * cosRadLat,
                       Math.Sin(radLat),
                       Math.Sin(radLon) * cosRadLat));
        }
Exemplo n.º 7
0
        private void MapMouseMove(object sender, MouseEventArgs e)
        {
            Point mouseCurrent2DPosition = new Point(Cursor.Position.X - this.Location.X - 8, Cursor.Position.Y - this.Location.Y - 32);

            if (e.Button.ToString().ToLower().Contains("left") && this.allowMovement)
            {
                Point locationDifference = new Point(mouseCurrent2DPosition.X - previousMouseLocation.X, mouseCurrent2DPosition.Y - previousMouseLocation.Y);
                this.pictureBox1.Location = new Point(this.pictureBox1.Location.X + locationDifference.X, this.pictureBox1.Location.Y + locationDifference.Y);
            }
            this.previousMouseLocation = mouseCurrent2DPosition;
            _3DNode mouseCurrent3DPosition = this.renderer.GetGeoCoordinatesForPosition(new _2DNode(e.X - (this.pictureBox1.Width / 2), this.pictureBox1.Height - e.Y - (this.pictureBox1.Height / 2)));

            this.mousePositionLabel.Text = string.Format("| Mouse: {0}, {1}", mouseCurrent3DPosition.lat, mouseCurrent3DPosition.lon);
        }
Exemplo n.º 8
0
        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (string info in File.ReadAllLines(folderBrowserDialog.SelectedPath + "\\information"))
                {
                    switch (info.Split(':')[0])
                    {
                    case "scale":
                        this.scale = Convert.ToInt32(info.Split(':')[1]);
                        break;

                    case "minlat":
                        this.minLat = Convert.ToSingle(info.Split(':')[1]);
                        break;

                    case "minlon":
                        this.minLon = Convert.ToSingle(info.Split(':')[1]);
                        break;

                    case "maxlat":
                        this.maxLat = Convert.ToSingle(info.Split(':')[1]);
                        break;

                    case "maxlon":
                        this.maxLon = Convert.ToSingle(info.Split(':')[1]);
                        break;
                    }
                }

                float latDiff = this.maxLat - this.minLat;
                float lonDiff = this.maxLon - this.minLon;
                this.center = new _3DNode(minLat + latDiff / 2, minLon + lonDiff / 2);

                this.DrawTiles(folderBrowserDialog.SelectedPath);
            }
        }
Exemplo n.º 9
0
        public static void DrawTiles(string path, string newPath, int tileSize, int scale)
        {
            const byte UNKNOWN = 0, NODE = 1, WAY = 2, READINGNODES = 1, NODEREAD = 0;
            byte       nodeType = UNKNOWN, state = NODEREAD;

            float minLat = float.MaxValue, maxLat = float.MinValue, minLon = float.MaxValue, maxLon = float.MinValue;

            XmlReaderSettings settings = new XmlReaderSettings()
            {
                IgnoreWhitespace = true
            };
            Hashtable nodes = new Hashtable();

            using (XmlReader reader = XmlReader.Create(path, settings))
            {
                reader.MoveToContent();
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.EndElement && reader.Depth == 1 && reader.Name == "node")
                    {
                        ulong id  = Convert.ToUInt64(reader.GetAttribute("id"));
                        float lon = Convert.ToSingle(reader.GetAttribute("lon").Replace(".", ","));
                        float lat = Convert.ToSingle(reader.GetAttribute("lat").Replace(".", ","));
                        nodes.Add(id, new _3DNode(lat, lon));
                        minLat = minLat < lat ? minLat : lat;
                        minLon = minLon < lon ? minLon : lon;
                        maxLat = maxLat > lat ? maxLat : lat;
                        maxLon = maxLon > lon ? maxLon : lon;
                    }
                }
            }
            float    latDiff     = maxLat - minLat;
            float    lonDiff     = maxLon - minLon;
            _3DNode  center      = new _3DNode(minLat + latDiff / 2, minLon + lonDiff / 2);
            Renderer renderer    = new Renderer(center, scale);
            _2DNode  topLeft     = renderer.GetCoordinatesFromCenter(new _3DNode(maxLat, minLon));
            _2DNode  bottomRight = renderer.GetCoordinatesFromCenter(new _3DNode(minLat, maxLon));
            float    xOffset     = -topLeft.X;
            float    yOffset     = -topLeft.Y;
            double   width       = bottomRight.X + xOffset;
            double   height      = bottomRight.Y + yOffset;
            int      yAmount     = (int)Math.Ceiling(height / tileSize);
            int      xAmount     = (int)Math.Ceiling(width / tileSize);

            Console.WriteLine("Top-Left\tx,y: {0}, {1}", topLeft.X, topLeft.Y);
            Console.WriteLine("Bottom-Right\tx,y: {0}, {1}", bottomRight.X, bottomRight.Y);
            Console.WriteLine("Height: {0}px => {2} Tiles \tWidth: {1}px => {3} Tiles", height, width, yAmount, xAmount);


            List <Line>[,] grid = new List <Line> [xAmount, yAmount];
            for (int x = 0; x < xAmount; x++)
            {
                for (int y = 0; y < yAmount; y++)
                {
                    grid[x, y] = new List <Line>();
                }
            }

            Hashtable pens = new Hashtable();

            foreach (string type in File.ReadAllLines("roadRender.txt"))
            {
                if (!type.StartsWith("//"))
                {
                    string key = type.Split(',')[0];
                    if (!pens.ContainsKey(key))
                    {
                        pens.Add(key, new Pen(Color.FromName(type.Split(',')[2]), Convert.ToInt32(type.Split(',')[1])));
                    }
                }
            }

            using (XmlReader reader = XmlReader.Create(path, settings))
            {
                List <ulong> currentNodes = new List <ulong>();
                Dictionary <string, string> currentTags = new Dictionary <string, string>();
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.EndElement)
                    {
                        if (reader.Depth == 1)
                        {
                            if (state == READINGNODES && nodeType == WAY)
                            {
                                state = NODEREAD;
                                if (currentTags.ContainsKey("highway"))
                                {
                                    Pen pen = (Pen)pens[(string)currentTags["highway"]];
                                    if (pen == null)
                                    {
                                        pen = (Pen)pens["default"];
                                    }
                                    for (int i = 1; i < currentNodes.Count; i++)
                                    {
                                        _2DNode _2dfrom = renderer.GetCoordinatesFromCenter((_3DNode)nodes[currentNodes[i - 1]]);
                                        _2DNode _2dto   = renderer.GetCoordinatesFromCenter((_3DNode)nodes[currentNodes[i]]);
                                        //Console.WriteLine("FROM X  {0:0000000.00} + {1:0000000.00} => {2:0000000.00}\t\tY  {3:0000000.00} + {4:0000000.00} => {5:0000000.00}", _2dfrom.X, xOffset, _2dfrom.X + xOffset, _2dfrom.Y, yOffset, _2dfrom.Y + yOffset);
                                        //Console.WriteLine("TO   X  {0:0000000.00} + {1:0000000.00} => {2:0000000.00}\t\tY  {3:0000000.00} + {4:0000000.00} => {5:0000000.00}", _2dto.X, xOffset, _2dto.X + xOffset, _2dto.Y, yOffset, _2dto.Y + yOffset);
                                        int minX = _2dfrom.X < _2dto.X ? (int)Math.Floor((_2dfrom.X + xOffset) / tileSize) : (int)Math.Floor((_2dto.X + xOffset) / tileSize);
                                        int maxX = _2dfrom.X > _2dto.X ? (int)Math.Floor((_2dfrom.X + xOffset) / tileSize) : (int)Math.Floor((_2dto.X + xOffset) / tileSize);
                                        int minY = _2dfrom.Y < _2dto.Y ? (int)Math.Floor((_2dfrom.Y + yOffset) / tileSize) : (int)Math.Floor((_2dto.Y + yOffset) / tileSize);
                                        int maxY = _2dfrom.Y > _2dto.Y ? (int)Math.Floor((_2dfrom.Y + yOffset) / tileSize) : (int)Math.Floor((_2dto.Y + yOffset) / tileSize);
                                        for (int x = minX; x <= maxX; x++)
                                        {
                                            for (int y = minY; y <= maxY; y++)
                                            {
                                                if (x >= 0 && x < grid.GetLength(0) && y >= 0 && y < grid.GetLength(1))
                                                {
                                                    grid[x, y].Add(new Line(pen, _2dfrom, _2dto));
                                                }
                                            }
                                        }
                                    }
                                }

                                /*else if (tags.ContainsKey("addr:housenumber") && !neededNodesIds.Contains(currentNodes[0]))
                                 * {
                                 *  //Addresses?
                                 * }*/
                                /*foreach (string key in tags.Keys)
                                 * {
                                 *  //Streetnames?
                                 * }*/
                            }
                            switch (reader.Name)
                            {
                            case "node":
                                nodeType = NODE;
                                break;

                            case "way":
                                currentNodes.Clear();
                                currentTags.Clear();
                                nodeType = WAY;
                                break;

                            default:
                                nodeType = UNKNOWN;
                                break;
                            }
                        }
                        else if (reader.Depth == 2 && nodeType == WAY)
                        {
                            state = READINGNODES;
                            switch (reader.Name)
                            {
                            case "nd":
                                currentNodes.Add(Convert.ToUInt64(reader.GetAttribute("ref")));
                                break;

                            case "tag":
                                currentTags.Add(reader.GetAttribute("k"), reader.GetAttribute("v"));
                                break;
                            }
                        }
                    }
                }
            }

            Directory.CreateDirectory(newPath);
            File.Copy(path, newPath + "map.osm", true);
            File.WriteAllLines(newPath + "information", new string[] {
                "scale:" + scale.ToString(),
                "minlat:" + minLat.ToString(),
                "maxlat:" + maxLat.ToString(),
                "minlon:" + minLon.ToString(),
                "maxlon:" + maxLon.ToString()
            });
            for (int x = 0; x < xAmount; x++)
            {
                Directory.CreateDirectory(newPath + "\\" + x);
                for (int y = 0; y < yAmount; y++)
                {
                    using (Bitmap bmp = new Bitmap(tileSize, tileSize))
                    {
                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            foreach (Line line in grid[x, y])
                            {
                                float  tileOffsetX = tileSize * x;
                                float  tileOffsetY = tileSize * y;
                                PointF pointFrom   = new PointF(line.from.X + xOffset - tileOffsetX, line.from.Y + yOffset - tileOffsetY);
                                PointF pointTo     = new PointF(line.to.X + xOffset - tileOffsetX, line.to.Y + yOffset - tileOffsetY);
                                g.FillEllipse(new SolidBrush(line.pen.Color), pointFrom.X - line.pen.Width / 2, pointFrom.Y - line.pen.Width / 2, line.pen.Width, line.pen.Width);
                                g.DrawLine(line.pen, pointFrom, pointTo);
                                g.FillEllipse(new SolidBrush(line.pen.Color), pointTo.X - line.pen.Width / 2, pointTo.Y - line.pen.Width / 2, line.pen.Width, line.pen.Width);
                            }
                        }
                        bmp.Save(newPath + "\\" + x + "\\" + y + ".png", System.Drawing.Imaging.ImageFormat.Png);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public static double DistanceBetweenNodes(_3DNode node1, _3DNode node2)
 {
     return(DistanceBetweenCoordinates(node1.lat, node1.lon, node2.lat, node2.lon));
 }
Exemplo n.º 11
0
        private static void DrawMap()
        {
            Console.WriteLine("Path to .osm file (E:\\Desktop\\map.osm)");
            string path = Console.ReadLine();

            Console.WriteLine("Outputfile (E:\\Desktop\\render.png");
            string outputFilePath = Console.ReadLine();

            Console.WriteLine("Scale (200)");
            int scale = Convert.ToInt32(Console.ReadLine());


            Importer importer = new Importer();

            importer.OnProgress += (s, e) =>
            {
                string progressString = string.Format("{0:#0.00}%", e.progress);
                int    consoleLeft = Console.CursorLeft, consoleTop = Console.CursorTop;
                Console.SetCursorPosition(Console.WindowWidth - progressString.Length, consoleTop);
                Console.WriteLine(progressString);
                Console.SetCursorPosition(consoleLeft, consoleTop);
            };
            importer.OnStatusChange += (s, e) =>
            {
                Console.WriteLine(e.status);
            };
            Graph   mapGraph     = importer.ImportOSM(path);
            _3DNode renderCenter = new _3DNode(mapGraph.minLat + (mapGraph.maxLat - mapGraph.minLat) / 2, mapGraph.minLon + (mapGraph.maxLon - mapGraph.minLon) / 2);

            Hashtable pens = new Hashtable();

            foreach (string type in File.ReadAllLines("roadRender.txt"))
            {
                if (!type.StartsWith("//"))
                {
                    string key = type.Split(',')[0];
                    if (!pens.ContainsKey(key))
                    {
                        pens.Add(key, new Pen(Color.FromName(type.Split(',')[2]), Convert.ToInt32(type.Split(',')[1])));
                    }
                }
            }

            int coreCount = 0;

            foreach (ManagementObject result in new ManagementObjectSearcher("Select * from Win32_Processor").Get())
            {
                coreCount += int.Parse(result["NumberOfCores"].ToString());
            }

            Renderer renderer = new Renderer(renderCenter, scale);

            _2DNode topLeft     = renderer.GetCoordinatesFromCenter(new _3DNode(mapGraph.maxLat, mapGraph.minLon));
            _2DNode bottomRight = renderer.GetCoordinatesFromCenter(new _3DNode(mapGraph.minLat, mapGraph.maxLon));
            int     width       = (int)(bottomRight.X - topLeft.X);
            int     height      = (int)(bottomRight.Y - topLeft.Y);

            Bitmap render = renderer.DrawMap(mapGraph, renderCenter, pens, width, height, coreCount);

            render.Save(outputFilePath);
        }