X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPointScaler.java;h=a1338857e0c509acc6a3d6227f4044080e3f2914;hb=7f5ed2be62905bd37717376dc22d09e5ea7edb4d;hp=4d2290f0b5e0f6b26f9dea13850efcf9d9db585d;hpb=23959e65a6a0d581e657b07186d18b7a1ac5afeb;p=GpsPrune.git diff --git a/tim/prune/data/PointScaler.java b/tim/prune/data/PointScaler.java index 4d2290f..a133885 100644 --- a/tim/prune/data/PointScaler.java +++ b/tim/prune/data/PointScaler.java @@ -1,42 +1,19 @@ package tim.prune.data; /** - * Class to manage the scaling of points + * Class to manage the scaling of points, used by the ThreeDModel */ public class PointScaler { // Original data private Track _track = null; - // Range information - private AltitudeRange _altRange = null; - private DoubleRange _latRange = null; - private DoubleRange _lonRange = null; - private double _latMedian = 0.0; - private double _lonMedian = 0.0; - private int _minAltitude = 0; - private int _maxAltitude = 0; - // Scaling information - private double _longFactor = 0.0; - // Scaled points + // Scaled values private double[] _xValues = null; private double[] _yValues = null; - private int[] _altValues = null; - private double _maxX = 0.0; - private double _maxY = 0.0; - // lat/long lines - private double[] _latLinesDegs = null; - private double[] _lonLinesDegs = null; - private double[] _latLinesScaled = null; - private double[] _lonLinesScaled = null; + private double[] _altValues = null; + // Altitude range + private double _altitudeRange = 0.0; - // Constants - private static final double[] COORD_SEPARATIONS = { - 1.0, // 1deg - 30.0/60.0, 20.0/60.0, // 30min, 20min - 10.0/60.0, 5.0/60.0, // 10min, 5min - 3.0/60.0, 2.0/60.0, 1.0/60.0 // 3min, 2min, 1min - }; - private static final int MAX_COORD_SEPARATION_INDEX = COORD_SEPARATIONS.length - 1; /** * Constructor @@ -45,9 +22,6 @@ public class PointScaler public PointScaler(Track inTrack) { _track = inTrack; - _altRange = new AltitudeRange(); - _latRange = new DoubleRange(); - _lonRange = new DoubleRange(); } @@ -56,71 +30,42 @@ public class PointScaler */ public void scale() { - // Clear data - _altRange.clear(); - _latRange.clear(); - _lonRange.clear(); - int numPoints = 0; - int p = 0; - DataPoint point = null; - // Find limits of data - if (_track != null && (numPoints = _track.getNumPoints()) > 0) + // Work out extents + TrackExtents extents = new TrackExtents(_track); + extents.applySquareBorder(); + final double horizDistance = Math.max(extents.getHorizontalDistanceMetres(), 1.0); + final int numPoints = _track.getNumPoints(); + + // Find altitude range + _altitudeRange = extents.getAltitudeRange().getRange() / horizDistance; + final double minAltitude = extents.getAltitudeRange().getMinimum(); + + // create new arrays for scaled values + if (_xValues == null || _xValues.length != numPoints) { - for (p=0; p getMaximumVert() ? - getMaximumHoriz():getMaximumVert(); - // calculate boundaries in degrees - double minLong = getUnscaledLongitude(-maxValue); - double maxLong = getUnscaledLongitude(maxValue); - double minLat = getUnscaledLatitude(-maxValue); - double maxLat = getUnscaledLatitude(maxValue); - // work out what line separation to use to give at least two lines - int sepIndex = -1; - double separation; - int numLatLines = 0, numLonLines = 0; - do - { - sepIndex++; - separation = COORD_SEPARATIONS[sepIndex]; - numLatLines = getNumLinesBetween(minLat, maxLat, separation); - numLonLines = getNumLinesBetween(minLong, maxLong, separation); - } - while ((numLonLines <= 1 || numLatLines <= 1) && sepIndex < MAX_COORD_SEPARATION_INDEX); - // create lines based on this separation - _latLinesDegs = getLines(minLat, maxLat, separation, numLatLines); - _lonLinesDegs = getLines(minLong, maxLong, separation, numLonLines); - // scale lines also - _latLinesScaled = new double[numLatLines]; - for (int i=0; i= inMin) numLines++; - value += inSeparation; - } - return numLines; - } - - - /** - * Get the line values in the given range using the specified separation - * @param inMin minimum value - * @param inMax maximum value - * @param inSeparation line separation - * @param inCount number of lines already counted - * @return array of line values - */ - private static double[] getLines(double inMin, double inMax, double inSeparation, int inCount) - { - double[] values = new double[inCount]; - // Start looking from round number of degrees below minimum - double value = (int) inMin; - if (inMin < 0.0) value = value - 1.0; - // Loop until bigger than maximum - int numLines = 0; - while (value < inMax) - { - if (value >= inMin) - { - values[numLines] = value; - numLines++; - } - value += inSeparation; - } - return values; - } - - /** - * @return array of latitude lines in degrees - */ - public double[] getLatitudeLines() - { - return _latLinesDegs; - } - /** - * @return array of longitude lines in degrees - */ - public double[] getLongitudeLines() - { - return _lonLinesDegs; - } - /** - * @return array of latitude lines in scaled units - */ - public double[] getScaledLatitudeLines() - { - return _latLinesScaled; - } - /** - * @return array of longitude lines in scaled units + * @return altitude range, in metres */ - public double[] getScaledLongitudeLines() + public double getAltitudeRange() { - return _lonLinesScaled; + return _altitudeRange; } }