Ejemplo n.º 1
0
        private void GenGraphData(List <Point> activeSegPts)
        {
            double disM = 0, prevHgt = 0;
            double prevDis = 0;

            GraphData.Clear();

            const double peakTolerance     = 100;
            const double distanceTolerance = 400;

            for (var c = 0; c != _slicesCalc.Count - 1; ++c)
            {
                for (var i = _slicesCalc[c].NPoint; i < _slicesCalc[c + 1].NPoint; ++i)
                {
                    disM += Geo.DistanceExactMeters(activeSegPts[i], activeSegPts[i + 1]);
                    var hgt = _srtmRepository.GetHeightForPoint(activeSegPts[i + 1]);

                    if (!hgt.HasValue)
                    {
                        continue;
                    }

                    if (i == _slicesCalc[c + 1].NPoint - 1 || (c == 0 && i == _slicesCalc[c].NPoint))
                    {
                        GraphData.SectionLabels.Add(new KeyValuePair <double, double>(disM, hgt.Value));
                    }

                    if (i == _slicesCalc[c].NPoint || Math.Abs(prevHgt - hgt.Value) > peakTolerance || Math.Abs(prevDis - disM) > distanceTolerance)
                    {
                        GraphData.Profile.Add(new KeyValuePair <double, double>(disM, hgt.Value));
                        prevDis = disM;
                        prevHgt = hgt.Value;
                    }
                }
            }

            GraphData.NotifyOnDataUpdateFinished();
        }
Ejemplo n.º 2
0
        public async Task <bool> CreateReportAsync()
        {
            var activeSeg    = Source.ActiveSeg;
            var activeSegPts = activeSeg?.Pts;

            Results.Clear();
            Totals.Recalculate();

            if (Source.AreHeightmapsMissing)
            {
                Source.RegisterError(Resources.TrackReportVm_CreateReportAsync_ErrNoHeightmap);
                return(false);
            }

            if (activeSegPts == null)
            {
                Source.RegisterError(Resources.TrackReportVm_CreateReportAsync_ErrNoTrack);
                return(false);
            }

            if (activeSegPts.Count < 2)
            {
                Source.RegisterError(Resources.TrackReportVm_CreateReportAsync_ErrNoPointsInTrack);
                return(false);
            }

            var points = FilterSlicepts();

            if (points.Count < 2)
            {
                Source.RegisterError(Resources.TrackReportVm_CreateReportAsync_ErrNotEnoughPoints);
                return(false);
            }

            // everything is ok, can calculate [17/12/2009 LysakA]
            _slicesCalc = new List <TrackSeg.Slice>();

            _loggingService.Log(Resources.TrackReportVm_CreateReportAsync_SplittingTrack);

            foreach (var pt in points)
            {
                var slice = Geo.SliceTrackSegmentWithPoint(pt, activeSegPts, _configuration.ReportGeneratorOptions.SliceptKickOutRadiusMeters);

                if (null != slice)
                {
                    _slicesCalc.Add(slice);
                }
            }

            // order by slice connection point [17/12/2009 LysakA]
            _slicesCalc.Sort((slc1, slc2) => slc1.NPoint - slc2.NPoint);

            // delete blind slices [17/12/2009 LysakA]
            for (var c = 0; c < _slicesCalc.Count - 1; ++c)
            {
                if (_slicesCalc[c].NPoint == _slicesCalc[c + 1].NPoint)
                {
                    _slicesCalc.Remove(_slicesCalc[c]);
                    c = 0;
                }
            }

            if (!_slicesCalc.Any())
            {
                _loggingService.LogError(Resources.TrackReportVm_CreateReportAsync_ErrSplitEmptyCantContinue);
                return(false);
            }

            _loggingService.Log(Resources.TrackReportVm_CreateReportAsync_RefiningSplit);
            // shift start & end to track start & end [18/12/2009 LysakA]
            if (Geo.DistanceExactMeters(_slicesCalc.First().SlicePoint, activeSegPts.First()) <
                StartEndCapDistance)
            {
                _slicesCalc.First().NPoint = 0;
            }
            if (Geo.DistanceExactMeters(_slicesCalc.Last().SlicePoint, activeSegPts.Last()) <
                StartEndCapDistance)
            {
                _slicesCalc.Last().NPoint = activeSegPts.Count - 1;
            }

            if (_slicesCalc.First().NPoint != 0) //Cap start
            {
                _slicesCalc.Insert(0, new TrackSeg.Slice {
                    NPoint = 0
                });                                                  //Start -- 0
            }
            if (_slicesCalc.Last().NPoint != activeSegPts.Count - 1) //Cap end
            {
                _slicesCalc.Add(new TrackSeg.Slice
                {
                    NPoint = activeSegPts.Count - 1
                }); //Last -- Finish
            }
            _loggingService.Log(Resources.TrackReportVm_CreateReportAsync_DeltaCalculation);

            for (var npoint = 0; npoint != _slicesCalc.Count - 1; ++npoint)
            {
                var reportItem = _reportItemGenerator(Source);

                reportItem.CalculateGeoProperties(npoint, activeSegPts, _slicesCalc);

                Results.Add(reportItem);
            }

            GenBackpackWeightColumn();

            GenGraphData(activeSegPts);

            // check for bad heights; [22/12/2009 LysakA]
            foreach (var s in _srtmRepository.LoadedSrtms)
            {
                if (s.HasVoids)
                {
                    _loggingService.LogError(
                        string.Format(Resources.TrackReportVm_CreateReportAsync_ErrHeightmapInvalid, s.OriginalFilename, s.OriginalFilename));
                }
            }

            Totals.Recalculate();

            return(true);
        }