From 1ba87a7b4f9afeecffd7418772ccf53696dea0ec Mon Sep 17 00:00:00 2001 From: erik Date: Sat, 26 Sep 2009 13:50:09 +0000 Subject: [PATCH] --- .../org/wamblee/gps/track/FilteredTrack.java | 3 +- .../java/org/wamblee/gps/track/TrackImpl.java | 7 +- .../java/org/wamblee/gpx/TrackStatistics.java | 88 ++++++++++--------- 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java b/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java index ddcaa496..46e969d8 100644 --- a/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java +++ b/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java @@ -1,5 +1,6 @@ package org.wamblee.gps.track; +import java.io.Serializable; import java.util.List; import org.wamblee.gps.geometry.Point; @@ -8,7 +9,7 @@ import org.wamblee.gps.geometry.Point; * Filtered track provides a filtered view on a track. * Changes in the filter are also represented by the filtered track. */ -public class FilteredTrack implements Track { +public class FilteredTrack implements Track, Serializable { private TrackFilter _filter; private Track _originalTrack; diff --git a/gps/src/main/java/org/wamblee/gps/track/TrackImpl.java b/gps/src/main/java/org/wamblee/gps/track/TrackImpl.java index 12513f3e..ce8e23e3 100644 --- a/gps/src/main/java/org/wamblee/gps/track/TrackImpl.java +++ b/gps/src/main/java/org/wamblee/gps/track/TrackImpl.java @@ -1,12 +1,13 @@ package org.wamblee.gps.track; +import java.io.Serializable; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.wamblee.gps.geometry.Point; -public class TrackImpl implements Track { +public class TrackImpl implements Track, Serializable { private String _description; private List _segments; @@ -50,7 +51,7 @@ public class TrackImpl implements Track { result = Math.min(result, segment.getMinCoordinate(i)); } } - return 0; + return result; } @Override @@ -64,7 +65,7 @@ public class TrackImpl implements Track { result = Math.max(result, segment.getMaxCoordinate(i)); } } - return 0; + return result; } @Override diff --git a/gps/src/main/java/org/wamblee/gpx/TrackStatistics.java b/gps/src/main/java/org/wamblee/gpx/TrackStatistics.java index 455ca985..964ac6eb 100644 --- a/gps/src/main/java/org/wamblee/gpx/TrackStatistics.java +++ b/gps/src/main/java/org/wamblee/gpx/TrackStatistics.java @@ -20,70 +20,74 @@ import org.wamblee.gps.geometry.ReferenceCoordinateSystem; import org.wamblee.gps.track.TrackSegment; public class TrackStatistics implements Serializable { - - private TrackSegment _track; - + + private TrackSegment _track; + public TrackStatistics(TrackSegment aTrack) { - _track = aTrack; + _track = aTrack; } - - public void writeHeightProfilePng(OutputStream aStream, int aWidth, int aHeight) throws IOException { - List> data = computeElevationProfile(); + + public void writeHeightProfilePng(OutputStream aStream, int aWidth, + int aHeight) throws IOException { + List> data = computeElevationProfile(); XYSeriesCollection dataset = createDataset(data, "height"); - JFreeChart chart = ChartFactory.createXYLineChart( - "Height Profile", - "Distance(km)", - "Height(m)", - dataset, - PlotOrientation.VERTICAL, - true, - true, - false); + JFreeChart chart = ChartFactory.createXYLineChart("Height Profile", + "Distance(km)", "Height(m)", dataset, PlotOrientation.VERTICAL, + true, true, false); chart.setBackgroundPaint(Color.WHITE); ChartUtilities.writeChartAsPNG(aStream, chart, aWidth, aHeight); } - - private static XYSeriesCollection createDataset(List> aHeightProfile, String aName) { + + private static XYSeriesCollection createDataset( + List> aHeightProfile, String aName) { XYSeries series = new XYSeries(aName, false); - for (Pair point: aHeightProfile) { - series.add(point.getFirst()/1000.0, point.getSecond()); + for (Pair point : aHeightProfile) { + series.add(point.getFirst() / 1000.0, point.getSecond()); } XYSeriesCollection dataset = new XYSeriesCollection(series); return dataset; } - + public List> computeElevationProfile() { - List> results = new ArrayList>(); - double distance = 0.0; - for (int i = 0; i < _track.size(); i++) { + List> results = new ArrayList>(); + double distance = 0.0; + for (int i = 0; i < _track.size(); i++) { Point point = _track.getPoint(i); - results.add(new Pair(distance, point.getCoordinates().getX3())); - if ( i+1 < _track.size()) { - Point nextPoint = _track.getPoint(i+1); - distance += ReferenceCoordinateSystem.distance(point, nextPoint); + results.add(new Pair(distance, point + .getCoordinates().getX3())); + if (i + 1 < _track.size()) { + Point nextPoint = _track.getPoint(i + 1); + distance += ReferenceCoordinateSystem + .distance(point, nextPoint); } } - return results; + return results; } - + public double getTotalClimb() { - - List> data = computeElevationProfile(); + + List> data = computeElevationProfile(); double result = 0.0; - + if ( data.size() == 0 ) { + return result; + } + double lastHeight = data.get(0).getSecond(); - for ( int i = 1; i < data.size(); i++) { + for (int i = 1; i < data.size(); i++) { double height = data.get(i).getSecond(); - if ( height > lastHeight) { - result += (height-lastHeight); + if (height > lastHeight) { + result += (height - lastHeight); } - lastHeight = height; + lastHeight = height; } - return result; + return result; } - - public double getDistance() { - List> data = computeElevationProfile(); - return data.get(data.size()-1).getFirst(); + + public double getDistance() { + List> data = computeElevationProfile(); + if (data.size() == 0) { + return 0.0; + } + return data.get(data.size() - 1).getFirst(); } } -- 2.31.1