public static Visibility IsPoiVisible(PoiViewItem item, ElevationProfileData elevationProfileData) { if (elevationProfileData == null) { return(Visibility.Visible); } var leftPoints = elevationProfileData.GetData((int)item.GpsLocation.Bearing); var rightPoints = elevationProfileData.GetData((int)GpsUtils.Normalize360(item.GpsLocation.Bearing.Value + 1)); if (leftPoints == null || rightPoints == null) { return(Visibility.Visible); } var maxLeft = new GpsLocation() { VerticalViewAngle = -100, Distance = 100 }; var leftPoints2 = leftPoints.GetPoints().Where(p => p.Distance < item.GpsLocation.Distance); if (leftPoints2.Any()) { maxLeft = leftPoints2.Aggregate((max, item2) => item2?.VerticalViewAngle > max?.VerticalViewAngle ? item2 : max); } var maxRight = new GpsLocation() { VerticalViewAngle = -100, Distance = 100 }; var rightPoints2 = rightPoints.GetPoints().Where(p => p.Distance < item.GpsLocation.Distance); if (rightPoints2.Any()) { maxRight = rightPoints2.Aggregate((max, item2) => item2?.VerticalViewAngle > max?.VerticalViewAngle ? item2 : max); } var maxViewAngle = maxRight.VerticalViewAngle > maxLeft.VerticalViewAngle ? maxRight : maxLeft; var itemViewAngle = item.VerticalViewAngle; var viewAngleDiff = item.VerticalViewAngle - maxViewAngle.VerticalViewAngle; var viewAngleDistance = item.GpsLocation.Distance - maxViewAngle.Distance; var viewAngleVisibilityLimit = -(itemViewAngle * 0.01 + 0.0); var viewAnglePartVisibilityLimit = -(itemViewAngle * 0.2 + 1.0); var distancePartVisibilityLimit = 2000;//m if (viewAngleDiff > viewAngleVisibilityLimit) { return(Visibility.Visible); } if (viewAngleDiff > viewAnglePartVisibilityLimit && viewAngleDistance < distancePartVisibilityLimit) { return(Visibility.PartialyVisible); } return(Visibility.Invisible); }
public void GenerateElevationProfile3(GpsLocation myLocation, double visibility, ElevationProfileData elevationData, Action <int> onProgressChange) { _elevationProfileData = new ElevationProfileData(myLocation, visibility); int progress = 0; foreach (var group in elevationData.GetData()) { progress++; onProgressChange(progress); var points = group.GetPoints() .Where(i => i.Distance > MIN_DISTANCE && i.Distance < visibility * 1000) .OrderBy(i => i.Distance); //Select visible points List <GpsLocation> tmpVisiblePoints = new List <GpsLocation>(); double maxViewAngle = -90; foreach (var point in points) { if (point.VerticalViewAngle > maxViewAngle) { tmpVisiblePoints.Add(point); maxViewAngle = point.VerticalViewAngle.Value; } } //Change order (now from the furthest to the nearest) tmpVisiblePoints.Reverse(); //... and ignore points on descending slope GpsLocation lastPoint = null; GpsLocation lastAddedPoint = null; var ed = new ElevationData(group.Angle); foreach (var point in tmpVisiblePoints) { if (lastPoint == null) { ed.Add(point); lastAddedPoint = point; lastPoint = point; continue; } //TODO: comment-out the folowing if for full rendering var distanceDiff = lastPoint.Distance.Value - point.Distance.Value; if (distanceDiff < lastPoint.Distance / 100 + 50) { lastPoint = point; continue; } ed.Add(point); lastAddedPoint = point; lastPoint = point; } _elevationProfileData.Add(ed); } }
void PaintProfile2(PaintEventArgs e) { List <GpsLocation> lst; if (elevationProfileNew == null) { return; } var pen = new Pen(Brushes.Black, 3); var data = elevationProfileNew.GetData(); for (ushort i = 0; i < 360; i++) { var thisAngle = elevationProfileNew.GetData(i); var prevAngle = elevationProfileNew.GetData(i - 1); if (thisAngle != null && prevAngle != null) { foreach (var point in thisAngle.GetPoints()) { foreach (var otherPoint in prevAngle.GetPoints()) { if (Math.Abs(point.Distance.Value - otherPoint.Distance.Value) < point.Distance / _minDist) { var b1 = GpsUtils.Normalize360(point.Bearing.Value - _heading); var x1 = GpsUtils.Normalize360(b1 + 35) * DG_WIDTH; var y1 = 250 - point.VerticalViewAngle.Value * 40; var b2 = GpsUtils.Normalize360(otherPoint.Bearing.Value - _heading); var x2 = GpsUtils.Normalize360(b2 + 35) * DG_WIDTH; var y2 = 250 - otherPoint.VerticalViewAngle.Value * 40; if (Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2)) < 100) { e.Graphics.DrawLine(pen, (float)x1, (float)y1, (float)x2, (float)y2); } } } } } } }
public void GenerateElevationProfileLines(ElevationProfileData epd, double displayWidth, double displayHeight) { /*foreach(var ed in epd.GetData()) * { * var edMaxDist = ed.GetPoints().Max(p => p.Distance.Value); * if (edMaxDist > maxDist) * { * maxDist = edMaxDist; * } * }*/ List <ProfileLine> listOfLines = new List <ProfileLine>(); for (ushort i = 0; i < 360; i++) { var thisAngle = epd.GetData(i); var prevAngle = epd.GetData(i - 1); if (thisAngle != null && prevAngle != null) { foreach (var point in thisAngle.GetPoints()) { var otherPoint = prevAngle.GetPoints() .Where(x => Math.Abs(point.Distance.Value - x.Distance.Value) <= point.Distance.Value / 12) .OrderBy(x => Math.Abs(point.Distance.Value - x.Distance.Value)) .FirstOrDefault(); if (otherPoint != null) { var y1 = point.VerticalViewAngle.Value; var x1 = (float)point.Bearing.Value; var y2 = otherPoint.VerticalViewAngle.Value; var x2 = (float)otherPoint.Bearing.Value; listOfLines.Add(new ProfileLine { Bearing1 = x1, Bearing2 = x2, VerticalViewAngle1 = (float)y1, VerticalViewAngle2 = (float)y2, distance = point.Distance.Value }); } } } } _context.ListOfProfileLines = listOfLines; }