예제 #1
0
        private void AddPolygon(bool sky, KmlLineList geo, float lineWidth, Color polyColor, Color lineColor, bool extrude, bool fill, Dates date)
        {
            //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.GeoTo3dDoubleRad(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / meanRadius)));
                vertexListGround.Add(Coordinates.GeoTo3dDoubleRad(geo.PointList[i].Lat, geo.PointList[i].Lng, 1));
            }


            for (int i = 0; i < (geo.PointList.Count - 1); i++)
            {
                if (sky)
                {
                    //tdo reenable this
                    //this.lineList2d.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, date);
                }
                else
                {
                    if (extrude)
                    {
                        this.triangleList.AddQuad(vertexList[i], vertexList[i + 1], vertexListGround[i], vertexListGround[i + 1], polyColor, date);
                    }
                    if (lineWidth > 0)
                    {
                        if (extrude)
                        {
                            this.lineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, date);
                        }
                        else
                        {
                            this.lineList2d.AddLine(vertexList[i], vertexList[i + 1], lineColor, date);
                        }
                        if (extrude)
                        {
                            this.lineList.AddLine(vertexListGround[i], vertexListGround[i + 1], lineColor, date);
                            this.lineList.AddLine(vertexList[i], vertexListGround[i], lineColor, date);
                            this.lineList.AddLine(vertexList[i + 1], vertexListGround[i + 1], lineColor, date);
                        }
                    }
                }
            }
            if (fill)
            {
                List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                for (int i = 0; i < indexes.Count; i += 3)
                {
                    this.triangleList.AddTriangle(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], polyColor, date);
                }
            }
        }
예제 #2
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 * y < 0 ? -1 : 1;
                }
                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.GeoTo3dDoubleRad(lat, 90 + lng + meridean, radius));
        }
예제 #3
0
        private void AddPolygonFlat(bool sky, KmlLineList geo, float lineWidth, Color polyColor, Color lineColor, bool extrude, bool fill, Dates date)
        {
            //todo can we save this work for later?
            List <Vector3d> vertexList = new List <Vector3d>();

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


            for (int i = 0; i < (geo.PointList.Count - 1); i++)
            {
                if (sky)
                {
                    //this.lineList2d.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, date);
                }
                else
                {
                    if (lineWidth > 0)
                    {
                        this.lineList2d.AddLine(vertexList[i], vertexList[i + 1], lineColor, date);
                    }
                }
            }
            if (fill)
            {
                List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                for (int i = 0; i < indexes.Count; i += 3)
                {
                    this.triangleList2d.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], polyColor, date, 2);
                }
            }
        }
예제 #4
0
        protected override bool PrepVertexBuffer(RenderContext renderContext, float opacity)
        {
            table.Lock();
            if (lineList != null)
            {
                lineList.Clear();
            }

            if (lineList2d != null)
            {
                lineList2d.Clear();
            }

            if (triangleList != null)
            {
                triangleList.Clear();
            }

            if (pointList != null)
            {
                pointList.Clear();
            }


            if (triangleList2d != null)
            {
                triangleList2d.Clear();
            }

            if (lineList == null)
            {
                lineList = new LineList();
            }

            if (pointList == null)
            {
                pointList = new PointList(renderContext);
            }

            lineList.TimeSeries = this.timeSeries;

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

            lineList.TimeSeries = this.timeSeries;



            if (triangleList == null)
            {
                triangleList = new TriangleList();
            }

            if (triangleList2d == null)
            {
                triangleList2d = new TriangleList();
                triangleList2d.DepthBuffered = false;
            }



            positions.Clear();
            UInt32 currentIndex = 0;
            //   device.RenderState.FillMode = FillMode.WireFrame;
            Color colorLocal = Color;

            // colorLocal.A = (byte)(Color.A * Opacity);

            // for space 3d
            double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI;



            Dictionary <string, bool> selectDomain = new Dictionary <string, bool>();


            double mr = 0;

            //    double mr = LayerManager.AllMaps[ReferenceFrame].Frame.MeanRadius;
            if (mr != 0)
            {
                meanRadius = mr;
            }

            Vector3d position       = new Vector3d();
            float    pointSize      = .0002f;
            Color    pointColor     = Colors.White;
            float    pointStartTime = 0;
            float    pointEndTime   = 0;

            foreach (string[] row in table.Rows)
            {
                try
                {
                    bool selected = false;

                    if (geometryColumn > -1 || (this.CoordinatesType == CoordinatesTypes.Spherical && (lngColumn > -1 && latColumn > -1)) || ((this.CoordinatesType == CoordinatesTypes.Rectangular) && (XAxisColumn > -1 && YAxisColumn > -1)))
                    {
                        double Xcoord = 0;
                        double Ycoord = 0;
                        double Zcoord = 0;

                        double alt        = 1;
                        double altitude   = 0;
                        double distParces = 0;
                        double factor     = GetScaleFactor(AltUnit, 1);
                        if (altColumn == -1 || AltType == AltTypes.SeaLevel || bufferIsFlat)
                        {
                            alt = 1;
                            if (astronomical & !bufferIsFlat)
                            {
                                alt = UiTools.AuPerLightYear * 100;
                            }
                        }
                        else
                        {
                            if (AltType == AltTypes.Depth)
                            {
                                factor = -factor;
                            }

                            alt = 0;
                            try
                            {
                                alt = double.Parse(row[altColumn]);
                            }
                            catch
                            {
                            }

                            if (astronomical)
                            {
                                factor     = factor / (1000 * UiTools.KilometersPerAu);
                                distParces = (alt * factor) / UiTools.AuPerParsec;

                                altitude = (factor * alt);
                                alt      = (factor * alt);
                            }
                            else if (AltType == AltTypes.Distance)
                            {
                                altitude = (factor * alt);
                                alt      = (factor * alt / meanRadius);
                            }
                            else
                            {
                                altitude = (factor * alt);
                                alt      = 1 + (factor * alt / meanRadius);
                            }
                        }

                        //todo remove hack when alt is fixed
                        //alt = 1;

                        if (CoordinatesType == CoordinatesTypes.Spherical && lngColumn > -1 && latColumn > -1)
                        {
                            //Xcoord = Coordinates.Parse(row[lngColumn]);
                            //Ycoord = Coordinates.Parse(row[latColumn]);
                            Xcoord = double.Parse(row[lngColumn]);
                            Ycoord = double.Parse(row[latColumn]);

                            if (astronomical)
                            {
                                if (RaUnits == RAUnits.Hours)
                                {
                                    Xcoord *= 015;
                                }
                                if (bufferIsFlat)
                                {
                                    //   Xcoord += 180;
                                }
                            }
                            double offset = 0; //todo EGM96Geoid.Height(Ycoord, Xcoord);
                            //   if (altitude != 0)
                            {
                                //altitude += offset;
                                //alt += offset / meanRadius;
                            }
                            Vector3d pos = Coordinates.GeoTo3dDoubleRad(Ycoord, Xcoord, alt);

                            if (astronomical && !bufferIsFlat)
                            {
                                pos.RotateX(ecliptic);
                            }

                            position = pos;

                            positions.Add(position);
                        }
                        else if (this.CoordinatesType == CoordinatesTypes.Rectangular)
                        {
                            double xyzScale = GetScaleFactor(CartesianScale, CartesianCustomScale) / meanRadius;

                            if (ZAxisColumn > -1)
                            {
                                Zcoord = double.Parse(row[ZAxisColumn]);
                            }

                            Xcoord = double.Parse(row[XAxisColumn]);
                            Ycoord = double.Parse(row[YAxisColumn]);

                            if (XAxisReverse)
                            {
                                Xcoord = -Xcoord;
                            }
                            if (YAxisReverse)
                            {
                                Ycoord = -Ycoord;
                            }
                            if (ZAxisReverse)
                            {
                                Zcoord = -Zcoord;
                            }


                            position = Vector3d.Create((Xcoord * xyzScale), (Zcoord * xyzScale), (Ycoord * xyzScale));
                            positions.Add(position);
                        }

                        // SqlGeometry pntGeo = SqlGeometry.Point(Xcoord,Ycoord, 4326);


                        //// SqlGeometry pntGeo = SqlGeometry.Point(new SqlChars(String.Format("Point ({0} {1})", Xcoord,Ycoord).ToCharArray()), 4326);


                        // if (!geo.STContains(pntGeo))
                        // {
                        //     continue;
                        // }

                        switch (ColorMap)
                        {
                        case ColorMaps.Same_For_All:
                            pointColor = colorLocal;
                            break;

                        case ColorMaps.Per_Column_Literal:
                            if (ColorMapColumn > -1)
                            {
                                pointColor = ParseColor(row[ColorMapColumn], colorLocal);
                            }
                            else
                            {
                                pointColor = colorLocal;
                            }
                            break;
                        //case ColorMaps.Group_by_Range:
                        //    break;
                        //case ColorMaps.Gradients_by_Range:
                        //    break;
                        //case ColorMaps.Group_by_Values:
                        //    pointColor = ColorDomainValues[row[ColorMapColumn]].MarkerIndex;
                        //    break;

                        default:
                            break;
                        }


                        if (sizeColumn > -1)
                        {
                            switch (pointScaleType)
                            {
                            case PointScaleTypes.Linear:
                                pointSize = Single.Parse(row[sizeColumn]);
                                break;

                            case PointScaleTypes.Log:
                                pointSize = (float)Math.Log(Single.Parse(row[sizeColumn]));
                                break;

                            case PointScaleTypes.Power:
                            {
                                double size = 0;

                                try
                                {
                                    pointSize = (float)double.Parse(row[altColumn]);
                                }
                                catch
                                {
                                    pointSize = 0;
                                }
                            }
                            break;

                            case PointScaleTypes.StellarMagnitude:
                            {
                                double size = 0;
                                try
                                {
                                    size = double.Parse(row[sizeColumn]);

                                    if (!bufferIsFlat)
                                    {
                                        size      = size - 5 * ((Util.LogN(distParces, 10) - 1));
                                        pointSize = (float)(120000000 / Math.Pow(1.6, size));
                                    }
                                    else
                                    {
                                        pointSize = (float)(40 / Math.Pow(1.6, size));
                                    }
                                }
                                catch
                                {
                                    pointSize = 0;
                                }
                            }
                            break;

                            case PointScaleTypes.Constant:
                                pointSize = 1;
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            pointSize = (float)1;
                        }
                        if (PlotType == PlotTypes.Point)
                        {
                            pointSize = (float)1;
                        }

                        if (astronomical & !bufferIsFlat)
                        {
                            //  lastItem.PointSize *= 1000000000000000000000000000f;
                        }


                        if (startDateColumn > -1)
                        {
                            Date dateTime = new Date(row[startDateColumn]);
                            pointStartTime = (float)(SpaceTimeController.UtcToJulian(dateTime) - SpaceTimeController.UtcToJulian(baseDate));

                            if (endDateColumn > -1)
                            {
                                dateTime = new Date(row[endDateColumn]);
                                //dateTime = DateTime.Parse(row[endDateColumn]);
                                pointEndTime = (float)(SpaceTimeController.UtcToJulian(dateTime) - SpaceTimeController.UtcToJulian(baseDate));
                            }
                            else
                            {
                                pointEndTime = pointStartTime;
                            }
                        }

                        pointList.AddPoint(position, pointColor, new Dates(pointStartTime, pointEndTime), pointSize);


                        if (geometryColumn > -1)
                        {
                            ParseGeometry(row[geometryColumn], pointColor, pointColor, altitude, new Dates(pointStartTime, pointEndTime));
                        }

                        //if (barChartBitmask != 0)
                        //{
                        //    MakeBarChart(device, row, Ycoord, Xcoord, pointSize, factor, Color.FromArgb(lastItem.Color), selected, new Dates(pointStartTime, pointEndTime));
                        //}


                        currentIndex++;
                    }
                }
                catch
                {
                }
                lines = false;
            }


            table.Unlock();
            dataDirty = false;
            dirty     = false;
            return(false);
        }