Ejemplo n.º 1
0
        public void ToVector3D()
        {
            Ellipsoid ellipsoid = new Ellipsoid(1, 1, 0.7);

            Assert.IsTrue(Vector3D.UnitX.EqualsEpsilon(ellipsoid.ToVector3D(new Geodetic3D(0, 0, 0)), 1e-10));
            Assert.IsTrue(Vector3D.UnitY.EqualsEpsilon(ellipsoid.ToVector3D(new Geodetic3D(Trig.ToRadians(90), 0, 0)), 1e-10));
            Assert.IsTrue(new Vector3D(0, 0, 0.7).EqualsEpsilon(ellipsoid.ToVector3D(new Geodetic3D(0, Trig.ToRadians(90), 0)), 1e-10));
        }
Ejemplo n.º 2
0
        public PointShapefile(
            Shapefile shapefile, 
            Context context, 
            Ellipsoid globeShape,
            ShapefileAppearance appearance)
        {
            Verify.ThrowIfNull(shapefile);
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);
            Verify.ThrowIfNull(appearance);

            _billboards = new BillboardCollection(context);
            _billboards.Texture = Device.CreateTexture2D(appearance.Bitmap, TextureFormat.RedGreenBlueAlpha8, false);
            
            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Point)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                Vector2D point = ((PointShape)shape).Position;
                Vector3D position = globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y)));

                Billboard billboard = new Billboard();
                billboard.Position = position;
                _billboards.Add(billboard);
            }
        }
Ejemplo n.º 3
0
        public void ToGeodetic3D()
        {
            Ellipsoid ellipsoid = new Ellipsoid(6378137.0, 6378137.0, 6356752.314245);

            Vector3D   v = ellipsoid.ToVector3D(new Geodetic3D(0, 0, 0));
            Geodetic3D g = ellipsoid.ToGeodetic3D(v);

            Assert.AreEqual(0.0, g.Longitude, 1e-10);
            Assert.AreEqual(0.0, g.Latitude, 1e-8);
            Assert.AreEqual(0.0, g.Height, 1e-10);

            v = ellipsoid.ToVector3D(new Geodetic3D(Trig.ToRadians(45.0), Trig.ToRadians(-60.0), -123.4));
            g = ellipsoid.ToGeodetic3D(v);
            Assert.AreEqual(Trig.ToRadians(45.0), g.Longitude, 1e-10);
            Assert.AreEqual(Trig.ToRadians(-60.0), g.Latitude, 1e-3);
            Assert.AreEqual(-123.4, g.Height, 1e-3);

            v = ellipsoid.ToVector3D(new Geodetic3D(Trig.ToRadians(-97.3), Trig.ToRadians(71.2), 1188.7));
            g = ellipsoid.ToGeodetic3D(v);
            Assert.AreEqual(Trig.ToRadians(-97.3), g.Longitude, 1e-10);
            Assert.AreEqual(Trig.ToRadians(71.2), g.Latitude, 1e-3);
            Assert.AreEqual(1188.7, g.Height, 1e-3);
        }
Ejemplo n.º 4
0
        public void ToGeodetic3D()
        {
            Ellipsoid ellipsoid = new Ellipsoid(6378137.0, 6378137.0, 6356752.314245);

            Vector3D v = ellipsoid.ToVector3D(new Geodetic3D(0, 0, 0));
            Geodetic3D g = ellipsoid.ToGeodetic3D(v);
            Assert.AreEqual(0.0, g.Longitude, 1e-10);
            Assert.AreEqual(0.0, g.Latitude, 1e-8);
            Assert.AreEqual(0.0, g.Height, 1e-10);

            v = ellipsoid.ToVector3D(new Geodetic3D(Trig.ToRadians(45.0), Trig.ToRadians(-60.0), -123.4));
            g = ellipsoid.ToGeodetic3D(v);
            Assert.AreEqual(Trig.ToRadians(45.0), g.Longitude, 1e-10);
            Assert.AreEqual(Trig.ToRadians(-60.0), g.Latitude, 1e-3);
            Assert.AreEqual(-123.4, g.Height, 1e-3);

            v = ellipsoid.ToVector3D(new Geodetic3D(Trig.ToRadians(-97.3), Trig.ToRadians(71.2), 1188.7));
            g = ellipsoid.ToGeodetic3D(v);
            Assert.AreEqual(Trig.ToRadians(-97.3), g.Longitude, 1e-10);
            Assert.AreEqual(Trig.ToRadians(71.2), g.Latitude, 1e-3);
            Assert.AreEqual(1188.7, g.Height, 1e-3);
        }
Ejemplo n.º 5
0
        public void ToVector3D()
        {
            Ellipsoid ellipsoid = new Ellipsoid(1, 1, 0.7);

            Assert.IsTrue(Vector3D.UnitX.EqualsEpsilon(ellipsoid.ToVector3D(new Geodetic3D(0, 0, 0)), 1e-10));
            Assert.IsTrue(Vector3D.UnitY.EqualsEpsilon(ellipsoid.ToVector3D(new Geodetic3D(Trig.ToRadians(90), 0, 0)), 1e-10));
            Assert.IsTrue(new Vector3D(0, 0, 0.7).EqualsEpsilon(ellipsoid.ToVector3D(new Geodetic3D(0, Trig.ToRadians(90), 0)), 1e-10));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sets the <see cref="CenterPoint"/> and <see cref="FixedToLocalRotation"/> properties so that the
        /// camera is looking at a given longitude, latitude, and height and is oriented in that point's local
        /// East-North-Up frame.  This method does not change the <see cref="Azimuth"/>, <see cref="Elevation"/>,
        /// or <see cref="Range"/> properties, but the existing values of those properties are interpreted in the
        /// new reference frame.
        /// </summary>
        /// <param name="longitude">The longitude of the point to look at, in radians.</param>
        /// <param name="latitude">The latitude of the point to look at, in radians.</param>
        /// <param name="height">The height of the point to look at, in meters above the <see cref="Ellipsoid"/> surface.</param>
        public void ViewPoint(Ellipsoid ellipsoid, Geodetic3D geographic)
        {
            _centerPoint = ellipsoid.ToVector3D(geographic);
            
            // Fixed to East-North-Up rotation, from Wikipedia's "Geodetic System" topic.
            double cosLon = Math.Cos(geographic.Longitude);
            double cosLat = Math.Cos(geographic.Latitude);
            double sinLon = Math.Sin(geographic.Longitude);
            double sinLat = Math.Sin(geographic.Latitude);
            _fixedToLocalRotation =
                new Matrix3D(-sinLon,            cosLon,             0.0,
                             -sinLat * cosLon,   -sinLat * sinLon,   cosLat,
                             cosLat * cosLon,    cosLat * sinLon,    sinLat);

            UpdateCameraFromParameters();
        }
Ejemplo n.º 7
0
        public PolygonShapefile(
            Shapefile shapefile, 
            Context context, 
            Ellipsoid globeShape,
            ShapefileAppearance appearance)
        {
            Verify.ThrowIfNull(shapefile);
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);

            _polyline = new OutlinedPolylineTexture();
            _polygons = new List<Polygon>();

            VertexAttributeDoubleVector3 positionAttribute = new VertexAttributeDoubleVector3("position");
            VertexAttributeRGBA colorAttribute = new VertexAttributeRGBA("color");
            VertexAttributeRGBA outlineColorAttribute = new VertexAttributeRGBA("outlineColor");
            IndicesUnsignedInt indices = new IndicesUnsignedInt();

            Random r = new Random(3);
            IList<Vector3D> positions = new List<Vector3D>();

            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Polygon)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                PolygonShape polygonShape = (PolygonShape)shape;

                for (int j = 0; j < polygonShape.Count; ++j)
                {
                    Color color = Color.FromArgb(127, r.Next(256), r.Next(256), r.Next(256));

                    positions.Clear();

                    ShapePart part = polygonShape[j];

                    for (int i = 0; i < part.Count; ++i)
                    {
                        Vector2D point = part[i];

                        positions.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))));

                        //
                        // For polyline
                        //
                        positionAttribute.Values.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))));
                        colorAttribute.AddColor(color);
                        outlineColorAttribute.AddColor(Color.Black);

                        if (i != 0)
                        {
                            indices.Values.Add((uint)positionAttribute.Values.Count - 2);
                            indices.Values.Add((uint)positionAttribute.Values.Count - 1);
                        }
                    }

                    try
                    {
                        Polygon p = new Polygon(context, globeShape, positions);
                        p.Color = color;
                        _polygons.Add(p);
                    }
                    catch (ArgumentOutOfRangeException) // Not enough positions after cleaning
                    {
                    }
                }
            }

            Mesh mesh = new Mesh();
            mesh.PrimitiveType = PrimitiveType.Lines;
            mesh.Attributes.Add(positionAttribute);
            mesh.Attributes.Add(colorAttribute);
            mesh.Attributes.Add(outlineColorAttribute);
            mesh.Indices = indices;
            _polyline.Set(context, mesh);
        }
Ejemplo n.º 8
0
        public PolylineShapefile(
            Shapefile shapefile, 
            Context context, 
            Ellipsoid globeShape, 
            ShapefileAppearance appearance)
        {
            Verify.ThrowIfNull(shapefile);
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);
            Verify.ThrowIfNull(appearance);
            
            _polyline = new OutlinedPolylineTexture();

            int positionsCount = 0;
            int indicesCount = 0;
            PolylineCapacities(shapefile, out positionsCount, out indicesCount);

            VertexAttributeDoubleVector3 positionAttribute = new VertexAttributeDoubleVector3("position", positionsCount);
            VertexAttributeRGBA colorAttribute = new VertexAttributeRGBA("color", positionsCount);
            VertexAttributeRGBA outlineColorAttribute = new VertexAttributeRGBA("outlineColor", positionsCount);
            IndicesUnsignedInt indices = new IndicesUnsignedInt(indicesCount);

            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Polyline)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                PolylineShape polylineShape = (PolylineShape)shape;

                for (int j = 0; j < polylineShape.Count; ++j)
                {
                    ShapePart part = polylineShape[j];

                    for (int i = 0; i < part.Count; ++i)
                    {
                        Vector2D point = part[i];

                        positionAttribute.Values.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))));
                        colorAttribute.AddColor(appearance.PolylineColor);
                        outlineColorAttribute.AddColor(appearance.PolylineOutlineColor);

                        if (i != 0)
                        {
                            indices.Values.Add((uint)positionAttribute.Values.Count - 2);
                            indices.Values.Add((uint)positionAttribute.Values.Count - 1);
                        }
                    }
                }
            }

            Mesh mesh = new Mesh();
            mesh.PrimitiveType = PrimitiveType.Lines;
            mesh.Attributes.Add(positionAttribute);
            mesh.Attributes.Add(colorAttribute);
            mesh.Attributes.Add(outlineColorAttribute);
            mesh.Indices = indices;
            _polyline.Set(context, mesh);
            _polyline.Width = appearance.PolylineWidth;
            _polyline.OutlineWidth = appearance.PolylineOutlineWidth;
        }
Ejemplo n.º 9
0
 private void SetShape()
 {
     _globeShape = new Ellipsoid(
         Ellipsoid.ScaledWgs84.Radii.X,
         Ellipsoid.ScaledWgs84.Radii.Y,
         _semiMinorAxis);
     _p = _globeShape.ToVector3D(new Geodetic2D(Trig.ToRadians(40), Trig.ToRadians(40)));
     _q = _globeShape.ToVector3D(new Geodetic2D(Trig.ToRadians(120), Trig.ToRadians(-30)));
 }