Esempio n. 1
0
        private void AddSiapStcRow(string stcsColName, VoRow row, bool selected)
        {
            string stcs = row[stcsColName].ToString().Replace("  ", " ");
            Color  col  = Color.FromArgb(120, 255, 255, 255);

            if (selected)
            {
                col = Color.Yellow;
            }

            if (stcs.StartsWith("Polygon J2000"))
            {
                string[] parts = stcs.Split(new char[] { ' ' });

                int len   = parts.Length;
                int index = 0;
                while (index < len)
                {
                    if (parts[index] == "Polygon")
                    {
                        index += 2;
                        Vector3d lastPoint  = new Vector3d();
                        Vector3d firstPoint = new Vector3d();
                        bool     start      = true;
                        for (int i = index; i < len; i += 2)
                        {
                            if (parts[i] == "Polygon")
                            {
                                start = true;
                                break;
                            }
                            else
                            {
                                double Xcoord = Coordinates.ParseRA(parts[i], true) * 15 + 180;
                                double Ycoord = Coordinates.ParseDec(parts[i + 1]);


                                Vector3d pnt = Coordinates.GeoTo3dDouble(Ycoord, Xcoord);

                                if (!start)
                                {
                                    lineList2d.AddLine(lastPoint, pnt, col, new Dates());
                                }
                                else
                                {
                                    firstPoint = pnt;
                                    start      = false;
                                }
                                lastPoint = pnt;
                            }
                            index += 2;
                        }
                        if (len > 4)
                        {
                            lineList2d.AddLine(firstPoint, lastPoint, col, new Dates());
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private double GetAltitudeFromLatLng(double lat, double lng, bool meters)
        {
            Vector3d testPoint = Coordinates.GeoTo3dDouble(lat, lng);
            Vector2d uv        = DistanceCalc.GetUVFromInnerPoint(TopLeft, TopRight, BottomLeft, BottomRight, testPoint);

            // Get 4 samples and interpolate
            double uud = Math.Max(0, Math.Min(16, (uv.X * 16)));
            double vvd = Math.Max(0, Math.Min(16, (uv.Y * 16)));



            int uu = Math.Max(0, Math.Min(15, (int)(uv.X * 16)));
            int vv = Math.Max(0, Math.Min(15, (int)(uv.Y * 16)));

            double ha = uud - uu;
            double va = vvd - vv;

            if (demArray != null)
            {
                // 4 nearest neighbors
                double ul = demArray[uu + 17 * vv];
                double ur = demArray[(uu + 1) + 17 * vv];
                double ll = demArray[uu + 17 * (vv + 1)];
                double lr = demArray[(uu + 1) + 17 * (vv + 1)];

                double top    = ul * (1 - ha) + ha * ur;
                double bottom = ll * (1 - ha) + ha * lr;
                double val    = top * (1 - va) + va * bottom;

                return(val / (meters ? 1 : DemScaleFactor));
            }

            return(demAverage / (meters ? 1 : DemScaleFactor));
        }
Esempio n. 3
0
        protected void ComputeBoundingSphereBottomsUp(Tile parent)
        {
            double tileDegrees = (double)this.dataset.BaseTileDegrees / ((double)Math.Pow(2, this.level));


            double latMin = (-90 + (((double)(this.y + 1)) * tileDegrees));
            double latMax = (-90 + (((double)this.y) * tileDegrees));
            double lngMin = (((double)this.x * tileDegrees) - 180.0);
            double lngMax = ((((double)(this.x + 1)) * tileDegrees) - 180.0);

            double latCenter = (latMin + latMax) / 2.0;
            double lngCenter = (lngMin + lngMax) / 2.0;

            if (level == 12 || level == 19)
            {
                Vector3d temp = Coordinates.GeoTo3dDouble(latCenter, lngCenter);
                localCenter = new Vector3d(temp.X, temp.Y, temp.Z);
            }
            else if (level > 12)
            {
                localCenter = parent.localCenter;
            }

            this.sphereCenter = GeoTo3d(latCenter, lngCenter, false);

            TopLeft     = GeoTo3dWithAltitude(latMin, lngMin, false);
            BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false);
            TopRight    = GeoTo3dWithAltitude(latMin, lngMax, false);
            BottomLeft  = GeoTo3dWithAltitude(latMax, lngMin, false);
            Vector3d distVect = TopLeft;

            distVect.Subtract(sphereCenter);
            this.sphereRadius = distVect.Length();
            tileDegrees       = lngMax - lngMin;
        }
Esempio n. 4
0
        public double Distance3d(Coordinates pointB)
        {
            Vector3d pnt1 = Coordinates.GeoTo3dDouble(pointB.Lat, pointB.Lng);
            Vector3d pnt2 = Coordinates.GeoTo3dDouble(this.Lat, this.Lng);

            Vector3d pntDiff = pnt1 - pnt2;

            return(pntDiff.Length() / RC);
        }
Esempio n. 5
0
        private void InitializeRoute(RenderContext11 renderContext)
        {
            triangleList               = new TriangleList();
            triangleList.Decay         = 1000;
            triangleList.Sky           = this.Astronomical;
            triangleList.TimeSeries    = true;
            triangleList.DepthBuffered = false;
            triangleList.AutoTime      = false;

            int steps = 500;

            Vector3d start = Coordinates.GeoTo3dDouble(latStart, lngStart);
            Vector3d end   = Coordinates.GeoTo3dDouble(latEnd, lngEnd);
            Vector3d dir   = end - start;

            dir.Normalize();

            Vector3d startNormal = start;

            startNormal.Normalize();

            Vector3d left  = Vector3d.Cross(startNormal, dir);
            Vector3d right = Vector3d.Cross(dir, startNormal);

            left.Normalize();
            right.Normalize();

            left.Multiply(.001 * width);
            right.Multiply(.001 * width);

            Vector3d lastLeft  = new Vector3d();
            Vector3d lastRight = new Vector3d();
            bool     firstTime = true;

            for (int i = 0; i <= steps; i++)
            {
                Vector3d v = Vector3d.Lerp(start, end, i / (float)steps);
                v.Normalize();
                Vector3d cl = v;
                Vector3d cr = v;

                cl.Add(left);
                cr.Add(right);

                if (!firstTime)
                {
                    triangleList.AddQuad(lastRight, lastLeft, cr, cl, Color, new Dates(i / (float)steps, 2));
                }
                else
                {
                    firstTime = false;
                }

                lastLeft  = cl;
                lastRight = cr;
            }
        }
Esempio n. 6
0
        private void AddLines(bool sky, KmlLineList geo, float lineWidth, Color polyColor, Color lineColor, bool extrude)
        {
            //todo can we save this work for later?
            List <Vector3d> vertexList       = new List <Vector3d>();
            List <Vector3d> vertexListGround = new List <Vector3d>();

            //todo list
            // We need to Wrap Around for complete polygone
            // we aldo need to do intereor
            //todo space? using RA/DEC



            for (int i = 0; i < (geo.PointList.Count); i++)
            {
                vertexList.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / geo.MeanRadius)));
                vertexListGround.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1));
            }


            for (int i = 0; i < (geo.PointList.Count - 1); i++)
            {
                if (sky)
                {
                    lines.AddLine(Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, new Dates());
                }
                else
                {
                    if (extrude)
                    {
                        triangles.AddQuad(vertexList[i], vertexList[i + 1], vertexListGround[i], vertexListGround[i + 1], polyColor, new Dates());
                    }

                    if (lineWidth > 0)
                    {
                        lines.AddLine
                            (vertexList[i], vertexList[i + 1], lineColor, new Dates());
                        if (extrude)
                        {
                            lines.AddLine(vertexListGround[i], vertexListGround[i + 1], lineColor, new Dates());
                            lines.AddLine(vertexList[i], vertexListGround[i], lineColor, new Dates());
                            lines.AddLine(vertexList[i + 1], vertexListGround[i + 1], lineColor, new Dates());
                        }
                    }
                }
            }

            List <int> indexes = Glu.TesselateSimplePoly(vertexList);

            for (int i = 0; i < indexes.Count; i += 3)
            {
                triangles.AddTriangle(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], polyColor, new Dates());
            }
        }
Esempio n. 7
0
        static public Vector3d SterographicTo3d(double x, double y, double radius, double standardLat, double meridean, double falseEasting, double falseNorthing, double scale, bool north)
        {
            double lat = 90;
            double lng = 0;

            x -= falseEasting;
            y -= falseNorthing;



            if (x != 0 || y != 0)
            {
                double re   = (1 + Math.Sin(Math.Abs(standardLat) / 180 * Math.PI)) * EarthRadius / scale;
                double rere = re * re;
                double c1   = 180 / Math.PI;

                if (x == 0)
                {
                    lng = 90 * Math.Sign(y);
                }
                else
                {
                    lng = Math.Atan2(y, x) * c1;
                }

                //if (x < 0)
                //{
                //    lng = lng + (180 * Math.Sign(y));
                //}

                //if (lng > 180)
                //{
                //    lng -= 360;
                //}

                //if (lng < -180)
                //{
                //    lng += 360;
                //}

                double len = (x * x) + (y * y);
                lat = (rere - len) / (rere + len);
                lat = Math.Asin(lat) * c1;

                if (!north)
                {
                    lat      = -lat;
                    lng      = -lng;
                    meridean = -meridean;
                }
            }
            return(Coordinates.GeoTo3dDouble(lat, 90 + lng + meridean, radius));
        }
Esempio n. 8
0
        public override bool IsPointInTile(double lat, double lng)
        {
            if (level == 0)
            {
                return(true);
            }

            if (level == 1)
            {
                if ((lng >= 0 && lng <= 90) && (X == 0 && Y == 1))
                {
                    return(true);
                }
                if ((lng > 90 && lng <= 180) && (X == 1 && Y == 1))
                {
                    return(true);
                }
                if ((lng < 0 && lng >= -90) && (X == 0 && Y == 0))
                {
                    return(true);
                }
                if ((lng < -90 && lng >= -180) && (X == 1 && Y == 0))
                {
                    return(true);
                }
            }

            if (!this.DemReady || this.DemData == null)
            {
                return(false);
            }

            Vector3d testPoint = Coordinates.GeoTo3dDouble(lat, lng);
            bool     top       = IsLeftOfHalfSpace(TopLeft, TopRight, testPoint);
            bool     right     = IsLeftOfHalfSpace(TopRight, BottomRight, testPoint);
            bool     bottom    = IsLeftOfHalfSpace(BottomRight, BottomLeft, testPoint);
            bool     left      = IsLeftOfHalfSpace(BottomLeft, TopLeft, testPoint);

            if (top && right && bottom && left)
            {
                // showSelected = true;
                return(true);
            }
            return(false);;
        }
Esempio n. 9
0
        public static CameraParameters InterpolateGreatCircle(CameraParameters from, CameraParameters to, double alphaIn, InterpolationType type)
        {
            CameraParameters result   = new CameraParameters();
            double           alpha    = EaseCurve(alphaIn, type);
            double           alphaBIn = Math.Min(1.0, alphaIn * 2);
            double           alphaB   = EaseCurve(alphaBIn, type);

            result.Angle    = to.Angle * alpha + from.Angle * (1.0 - alpha);
            result.Rotation = to.Rotation * alpha + from.Rotation * (1.0 - alpha);

            Vector3d left  = Coordinates.GeoTo3dDouble(from.Lat, from.Lng);
            Vector3d right = Coordinates.GeoTo3dDouble(to.Lat, to.Lng);

            Vector3d mid = Vector3d.Slerp(left, right, alpha);

            Vector2d midV2 = Coordinates.CartesianToLatLng(mid);

            result.Lat = midV2.Y;
            result.Lng = midV2.X;

            result.Zoom       = Math.Pow(2, Math.Log(to.Zoom, 2) * alpha + Math.Log(from.Zoom, 2) * (1.0 - alpha));
            result.Opacity    = (float)(to.Opacity * alpha + from.Opacity * (1.0 - alpha));
            result.ViewTarget = Vector3d.Lerp(from.ViewTarget, to.ViewTarget, alpha);

            result.DomeAlt = to.DomeAlt * alpha + from.DomeAlt * (1.0 - alpha);
            result.DomeAz  = to.DomeAz * alpha + from.DomeAz * (1.0 - alpha);


            result.TargetReferenceFrame = to.TargetReferenceFrame;
            if (to.Target == from.Target)
            {
                result.Target = to.Target;
            }
            else
            {
                result.Target = SolarSystemObjects.Custom;
            }
            return(result);
        }
Esempio n. 10
0
        private void ComputePoints()
        {
            Vector3d center = Coordinates.GeoTo3dDouble(alt, az + 90);
            Vector3d up     = Coordinates.GeoTo3dDouble(alt + 90, az + 90);

            double width  = .03;
            double height = width;

            Vector3d left  = Vector3d.Cross(center, up);
            Vector3d right = Vector3d.Cross(up, center);

            left.Normalize();
            right.Normalize();
            up.Normalize();

            Vector3d upTan = Vector3d.Cross(center, right);

            upTan.Normalize();

            left.Multiply(width);
            right.Multiply(width);
            Vector3d top    = upTan;
            Vector3d bottom = -upTan;

            top.Multiply(height);
            bottom.Multiply(height);
            Vector3d ul = center;

            ul.Add(top);
            ul.Add(left);
            Vector3d ur = center;

            ur.Add(top);
            ur.Add(right);

            Vector3d ll = center;

            ll.Add(left);
            ll.Add(bottom);

            Vector3d lr = center;

            lr.Add(right);
            lr.Add(bottom);

            points[0].Position = ul.Vector4;
            points[1].Position = ll.Vector4;
            points[3].Position = lr.Vector4;
            points[2].Position = ur.Vector4;

            points[0].Color = Color;
            points[1].Color = Color;
            points[3].Color = Color;
            points[2].Color = Color;

            points[0].Tu = 0;
            points[0].Tv = 0;
            points[1].Tu = 0;
            points[1].Tv = 1;
            points[3].Tu = 1;
            points[3].Tv = 1;
            points[2].Tu = 1;
            points[2].Tv = 0;
        }
        private void UpdateLines()
        {
            if (!initialized)
            {
                return;
            }
            lines.Clear();

            double width  = Overlay.east - Overlay.west;
            double height = Overlay.north - Overlay.south;

            double altitude = 1 + Earth3d.MainWindow.GetScaledAltitudeForLatLong((Overlay.north + Overlay.south) / 2, (Overlay.east + Overlay.west) / 2);

            Vector3d topLeftA   = Coordinates.GeoTo3dDouble(Overlay.north - height / 20, Overlay.west, altitude);
            Vector3d topLeftB   = Coordinates.GeoTo3dDouble(Overlay.north, Overlay.west, altitude);
            Vector3d topLeftC   = Coordinates.GeoTo3dDouble(Overlay.north, Overlay.west + width / 20, altitude);
            Vector3d topMiddleA = Coordinates.GeoTo3dDouble(Overlay.north, ((Overlay.east + Overlay.west) / 2) - width / 20, altitude);
            Vector3d topMiddleB = Coordinates.GeoTo3dDouble(Overlay.north, ((Overlay.east + Overlay.west) / 2) + width / 20, altitude);
            Vector3d topRightA  = Coordinates.GeoTo3dDouble(Overlay.north - height / 20, Overlay.east, altitude);
            Vector3d topRightB  = Coordinates.GeoTo3dDouble(Overlay.north, Overlay.east, altitude);
            Vector3d topRightC  = Coordinates.GeoTo3dDouble(Overlay.north, Overlay.east - width / 20, altitude);

            Vector3d middleRightA = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2 - height / 20, Overlay.west, altitude);
            Vector3d middleRightB = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2 + height / 20, Overlay.west, altitude);
            Vector3d centerA      = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2, ((Overlay.east + Overlay.west) / 2) - width / 20, altitude);
            Vector3d centerB      = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2, ((Overlay.east + Overlay.west) / 2) + width / 20, altitude);
            Vector3d centerC      = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2 - height / 20, ((Overlay.east + Overlay.west) / 2), altitude);
            Vector3d centerD      = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2 + height / 20, ((Overlay.east + Overlay.west) / 2), altitude);
            Vector3d middleLeftA  = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2 - height / 20, Overlay.east, altitude);
            Vector3d middleLeftB  = Coordinates.GeoTo3dDouble((Overlay.north + Overlay.south) / 2 + height / 20, Overlay.east, altitude);



            Vector3d bottomLeftA   = Coordinates.GeoTo3dDouble(Overlay.south + height / 20, Overlay.west, altitude);
            Vector3d bottomLeftB   = Coordinates.GeoTo3dDouble(Overlay.south, Overlay.west, altitude);
            Vector3d bottomLeftC   = Coordinates.GeoTo3dDouble(Overlay.south, Overlay.west + width / 20, altitude);
            Vector3d bottomMiddleA = Coordinates.GeoTo3dDouble(Overlay.south, ((Overlay.east + Overlay.west) / 2) - width / 20, altitude);
            Vector3d bottomMiddleB = Coordinates.GeoTo3dDouble(Overlay.south, ((Overlay.east + Overlay.west) / 2) + width / 20, altitude);
            Vector3d bottomRightA  = Coordinates.GeoTo3dDouble(Overlay.south + height / 20, Overlay.east, altitude);
            Vector3d bottomRightB  = Coordinates.GeoTo3dDouble(Overlay.south, Overlay.east, altitude);
            Vector3d bottomRightC  = Coordinates.GeoTo3dDouble(Overlay.south, Overlay.east - width / 20, altitude);
            Color    lineColor     = Color.Yellow;

            lines.AddLine(topLeftA, topLeftB, lineColor, new Dates());
            lines.AddLine(topLeftB, topLeftC, lineColor, new Dates());
            lines.AddLine(topMiddleA, topMiddleB, lineColor, new Dates());
            lines.AddLine(topRightA, topRightB, lineColor, new Dates());
            lines.AddLine(topRightB, topRightC, lineColor, new Dates());

            lines.AddLine(middleRightA, middleRightB, lineColor, new Dates());
            lines.AddLine(centerA, centerB, lineColor, new Dates());
            lines.AddLine(centerC, centerD, lineColor, new Dates());
            lines.AddLine(middleLeftA, middleLeftB, lineColor, new Dates());


            lines.AddLine(bottomLeftA, bottomLeftB, lineColor, new Dates());
            lines.AddLine(bottomLeftB, bottomLeftC, lineColor, new Dates());
            lines.AddLine(bottomMiddleA, bottomMiddleB, lineColor, new Dates());
            lines.AddLine(bottomRightA, bottomRightB, lineColor, new Dates());
            lines.AddLine(bottomRightB, bottomRightC, lineColor, new Dates());
        }
Esempio n. 12
0
        private void AddFeatureToDisplay(KmlFeature feature, bool sky)
        {
            KmlDocument doc = feature as KmlDocument;

            if (doc != null)
            {
                sky = doc.sky;
            }
            if (!(feature is KmlNetworkLink))
            {
                if (feature.visibility == false)
                {
                    return;
                }
                else if (feature is KmlPlacemark)
                {
                    KmlPlacemark placemark = (KmlPlacemark)feature;
                    KmlStyle     style     = placemark.Style.GetStyle(placemark.Selected);
                    Color        lineColor = Color.White;
                    if (style != null)
                    {
                        lineColor = style.LineStyle.Color;
                    }
                    if (placemark.geometry is KmlPoint)
                    {
                        placemark.Point = (KmlPoint)placemark.geometry;
                        AddPlacemark(placemark);
                    }
                    else if (placemark.geometry is KmlMultiGeometry)
                    {
                        KmlMultiGeometry geo = (KmlMultiGeometry)placemark.geometry;
                        AddMultiGeometry(sky, placemark, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo);
                    }
                    else if (placemark.geometry is KmlPolygon)
                    {
                        KmlPolygon geo = (KmlPolygon)placemark.geometry;
                        if (geo.OuterBoundary != null)
                        {
                            AddLines(sky, geo.OuterBoundary as KmlLineList, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo.extrude);
                            // to do 3d work and subtract inner rings
                        }
                    }
                    else if (placemark.geometry is KmlLineString)
                    {
                        KmlLineString geo = (KmlLineString)placemark.geometry;

                        List <Vector3d> vertexList = new List <Vector3d>();
                        for (int i = 0; i < (geo.PointList.Count); i++)
                        {
                            vertexList.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / geo.MeanRadius)));
                        }
                        for (int i = 0; i < (geo.PointList.Count - 1); i++)
                        {
                            if (sky)
                            {
                                lines.AddLine(Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, new Dates());
                            }
                            else
                            {
                                lines.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates());
                            }
                        }
                    }
                }
                if (feature is KmlGroundOverlay && feature.visibility)
                {
                    AddGroundOverlay(feature as KmlGroundOverlay);
                }

                if (feature is KmlScreenOverlay && feature.visibility)
                {
                    AddScreenOverlay(feature as KmlScreenOverlay);
                }
            }
            if (feature.visibility)
            {
                if (feature is KmlContainer)
                {
                    KmlContainer container = (KmlContainer)feature;
                    if (container.children != null)
                    {
                        foreach (KmlFeature child in container.children)
                        {
                            AddFeatureToDisplay(child, sky);
                        }
                    }
                }
                else
                {
                    if (feature is KmlNetworkLink)
                    {
                        KmlNetworkLink netLink = (KmlNetworkLink)feature;
                        if (netLink.LinkRoot != null)
                        {
                            foreach (KmlFeature child in netLink.LinkRoot.children)
                            {
                                AddFeatureToDisplay(child, sky);
                            }
                        }
                    }
                }
            }
        }
        protected void ComputeBoundingSphere(MercatorTile parent, double altitude)
        {
            double tileDegrees = 360 / (Math.Pow(2, this.level));

            latMin = AbsoluteMetersToLatAtZoom(y * 256, level);
            latMax = AbsoluteMetersToLatAtZoom((y + 1) * 256, level);
            lngMin = (((double)this.x * tileDegrees) - 180.0);
            lngMax = ((((double)(this.x + 1)) * tileDegrees) - 180.0);

            double latCenter = AbsoluteMetersToLatAtZoom(((y * 2) + 1) * 256, level + 1);
            double lngCenter = (lngMin + lngMax) / 2.0;


            if (level == 12 || level == 17)
            {
                localCenter = Coordinates.GeoTo3dDouble(latCenter, lngCenter);
            }
            else if (level > 12)
            {
                localCenter = parent.localCenter;
            }


            demIndex = 0;

            if (parent != null && parent.DemData != null)
            {
                this.sphereCenter = GeoTo3dWithAltitude(latCenter, lngCenter, parent.GetAltitudeAtLatLng(latCenter, lngCenter, 1), false);
                TopLeft           = GeoTo3dWithAltitude(latMin, lngMin, parent.GetAltitudeAtLatLng(latMin, lngMin, 1), false);
                BottomRight       = GeoTo3dWithAltitude(latMax, lngMax, parent.GetAltitudeAtLatLng(latMax, lngMax, 1), false);
                TopRight          = GeoTo3dWithAltitude(latMin, lngMax, parent.GetAltitudeAtLatLng(latMin, lngMax, 1), false);
                BottomLeft        = GeoTo3dWithAltitude(latMax, lngMin, parent.GetAltitudeAtLatLng(latMax, lngMin, 1), false);
            }
            else
            {
                this.sphereCenter = GeoTo3dWithAltitude(latCenter, lngCenter, altitude, false);

                TopLeft     = GeoTo3dWithAltitude(latMin, lngMin, altitude, false);
                BottomRight = GeoTo3dWithAltitude(latMax, lngMax, altitude, false);
                TopRight    = GeoTo3dWithAltitude(latMin, lngMax, altitude, false);
                BottomLeft  = GeoTo3dWithAltitude(latMax, lngMin, altitude, false);
            }

            center = sphereCenter;

            if (Y == 0)
            {
                TopLeft  = new Vector3d(0, 1, 0);
                TopRight = new Vector3d(0, 1, 0);
            }

            if (Y == Math.Pow(2, level) - 1)
            {
                BottomRight = new Vector3d(0, -1, 0);
                BottomLeft  = new Vector3d(0, -1, 0);
            }

            Vector3d distVect1 = TopLeft;

            distVect1.Subtract(sphereCenter);
            Vector3d distVect2 = BottomRight;

            distVect2.Subtract(sphereCenter);
            Vector3d distVect3 = TopRight;

            distVect3.Subtract(sphereCenter);
            Vector3d distVect4 = BottomLeft;

            distVect4.Subtract(sphereCenter);


            this.sphereRadius = Math.Max(Math.Max(distVect1.Length(), distVect2.Length()), Math.Max(distVect3.Length(), distVect4.Length()));
            tileDegrees       = lngMax - lngMin;

            //  if (level > 14)
            {
                //              this.sphereCenter.Add(localCenter);
            }
        }
Esempio n. 14
0
        public override IPlace FindClosest(Coordinates target, float distance, IPlace defaultPlace, bool astronomical)
        {
            Vector3d searchPoint = Coordinates.GeoTo3dDouble(target.Lat, target.Lng);

            //searchPoint = -searchPoint;
            Vector3d dist;

            if (defaultPlace != null)
            {
                Vector3d testPoint = Coordinates.RADecTo3d(defaultPlace.RA, -defaultPlace.Dec, -1.0);
                dist     = searchPoint - testPoint;
                distance = (float)dist.Length();
            }

            int closestItem = -1;
            int index       = 0;

            foreach (Vector3 point in positions)
            {
                dist = searchPoint - new Vector3d(point);
                if (dist.Length() < distance)
                {
                    distance    = (float)dist.Length();
                    closestItem = index;
                }
                index++;
            }


            if (closestItem == -1)
            {
                return(defaultPlace);
            }

            Coordinates pnt = Coordinates.CartesianToSpherical2(positions[closestItem]);

            string name = table.Rows[closestItem].ColumnData[this.nameColumn].ToString();

            if (nameColumn == startDateColumn || nameColumn == endDateColumn)
            {
                name = SpreadSheetLayer.ParseDate(name).ToString("u");
            }

            if (String.IsNullOrEmpty(name))
            {
                name = string.Format("RA={0}, Dec={1}", Coordinates.FormatHMS(pnt.RA), Coordinates.FormatDMS(pnt.Dec));
            }
            TourPlace place = new TourPlace(name, pnt.Lat, pnt.RA, Classification.Unidentified, "", ImageSetType.Sky, -1);

            Dictionary <String, String> rowData = new Dictionary <string, string>();

            for (int i = 0; i < table.Columns.Count; i++)
            {
                string colValue = table.Rows[closestItem][i].ToString();
                if (i == startDateColumn || i == endDateColumn)
                {
                    colValue = SpreadSheetLayer.ParseDate(colValue).ToString("u");
                }

                if (!rowData.ContainsKey(table.Column[i].Name) && !string.IsNullOrEmpty(table.Column[i].Name))
                {
                    rowData.Add(table.Column[i].Name, colValue);
                }
                else
                {
                    rowData.Add("Column" + i.ToString(), colValue);
                }
            }
            place.Tag = rowData;
            if (Viewer != null)
            {
                Viewer.LabelClicked(closestItem);
            }
            return(place);
        }
Esempio n. 15
0
        private void GoToRADec_Click(object sender, EventArgs e)
        {
            int index = coordinateType.SelectedIndex;


            double ra       = 0;
            double dec      = 0;
            bool   raValid  = false;
            bool   decValid = false;

            switch (index)
            {
            case 0:     // Equitorial
            {
                ra       = Coordinates.ParseRA(raText.Text, false);
                dec      = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.ValidateRA(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
            }
            break;

            case 2:     // Galactic
            {
                double l = Coordinates.Parse(raText.Text);
                double b = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
                if (raValid && decValid)
                {
                    double[] result = Earth3d.GalactictoJ2000(l, b);
                    ra  = result[0] / 15;
                    dec = result[1];
                }
            }
            break;

            case 3:     // Ecliptic
            {
                double l = Coordinates.Parse(raText.Text);
                double b = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
                if (raValid && decValid)
                {
                    AstroCalc.AstroRaDec radec = AstroCalc.AstroCalc.EclipticToJ2000(l, b, SpaceTimeController.JNow);
                    ra  = radec.RA;
                    dec = radec.Dec;
                }
            }
            break;

            case 4:     // Geo
            {
                ra       = -Coordinates.Parse(raText.Text) / 15;
                dec      = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
            }
            break;

            case 1:     // alt/az
            {
                double az  = Coordinates.Parse(raText.Text);
                double alt = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
                Coordinates radec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(alt, az), SpaceTimeController.Location, SpaceTimeController.Now);
                ra  = radec.RA;
                dec = radec.Dec;
            }
            break;
            }
            if (raValid && decValid)
            {
                if (Earth3d.MainWindow.SolarSystemMode)
                {
                    Vector3d pnt = Coordinates.GeoTo3dDouble(dec, Coordinates.Parse(raText.Text));


                    pnt = Vector3d.TransformCoordinate(pnt, Planets.EarthMatrix);
                    pnt.Normalize();
                    Vector2d radec = Coordinates.CartesianToLatLng(pnt);

                    Earth3d.MainWindow.TargetLat  = radec.Y;
                    Earth3d.MainWindow.TargetLong = radec.X - 90;
                }
                else
                {
                    Earth3d.MainWindow.GotoTargetRADec(ra, dec, true, false);
                }
            }
        }
Esempio n. 16
0
        public bool MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (Earth3d.MainWindow.StudyImageset == null)
            {
                mouseDown = false;
                return(false);
            }
            Tile root = TileCache.GetTile(0, 0, 0, Earth3d.MainWindow.StudyImageset, null);

            if (root == null)
            {
                mouseDown = false;
                return(false);
            }
            if (e.Button == MouseButtons.Right && (root is SkyImageTile))
            {
                anchored = !anchored;
                popup.SetPivotMode(anchored);
                if (anchored)
                {
                    anchoredPoint1 = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                    TourPlace place = new TourPlace("", anchoredPoint1.Dec, anchoredPoint1.RA, Classification.Unidentified, "UMA", ImageSetType.Sky, -1);
                    Earth3d.MainWindow.SetLabelText(place, false);
                    if (root is TangentTile)
                    {
                        TangentTile tile   = (TangentTile)root;
                        Vector3d    vector = tile.TransformPoint(12, 12);
                        vector = Coordinates.GeoTo3dDouble(anchoredPoint1.Lat, anchoredPoint1.Lng);
                        double x;
                        double y;
                        tile.UnTransformPoint(vector, out x, out y);
                    }
                    else if (root is SkyImageTile)
                    {
                        SkyImageTile tile = (SkyImageTile)root;
                        anchorPoint1 = tile.GetImagePixel(anchoredPoint1);
                    }
                }
                mouseDown = true;
                return(true);
            }
            else if (e.Button == MouseButtons.Left)
            {
                dragging = true;
                pntDown  = e.Location;
                if (anchored)
                {
                    if (root is TangentTile)
                    {
                        startRotation = Earth3d.MainWindow.StudyImageset.Rotation;
                        startCenterX  = Earth3d.MainWindow.StudyImageset.OffsetX;
                        startCenterY  = Earth3d.MainWindow.StudyImageset.OffsetY;
                        startScale    = Earth3d.MainWindow.StudyImageset.BaseTileDegrees;
                        Coordinates downPoint = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                        startLength = anchoredPoint1.Distance(downPoint);
                        startAngle  = anchoredPoint1.Angle(downPoint) / RC;
                    }
                    else if (root is SkyImageTile)
                    {
                        SkyImageTile tile = (SkyImageTile)root;
                        anchoredPoint2 = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                        anchorPoint2   = tile.GetImagePixel(anchoredPoint2);
                    }
                }
                mouseDown = true;
                return(true);
            }
            else
            {
                mouseDown = false;
                return(false);
            }
        }
Esempio n. 17
0
        public void DrawPlaceMarks()
        {
            // todo11 port this Maybe instancing later?
            Matrix   projection = Earth3d.MainWindow.RenderContext11.Projection.Matrix11;
            Matrix   view       = Earth3d.MainWindow.RenderContext11.View.Matrix11;
            Matrix   world      = Earth3d.MainWindow.RenderContext11.World.Matrix11;
            Matrix3d worldD     = Earth3d.MainWindow.RenderContext11.World;
            Matrix   wvp        = (world * view * projection);

            try
            {
                Vector3 center = new Vector3(0f, 0f, 0);

                foreach (KmlPlacemark placemark in Placemarks)
                {
                    if (placemark.ShouldDisplay())
                    {
                        SharpDX.Direct3D11.Viewport vp = Earth3d.MainWindow.RenderContext11.ViewPort;
                        double   alt     = placemark.Point.altitude + EGM96Geoid.Height(placemark.Point.latitude, placemark.Point.longitude);
                        Vector3d point3d = Coordinates.GeoTo3dDouble(placemark.Point.latitude, placemark.Point.longitude, 1 + (alt / Earth3d.MainWindow.RenderContext11.NominalRadius));
                        Vector3  point   = Vector3.Project(point3d.Vector311, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0, 1, wvp);
                        // point.Z = 1;
                        KmlStyle  style   = placemark.Style.GetStyle(placemark.Selected);
                        Texture11 texture = style.IconStyle.Icon.Texture;

                        if (String.IsNullOrEmpty(style.IconStyle.Icon.Href))
                        {
                            texture = Star;
                        }

                        double sizeFactor = 1;

                        if (placemark.Selected)
                        {
                            double ticks          = HiResTimer.TickCount;
                            double elapsedSeconds = ((double)(ticks - TicksAtLastSelect)) / HiResTimer.Frequency;
                            sizeFactor = 1 + .3 * (Math.Sin(elapsedSeconds * 15) * Math.Max(0, (1 - elapsedSeconds)));
                        }

                        point3d.TransformCoordinate(worldD);
                        Vector3d dist     = Earth3d.MainWindow.RenderContext11.CameraPosition - point3d;
                        double   distance = dist.Length() * Earth3d.MainWindow.RenderContext11.NominalRadius;
                        dist.Normalize();
                        double dot = Vector3d.Dot(point3d, dist);
                        // if (dot > -.2)
                        {
                            double baseSize = Math.Min(40, 25 * ((2 * Math.Atan(.5 * (5884764 / distance))) / .7853)) * sizeFactor;
                            float  size     = (float)baseSize * style.IconStyle.Scale;
                            //todo fix this with real centers and offset by KML data
                            placemark.hitTestRect = new Rectangle((int)(point.X - (size / 2)), (int)(point.Y - (size / 2)), (int)(size + .5), (int)(size + .5));
                            if (texture != null)
                            {
                                center = new Vector3((float)texture.Width / 2f, (float)texture.Height / 2f, 0);

                                Sprite2d.Draw2D(Earth3d.MainWindow.RenderContext11, texture, new SizeF(size, size), new PointF(center.X, center.Y), (float)(style.IconStyle.Heading * Math.PI / 180f), new PointF(point.X, point.Y), Color.White);
                            }

                            if (style.LabelStyle.Color.A > 0 && style.LabelStyle.Scale > 0)
                            {
                                Rectangle recttext = new Rectangle((int)(point.X + (size / 2) + 10), (int)(point.Y - (size / 2)), 1000, 100);
                                //todo11 Earth3d.MainWindow.labelFont.DrawText(null, placemark.Name, recttext, DrawTextFormat.NoClip, style.LabelStyle.Color);
                            }
                        }
                    }
                }
            }
            finally
            {
            }
        }
Esempio n. 18
0
        protected override bool PrepVertexBuffer(float opacity)
        {
            VoColumn col = table.GetColumnByUcd("meta.id");

            if (col == null)
            {
                col = table.Column[0];
            }

            if (shapeFileVertex == null)
            {
                bool siapSet = IsSiapResultSet();

                if (lineList2d == null)
                {
                    lineList2d = new LineList();
                }
                lineList2d.Clear();

                VoColumn stcsCol = table.GetColumnByUcd("phys.area;obs.field");

                if (stcsCol == null && table.Columns.ContainsKey("regionSTCS"))
                {
                    stcsCol = table.Columns["regionSTCS"];
                }

                if (PlotType == PlotTypes.Gaussian)
                {
                    MarkerScale = MarkerScales.World;
                }
                else
                {
                    MarkerScale = MarkerScales.Screen;
                }

                List <TimeSeriesPointVertex> vertList = new List <TimeSeriesPointVertex>();
                List <UInt32>         indexList       = new List <UInt32>();
                TimeSeriesPointVertex lastItem        = new TimeSeriesPointVertex();
                positions.Clear();
                UInt32 currentIndex = 0;
                Color  color        = Color.FromArgb((int)(opacity * (float)Color.A), Color);

                pointScaleType = PointScaleTypes.StellarMagnitude;

                foreach (VoRow row in table.Rows)
                {
                    try
                    {
                        if (lngColumn > -1 && latColumn > -1)
                        {
                            double Xcoord = Coordinates.ParseRA(row[this.LngColumn].ToString(), true) * 15 + 180;
                            double Ycoord = Coordinates.ParseDec(row[this.LatColumn].ToString());
                            lastItem.Position = Coordinates.GeoTo3dDouble(Ycoord, Xcoord).Vector311;
                            positions.Add(lastItem.Position);
                            lastItem.Color = color;
                            if (sizeColumn > -1)
                            {
                                try
                                {
                                    if (MarkerScale == MarkerScales.Screen)
                                    {
                                        lastItem.PointSize = 20f;
                                    }
                                    else
                                    {
                                        switch (pointScaleType)
                                        {
                                        case PointScaleTypes.Linear:
                                            lastItem.PointSize = Convert.ToSingle(row[sizeColumn]);
                                            break;

                                        case PointScaleTypes.Log:
                                            lastItem.PointSize = (float)Math.Log(Convert.ToSingle(row[sizeColumn]));
                                            break;

                                        case PointScaleTypes.Power:
                                            lastItem.PointSize = (float)Math.Pow(2, Convert.ToSingle(row[sizeColumn]));
                                            break;

                                        case PointScaleTypes.StellarMagnitude:
                                        {
                                            double size = Convert.ToSingle(row[sizeColumn]);
                                            lastItem.PointSize = (float)(40 / Math.Pow(1.6, size)) * 10;
                                        }
                                        break;

                                        case PointScaleTypes.Constant:
                                            lastItem.PointSize = 1;
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                }
                                catch
                                {
                                    lastItem.PointSize = .01f;
                                }
                            }
                            else
                            {
                                if (MarkerScale == MarkerScales.Screen)
                                {
                                    lastItem.PointSize = 20;
                                }
                                else
                                {
                                    lastItem.PointSize = (float)Math.Pow(2, 1) * 100;
                                }
                            }


                            if (startDateColumn > -1)
                            {
                                DateTime dateTime = DateTime.Parse(row[startDateColumn].ToString());
                                lastItem.Tu = (float)SpaceTimeController.UtcToJulian(dateTime);
                                lastItem.Tv = 0;
                            }


                            vertList.Add(lastItem);
                            currentIndex++;
                        }


                        if (siapSet && stcsCol != null)
                        {
                            AddSiapStcRow(stcsCol.Name, row, row == table.SelectedRow);
                        }
                    }

                    catch
                    {
                    }
                    lines = false;
                }

                if (siapSet && stcsCol != null)
                {
                    AddSiapStcRow(stcsCol.Name, table.SelectedRow, true);
                }


                shapeVertexCount = vertList.Count;
                if (shapeVertexCount == 0)
                {
                    shapeVertexCount = 1;
                }
                shapeFileVertex = new TimeSeriesPointSpriteSet(RenderContext11.PrepDevice, vertList.ToArray());
            }
            return(true);
        }
        public override IPlace FindClosest(Coordinates target, float distance, IPlace closestPlace, bool astronomical)
        {
            bool     pointFound = false;
            int      pointIndex = -1;
            Vector3d target3d   = Coordinates.GeoTo3dDouble(target.Lat, target.Lng, 1);

            for (int i = 0; i < shapefile.Shapes.Count; i++)
            {
                if (shapefile.Shapes[i] is ComplexShape)
                {
                    ComplexShape p = (ComplexShape)shapefile.Shapes[i];

                    if (PointInboundingBox(target, p.BoundingBox))
                    {
                        if (p.Attributes != null && p.Attributes.ItemArray.GetLength(0) > 0)
                        {
                            int nameCol = GetNameColumn();
                            if (nameCol == -1)
                            {
                                nameCol = 0;
                            }

                            TourPlace place = new TourPlace(p.Attributes.ItemArray[nameCol].ToString(), (p.BoundingBox[1] + p.BoundingBox[3]) / 2, (p.BoundingBox[0] + p.BoundingBox[2]) / 2, Classification.Unidentified, "", ImageSetType.Earth, -1);

                            Dictionary <String, String> rowData = new Dictionary <string, string>();
                            for (int r = 0; r < p.Attributes.ItemArray.GetLength(0); r++)
                            {
                                rowData.Add(p.Attributes.Table.Columns[r].ColumnName, p.Attributes.ItemArray[r].ToString());
                            }
                            place.Tag = rowData;
                            return(place);
                        }
                        return(closestPlace);
                    }
                }

                else if (shapefile.Shapes[i].GetType() == typeof(ShapefileTools.Point))
                {
                    ShapefileTools.Point p = (ShapefileTools.Point)shapefile.Shapes[i];

                    Vector3d point = Coordinates.GeoTo3dDouble(p.Y, p.X, 1);
                    Vector3d dist  = target3d - point;

                    if (dist.Length() < distance)
                    {
                        pointFound = true;
                        pointIndex = i;
                        distance   = (float)dist.Length();
                    }
                }
            }

            if (pointFound)
            {
                ShapefileTools.Point p = (ShapefileTools.Point)shapefile.Shapes[pointIndex];
                if (p.Attributes.ItemArray.GetLength(0) > 0)
                {
                    TourPlace place = new TourPlace(p.Attributes.ItemArray[0].ToString(), p.Y, p.X, Classification.Unidentified, "", ImageSetType.Earth, -1);

                    Dictionary <String, String> rowData = new Dictionary <string, string>();
                    for (int r = 0; r < p.Attributes.ItemArray.GetLength(0); r++)
                    {
                        rowData.Add(p.Attributes.Table.Columns[r].ColumnName, p.Attributes.ItemArray[r].ToString());
                    }
                    place.Tag = rowData;
                    return(place);
                }
            }
            return(closestPlace);
        }