1 package tim.prune.gui.colour;
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Track;
7 import tim.prune.data.TrackInfo;
10 * Colourer based on altitude values
12 public class AltitudeColourer extends ContinuousPointColourer
16 * @param inStartColour start colour
17 * @param inEndColour end colour
19 public AltitudeColourer(Color inStartColour, Color inEndColour)
21 super(inStartColour, inEndColour);
25 public void calculateColours(TrackInfo inTrackInfo)
27 Track track = inTrackInfo == null ? null : inTrackInfo.getTrack();
28 final int numPoints = track == null ? 0 : track.getNumPoints();
29 DataPoint point = null;
31 // Figure out altitude range
32 double minAltitude = 0.0;
33 double maxAltitude = 0.0;
34 boolean altFound = false;
35 for (int i=0; i<numPoints; i++)
37 point = track.getPoint(i);
38 if (point != null && point.hasAltitude())
40 double altValue = point.getAltitude().getMetricValue();
41 if (altValue < minAltitude || !altFound) {minAltitude = altValue;}
42 if (altValue > maxAltitude || !altFound) {maxAltitude = altValue;}
47 if ((maxAltitude - minAltitude) < 1.0)
49 // not enough altitude range, set all to null
54 // initialise the array to the right size
56 // loop over track points to calculate colours
57 for (int i=0; i<numPoints; i++)
59 point = track.getPoint(i);
60 if (point != null && point.hasAltitude() && !point.isWaypoint())
62 double altValue = point.getAltitude().getMetricValue();
63 double fraction = (altValue - minAltitude) / (maxAltitude - minAltitude);
64 setColour(i, mixColour((float) fraction));
66 else setColour(i, null);