Esempio n. 1
0
        static void DrawTest(OsmNode[] nodes, List <GpsLine> polyLines, GpsStripe[] stripes)
        {
            const int Height  = 800;
            const int Padding = 10;

            var points = nodes.Select(node => new PointXY(node)).ToArray();
            int minX   = points.Min(p => p.x);
            int maxX   = points.Max(p => p.x);
            int minY   = points.Min(p => p.y);
            int maxY   = points.Max(p => p.y);

            double distX = GpsDistance((minY + (maxY - minY) / 2) / 10000000.0, minX / 10000000.0, (minY + (maxY - minY) / 2) / 10000000.0, maxX / 10000000.0);
            double distY = GpsDistance(minY / 10000000.0, 0, maxY / 10000000.0, 0);

            int width = (int)((Height - Padding - Padding) / distY * distX) + Padding + Padding;

            var    pic  = new Bitmap(width, Height, PixelFormat.Format32bppRgb);
            double mulX = (width - Padding - Padding) / (double)(maxX - minX);
            double mulY = (Height - Padding - Padding) / (double)(maxY - minY);

            var g = Graphics.FromImage(pic);

            //g.FillPolygon(new SolidBrush(Color.FromArgb(0x0080ff - 16777216)), points.Select(p => new Point((int)((p.x - minX) * mulX) + Padding, Height - (int)((p.y - minY) * mulY) - Padding)).ToArray());
            g.DrawPolygon(new Pen(Color.FromArgb(0x0080ff - 16777216)), points.Select(p => new Point((int)((p.x - minX) * mulX) + Padding, Height - (int)((p.y - minY) * mulY) - Padding)).ToArray());

            //ViewPicture(pic, nodes.Length.ToString("N0") + " Lines");

            long bestTicks = long.MaxValue;

            for (int i = 0; i < 10; i++)
            {
                var time = Stopwatch.StartNew();
                ScanTest(stripes, width, minX, mulX, Height, Padding, mulY, minY);
                time.Stop();
                if (time.ElapsedTicks < bestTicks)
                {
                    bestTicks = time.ElapsedTicks;
                }
            }

            g.DrawString("time: " + (bestTicks * 1000.0 / Stopwatch.Frequency).ToString("N2") + " ms", new Font("Arial", 24), new SolidBrush(Color.White), 10, 10);

            ViewPicture(pic, nodes.Length.ToString("N0") + " Lines", (form, x, y) =>
            {
                long latCode = (long)((Height - y - Padding) / mulY) + minY;
                long lonCode = (long)((x - Padding) / mulX) + minX;
                var posCode  = new GpsPos((uint)(ulong)lonCode + 1800000000u, 900000000u - (uint)(ulong)latCode);

                int collisions = ScanCollisions(stripes, posCode);

                string txt = "lat: " + (latCode / 10000000.0).ToString("N5") + ", lon: " + (lonCode / 10000000.0).ToString("N5") + ", colli: " + collisions + (collisions % 2 == 1 ? " #####" : "");

                //File.AppendAllText(@"C:\Users\Max\Desktop\prog\vacaVista\dummytest\log.txt", txt + "\r\n");

                form.Text = txt;
            });
        }
Esempio n. 2
0
 void PositionChanged(object sender, PositionEventArgs e)
 {
     lock (syncRoot)
     {
         GpsPos = e.Position;
         // We don't receive elevation and position simultaneously, so
         // take the last known elevation.
         AddPosSample(new Position3D(Elevation, e.Position));
     }
     Debug.WriteLine("Position changed: " + GpsPos.ToString());
     NotifyOfGpsDataUpdate();
 }
Esempio n. 3
0
        static int ScanTest(GpsStripe[] stripes, int width, int minX, double mulX, int Height, int Padding, double mulY, int minY)
        {
            int filled = 0;

            for (int y = 0; y < Height; y++)
            {
                long latCode = (long)((Height - y - Padding) / mulY) + minY;
                var  posCode = new GpsPos(0, 900000000u - (uint)(ulong)latCode);
                for (int x = 0; x < width; x++)
                {
                    long lonCode = (long)((x - Padding) / mulX) + minX;
                    posCode.posX = (uint)(ulong)lonCode + 1800000000u;

                    int collisions = ScanCollisions(stripes, posCode);
                    if ((collisions & 1) == 1)
                    {
                        filled++;
                    }
                }
            }
            return(filled);
        }
Esempio n. 4
0
        static int ScanCollisions(GpsStripe[] stripes, GpsPos gpsPos)
        {
            if (gpsPos.posY < stripes[0].startY || gpsPos.posY > stripes[stripes.Length - 1].startY)
            {
                return(0);
            }

            int start = 0;
            int end   = stripes.Length;

            do
            {
                var center = (start + end) >> 1;
                if (gpsPos.posY < stripes[center].startY)
                {
                    end = center;
                }
                else
                {
                    start = center;
                }
            } while (end - start > 1);

            int collisions = 0;

            if (gpsPos.posY >= stripes[start].startY && gpsPos.posY <= stripes[start].endY)
            {
                foreach (var line in stripes[start].lines)
                {
                    if (CheckPoint(gpsPos.posX, gpsPos.posY, line.pos1.posX, line.pos1.posY, line.pos2.posX, line.pos2.posY))
                    {
                        collisions++;
                    }
                }
            }

            return(collisions);
        }
Esempio n. 5
0
        static void ConverterTest_1_ExtractNodes()
        {
            Directory.CreateDirectory("../tmp");
            using (var wdatRaw = File.Create("../tmp/node_rawfull.dat"))
                using (var wdatRawIndex = File.Create("../tmp/node_rawfull_index.dat"))
                    using (var pbf = new OsmPbfReader(PbfPath))
                    {
                        long cc = 0;

                        var  rawBuf = new byte[4096];
                        int  rawLen = 0;
                        long rawId  = 0;
                        long rawPos = 0;

                        var  buf     = new byte[2000 * 1048576];
                        int  len     = 0;
                        long lastId  = 0;
                        long lastPos = 0;
                        int  block   = 0;

                        long totalPos = 0;
                        long totalSum = pbf.nodeIndex.Sum(x => x.nodeCount);

                        wdatRawIndex.Write(BitConverter.GetBytes(0L), 0, sizeof(long));
                        wdatRawIndex.Write(BitConverter.GetBytes(0L), 0, sizeof(long));
                        foreach (var node in pbf.ReadAllNodes())
                        {
                            totalPos++;
                            var gpsPos = new GpsPos(node);

                            rawLen += ProtoBuf.WriteVarInt(rawBuf, rawLen, ProtoBuf.UnsignedInt64(node.id - rawId));
                            rawId   = node.id;
                            long nextFullPos = gpsPos.Int64Pos;
                            rawLen += ProtoBuf.WriteVarInt(rawBuf, rawLen, ProtoBuf.UnsignedInt64(nextFullPos - rawPos));
                            rawPos  = nextFullPos;

                            if (rawLen > rawBuf.Length - 18)
                            {
                                while (rawLen < rawBuf.Length)
                                {
                                    rawBuf[rawLen++] = 0;
                                }
                                wdatRaw.Write(rawBuf, 0, rawBuf.Length);
                                wdatRawIndex.Write(BitConverter.GetBytes(rawId + 1), 0, sizeof(long));
                                wdatRawIndex.Write(BitConverter.GetBytes(wdatRaw.Length), 0, sizeof(long));
                                rawLen = 0;
                                rawId  = 0;
                                rawPos = 0;
                            }

                            //todo
                            //if (node.values.Length > 0)
                            //{
                            //  cc++;
                            //  if ((ushort)cc == 0) Console.WriteLine(cc.ToString("N0") + " (" + (100.0 / totalSum * totalPos).ToString("N2") + " %) - " + (len / 1048576.0).ToString("N1") + " MByte / " + (wdatRaw.Length / 1048576.0).ToString("N1") + " MByte");
                            //  len += ProtoBuf.WriteVarInt(buf, len, ProtoBuf.UnsignedInt64(node.id - lastId));
                            //  lastId = node.id;
                            //  long nextPos = gpsPos.Int64Pos;
                            //  len += ProtoBuf.WriteVarInt(buf, len, ProtoBuf.UnsignedInt64(nextPos - lastPos));
                            //  lastPos = nextPos;
                            //  len += ProtoBuf.WriteVarInt(buf, len, (uint)node.values.Length);
                            //  foreach (var v in node.values)
                            //  {
                            //    len += ProtoBuf.WriteString(buf, len, v.Key);
                            //    len += ProtoBuf.WriteString(buf, len, v.Value);
                            //  }
                            //  if (len > buf.Length - 65536)
                            //  {
                            //    block++;
                            //    using (var wdat = File.Create("../tmp/node_block_" + block + "_" + lastId + ".dat"))
                            //    {
                            //      wdat.Write(buf, 0, len);
                            //      len = 0;
                            //      lastId = 0;
                            //      lastPos = 0;
                            //    }
                            //  }
                            //}
                        }
                        if (rawLen > 0)
                        {
                            while (rawLen < rawBuf.Length)
                            {
                                rawBuf[rawLen++] = 0;
                            }
                            wdatRaw.Write(rawBuf, 0, rawBuf.Length);
                        }
                        if (len > 0)
                        {
                            block++;
                            using (var wdat = File.Create("../tmp/node_block_" + block + "_" + lastId + ".dat"))
                            {
                                wdat.Write(buf, 0, len);
                            }
                        }

                        //foreach (var way in pbf.ReadAllWays())
                        //{
                        //  Console.WriteLine(way);
                        //}
                        //foreach (var relation in pbf.ReadAllRelations())
                        //{
                        //  cc++;
                        //  if ((byte)cc == 0)
                        //  {
                        //    Console.WriteLine(cc.ToString("N0") + " - " + relation);
                        //  }
                        //}
                    }
        }
Esempio n. 6
0
 public GpsLine(GpsPos pos1, GpsPos pos2)
 {
     this.pos1 = pos1;
     this.pos2 = pos2;
 }