Exemplo n.º 1
0
        private void btnTileInfo_Click(object sender, EventArgs e)
        {
            Vector3[] v3 = new Vector3[5];

            // python demo data in ECEF coordinates
            v3[0] = new Vector3(4480363.47619142, 580530.98724711, 4487574.82445706);
            v3[1] = new Vector3(4507665.32245697, 584068.55018155, 4459851.33224541);
            v3[2] = new Vector3(4492226.98875439, 596087.14785771, 4473732.87770479);
            v3[3] = new Vector3(4504029.82280181, 611720.56972904, 4459884.3617184);
            v3[4] = new Vector3(4476724.14024925, 608012.01353714, 4487581.96623555);


            TileInfo tf  = new TileInfo();
            var      hdr = tf.CalculateHeaderInfo(ref v3, false);
            var      hop = HorizonOcclusionPoint.FromPoints(v3, tf.BoundingSphere);


// python demo      var hdr = tf.CalculateHeaderInfo(ref v3, false);

            listBox1.Items.Add($"Header Info CenterXYZ:{hdr.CenterX} , {hdr.CenterY}, {hdr.CenterZ}");
            listBox1.Items.Add($"Header Info HorizonOcclusionPoint: {hop.X} , {hop.Y} , {hop.Z}");
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        private ElevationData MakeTileDEM(LLBoundingBox bbox)
        {
            // Steps
            // Using bounding box get elevation data for tile
            // Calculate header info

            Vector3[]     ecefPoints;
            ElevationData ed = GetData(bbox, out ecefPoints);

            // Work out bounding sphere
            TileInfo tileInfo = new TileInfo();
            var      hdr      = tileInfo.CalculateHeaderInfo(ref ecefPoints, false);

            ed.CenterX = hdr.CenterX;
            ed.CenterY = hdr.CenterY;
            ed.CenterZ = hdr.CenterZ;
            ed.BoundingSphereCenterX = hdr.CenterX;
            ed.BoundingSphereCenterY = hdr.CenterY;
            ed.BoundingSphereCenterZ = hdr.CenterZ;
            ed.BoundingSphereRadius  = hdr.BoundingSphereRadius;

            // Work out HorizonOcclusionPoint
            var hop = HorizonOcclusionPoint.FromPoints(ecefPoints, tileInfo.BoundingSphere);

            ed.HorizonOcclusionPointX = hop.X;
            ed.HorizonOcclusionPointY = hop.Y;
            ed.HorizonOcclusionPointZ = hop.Z;

            /* Quicker cheat method untested
             * ed.HorizonOcclusionPointX = hdr.CenterX;
             * ed.HorizonOcclusionPointY = hdr.CenterY;
             * ed.HorizonOcclusionPointZ = maxElev;
             */

            // todo lighting

            return(ed);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compute all header info
        /// </summary>
        /// <returns></returns>
        private void ComputeHeaderInfo()
        {
            // Work out bounding sphere for Cesium tile
            TileInfo tileInfo   = new TileInfo();
            var      tileHeader = tileInfo.CalculateHeaderInfo(ref TileData.EcefPoints);

            TileData.CenterX = tileHeader.CenterX;
            TileData.CenterY = tileHeader.CenterY;
            TileData.CenterZ = tileHeader.CenterZ;
            TileData.BoundingSphereCenterX = tileHeader.CenterX;
            TileData.BoundingSphereCenterY = tileHeader.CenterY;
            TileData.BoundingSphereCenterZ = tileHeader.CenterZ;
            TileData.BoundingSphereRadius  = tileHeader.BoundingSphereRadius;

            // Work out tile HorizonOcclusionPoint
            var hop = HorizonOcclusionPoint.FromPoints(ref TileData.EcefPoints, tileInfo.BoundingSphere);

            TileData.HorizonOcclusionPointX = hop.X;
            TileData.HorizonOcclusionPointY = hop.Y;
            TileData.HorizonOcclusionPointZ = hop.Z;

            // If lighting is required add code here
        }
Exemplo n.º 4
0
        private void btnMyData_Click(object sender, EventArgs e)
        {
            // Array of Lat Long
            Vector3[] v3 = new Vector3[16];

            v3[0]  = new Vector3(7.3828125, 44.6484375, 303.3);
            v3[1]  = new Vector3(7.3828125, 45.0, 320.2);
            v3[2]  = new Vector3(7.5585937, 44.82421875, 310.2);
            v3[3]  = new Vector3(7.3828125, 44.6484375, 303.3);
            v3[4]  = new Vector3(7.3828125, 44.6484375, 303.3);
            v3[5]  = new Vector3(7.734375, 44.6484375, 350.3);
            v3[6]  = new Vector3(7.5585937, 44.82421875, 310.2);
            v3[7]  = new Vector3(7.3828125, 44.6484375, 303.3);
            v3[8]  = new Vector3(7.734375, 44.6484375, 350.3);
            v3[9]  = new Vector3(7.734375, 45.0, 330.3);
            v3[10] = new Vector3(7.5585937, 44.82421875, 310.2);
            v3[11] = new Vector3(7.734375, 44.6484375, 350.3);
            v3[12] = new Vector3(7.734375, 45.0, 330.3);
            v3[13] = new Vector3(7.5585937, 44.82421875, 310.2);
            v3[14] = new Vector3(7.3828125, 45.0, 320.2);
            v3[15] = new Vector3(7.734375, 45.0, 330.3);

            // Convert to ECEF coords
            Vector3[] points = new Vector3[5];
            for (int i = 0; i < 5; i++)
            {
                points[i] = Coord.geo_to_ecef(v3[i]);
            }

            // Now get tile header info
            TileInfo tf  = new TileInfo();
            var      hdr = tf.CalculateHeaderInfo(ref points, false);
            var      hop = HorizonOcclusionPoint.FromPoints(points, tf.BoundingSphere);

            listBox1.Items.Add($"Header Info CenterXYZ:{hdr.CenterX} , {hdr.CenterY}, {hdr.CenterZ}");
            listBox1.Items.Add($"Header Info HorizonOcclusionPoint: {hop.X} , {hop.Y} , {hop.Z}");
        }
Exemplo n.º 5
0
        /*
         * https://cesium.com/blog/2013/05/09/computing-the-horizon-occlusion-point/
         * private computeMagnitude(ellipsoid, position, scaledSpaceDirectionToPoint)
         * {
         * var scaledSpacePosition = ellipsoid.transformPositionToScaledSpace(position);
         * var magnitudeSquared = scaledSpacePosition.magnitudeSquared();
         * var magnitude = Math.sqrt(magnitudeSquared);
         * var direction = scaledSpacePosition.divideByScalar(magnitude);
         *
         * // For the purpose of this computation, points below the ellipsoid
         * // are considered to be on it instead.
         * magnitudeSquared = Math.max(1.0, magnitudeSquared);
         * magnitude = Math.max(1.0, magnitude);
         *
         * var cosAlpha = direction.dot(scaledSpaceDirectionToPoint);
         * var sinAlpha = direction.cross(scaledSpaceDirectionToPoint).magnitude();
         * var cosBeta = 1.0 / magnitude;
         * var sinBeta = Math.sqrt(magnitudeSquared - 1.0) * cosBeta;
         *
         * return 1.0 / (cosAlpha * cosBeta - sinAlpha * sinBeta);
         * }
         */

        /// <summary>
        /// By LatLon
        /// </summary>
        /// <param name="bb"></param>
        /// <returns></returns>
        private ElevationData MakeTileDEM(LLBoundingBox bb)
        {
            // todo we also need to comput header info for the quantized mesh


            Vector2 v;

            v.X = 0;
            v.Y = 0;
            int x2         = 0;
            int y2         = 0;
            int PixelCount = GridSize - 1;


            var DoRandom = false;
            int HgtMode  = 2;

            float minElev = float.PositiveInfinity;
            float maxElev = float.NegativeInfinity;

            Random rnd = new Random();

            ElevationData ed = new ElevationData(GridSize);

            var midPt = bb.GetCenter();
            //  var pt2 =  Coord.geo_to_ecef(new Vector3( MapUtil.Deg2Rad(midPt.Longitude), MapUtil.Deg2Rad(midPt.Latitude),0)); // zero elevation for now
            var pt = MapUtil.LatLonToEcef(midPt.Latitude, midPt.Longitude, 0); // zero elevation for now

            Vector3[] ecefPoints = new Vector3[GridSize * GridSize];

            try
            {
                // we are going to walk up from sw to ne for returning dem in latlon coordinates
                var yRange = bb.North - bb.South;
                var xRange = bb.East - bb.West;
                var xStep  = xRange / PixelCount;
                var yStep  = yRange / PixelCount;


                int   i   = 0;
                float hgt = 0;
                for (int y = 0; y < GridSize; y++)
                {
                    for (int x = 0; x < GridSize; x++)
                    {
                        var lat = bb.South + (y * yStep);
                        var lon = bb.West + (x * xStep);
                        v = MapProject(lat, lon); // MapProject is lat long


                        if (v.X >= Width)
                        {
                            v.X = Width - 1;
                        }
                        if (v.Y >= Depth)
                        {
                            v.Y = Depth - 1;
                        }
                        if (v.X < 0)
                        {
                            v.X = 0;
                        }
                        if (v.Y < 0)
                        {
                            v.Y = 0;
                        }

                        x2 = (int)v.X;
                        y2 = (int)v.Y;

                        //hgt = 0;
                        // if (i == 4)
                        //  hgt = 100;

                        if (HgtMode == 1)
                        {
                            ed.Elev[i] = rnd.Next(1, 8000);
                        }
                        else if (HgtMode == 2)
                        {
                            ed.Elev[i] = 0;
                            if (lat >= -43.548006 & lat <= -43.547679)
                            {
                                if (lon >= 172.632951 & lon <= 172.633542)
                                {
                                    ed.Elev[i] = (float)10.0;
                                }
                            }
                        }
                        else
                        {
                            hgt        = Map.GetPixel(x2, y2).GetBrightness(); // 0=black, 1= white
                            ed.Elev[i] = MapUtil.Lerp(0, 1, ElevMin, ElevMax, hgt);
                        }

                        if (ed.Elev[i] < minElev)
                        {
                            minElev = ed.Elev[i];
                        }

                        if (ed.Elev[i] > maxElev)
                        {
                            maxElev = ed.Elev[i];
                        }

                        // Make ecef point list for later calculations
                        ecefPoints[i] = Coord.geo_to_ecef(new Vector3()
                        {
                            X = MapUtil.Deg2Rad(lon), Y = MapUtil.Deg2Rad(lat), Z = ed.Elev[i]
                        });


                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine($"**** MakeTileDEM Exception ****:{ex} v:{v} x2{x2} y2{y2} ");
// file writer        System.Diagnostics.Trace.WriteLine($"**** MakeTileDEM Exception *********:{ex} v:{v} x2{x2} y2{y2} ");
#endif
            }

            // todo now make a ecfc array to calculate header info
            TileInfo tileInfo = new TileInfo();
            var      hdr      = tileInfo.CalculateHeaderInfo(ref ecefPoints, false);
            ed.CenterX = hdr.CenterX;
            ed.CenterY = hdr.CenterY;
            ed.CenterZ = hdr.CenterZ;
            ed.BoundingSphereCenterX = hdr.CenterX;
            ed.BoundingSphereCenterY = hdr.CenterY;
            ed.BoundingSphereCenterZ = hdr.CenterZ;
            ed.BoundingSphereRadius  = hdr.BoundingSphereRadius;
            ed.MaximumHeight         = maxElev;
            ed.MinimumHeight         = minElev;


            var hop = HorizonOcclusionPoint.FromPoints(ecefPoints, tileInfo.BoundingSphere);
            ed.HorizonOcclusionPointX = hop.X;
            ed.HorizonOcclusionPointY = hop.Y;
            ed.HorizonOcclusionPointZ = hop.Z;


            /*
             * // FIXME: is there a better choice for a horizon occlusion point?
             * // Currently it's the center of tile elevated to bbox's max Z
             * header.horizon_occlusion = c;
             * header.horizon_occlusion.z = bbox.max.z;
             *
             *
             * ed.HorizonOcclusionPointX = hdr.CenterX;
             * ed.HorizonOcclusionPointY = hdr.CenterY;
             * ed.HorizonOcclusionPointZ = maxElev;
             */
            return(ed);
        }