Example #1
0
        private void InitializeRoute(RenderContext 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   = Vector3d.SubtractVectors(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();
                // v.Multiply(1.1);
                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;
            }
        }
Example #2
0
 public override void CleanUp()
 {
     if (triangleList != null)
     {
         triangleList.Clear();
     }
     triangleList = null;
     base.CleanUp();
 }
Example #3
0
 public static void PrepBatch(RenderContext renderContext)
 {
     if (PointList == null || BatchDirty)
     {
         PointList                  = new PointList(renderContext);
         LineList                   = new LineList();
         TriangleList               = new TriangleList();
         LineList.DepthBuffered     = false;
         TriangleList.DepthBuffered = false;
     }
 }
Example #4
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    //todo can we save this work for later?
                    List <Vector3d> vertexList = points;


                    if (strokeWidth > 0 && points.Count > 1)
                    {
                        for (int i = 0; i < (points.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[points.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
Example #5
0
        public override void Draw(RenderContext renderContext)
        {
            bool   onScreen = true;
            double rad      = radius;

            if (skyRelative)
            {
                rad /= renderContext.FovScale / 3600;
            }
            Vector3d screenSpacePnt = renderContext.WVP.Transform(center);

            if (screenSpacePnt.Z < 0)
            {
                onScreen = false;
            }

            if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, center) < .55)
            {
                onScreen = false;
            }

            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    Vector3d up = Vector3d.Create(0, 1, 0);

                    Vector3d xNormal = Vector3d.Cross(center, up);

                    Vector3d yNormal = Vector3d.Cross(center, xNormal);

                    double r = radius / 44;

                    int segments = 72;

                    double          radiansPerSegment = Math.PI * 2 / segments;
                    List <Vector3d> vertexList        = new List <Vector3d>();

                    for (int j = 0; j <= segments; j++)
                    {
                        double x = Math.Cos(j * radiansPerSegment) * r;
                        double y = Math.Sin(j * radiansPerSegment) * r;

                        vertexList.Add(Vector3d.Create(center.X + x * xNormal.X + y * yNormal.X, center.Y + x * xNormal.Y + y * yNormal.Y, center.Z + x * xNormal.Z + y * yNormal.Z));
                    }

                    if (strokeWidth > 0 && vertexList.Count > 1)
                    {
                        for (int i = 0; i < (vertexList.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[vertexList.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                if (onScreen)
                {
                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();
                    ctx.Alpha = Opacity;
                    ctx.BeginPath();
                    ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true);
                    ctx.LineWidth = strokeWidth;
                    ctx.FillStyle = fillColor.ToString();
                    if (fill)
                    {
                        ctx.Fill();
                    }
                    ctx.Alpha       = 1.0;
                    ctx.StrokeStyle = lineColor.ToString();
                    ctx.Stroke();

                    ctx.Restore();
                }
            }
        }
        private void InitializeRoute(RenderContext 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 = Vector3d.SubtractVectors(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();
               // v.Multiply(1.1);
                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;

            }
        }
 public override void CleanUp()
 {
     if (triangleList != null)
     {
         triangleList.Clear();
     }
     triangleList = null;
     base.CleanUp();
 }
        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);
        }