]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/threedee/ThreeDModel.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / threedee / ThreeDModel.java
index 141ec38a88d8656e18110e68181bb238b99f170c..2c9ac97784e79f24e2c378766283720e354c8a15 100644 (file)
@@ -14,20 +14,18 @@ public class ThreeDModel
 {
        private Track _track = null;
        private PointScaler _scaler = null;
-       private double _modelSize;
-       private int _altitudeCap = -1;
        private double _scaleFactor = 1.0;
        private double _altFactor = 1.0;
-       // TODO: How to store rods (lifts) in data?
+       // MAYBE: How to store rods (lifts) in data?
        private byte[] _pointTypes = null;
        private byte[] _pointHeights = null;
 
-       private static final double DEFAULT_MODEL_SIZE = 10.0;
-       public static final int MINIMUM_ALTITUDE_CAP = 100;
+       private static final double MODEL_SIZE = 10.0;
 
        // Constants for point types
-       public static final byte POINT_TYPE_WAYPOINT = 1;
-       public static final byte POINT_TYPE_NORMAL_POINT = 2;
+       public static final byte POINT_TYPE_WAYPOINT      = 1;
+       public static final byte POINT_TYPE_NORMAL_POINT  = 2;
+       public static final byte POINT_TYPE_SEGMENT_START = 3;
 
 
        /**
@@ -35,21 +33,8 @@ public class ThreeDModel
         * @param inTrack Track object
         */
        public ThreeDModel(Track inTrack)
-       {
-               this(inTrack, DEFAULT_MODEL_SIZE);
-       }
-
-
-       /**
-        * Constructor
-        * @param inTrack Track object
-        * @param inSize model size
-        */
-       public ThreeDModel(Track inTrack, double inSize)
        {
                _track = inTrack;
-               _modelSize = inSize;
-               if (_modelSize <= 0.0) _modelSize = DEFAULT_MODEL_SIZE;
        }
 
 
@@ -62,21 +47,16 @@ public class ThreeDModel
                return _track.getNumPoints();
        }
 
-
        /**
-        * Set the altitude cap
-        * @param inAltitudeCap altitude range to cap to (ignored if less than data range)
+        * @param inFactor altitude exaggeration factor (default 1.0)
         */
-       public void setAltitudeCap(int inAltitudeCap)
+       public void setAltitudeFactor(double inFactor)
        {
-               _altitudeCap = inAltitudeCap;
-               if (_altitudeCap < MINIMUM_ALTITUDE_CAP)
-               {
-                       _altitudeCap = MINIMUM_ALTITUDE_CAP;
+               if (inFactor >= 1.0) {
+                       _altFactor = inFactor;
                }
        }
 
-
        /**
         * Scale all points and calculate factors
         */
@@ -92,29 +72,19 @@ public class ThreeDModel
                        if (_scaler.getMaximumHoriz() > _scaler.getMaximumVert())
                        {
                                // scale limited by longitude
-                               _scaleFactor = _modelSize / _scaler.getMaximumHoriz();
+                               _scaleFactor = MODEL_SIZE / _scaler.getMaximumHoriz();
                        }
                        else
                        {
                                // scale limited by latitude
-                               _scaleFactor = _modelSize / _scaler.getMaximumVert();
+                               _scaleFactor = MODEL_SIZE / _scaler.getMaximumVert();
                        }
                }
-               // calculate altitude scale factor
-               _altFactor = 1.0;
-               if (_scaler.getMaximumAlt() >= 0)
-               {
-                       // limit by altitude cap or by data range?
-                       if (_scaler.getMaximumAlt() > _altitudeCap)
-                       {
-                               // data is bigger than cap
-                               _altFactor = _modelSize / _scaler.getMaximumAlt();
-                       }
-                       else
-                       {
-                               // capped
-                               _altFactor = _modelSize / _altitudeCap;
-                       }
+               // cap altitude scale factor if it's too big
+               double maxScaledAlt = _scaler.getMaxScaledAlt() * _altFactor;
+               if (maxScaledAlt > MODEL_SIZE) {
+                       // capped
+                       _altFactor = _altFactor * MODEL_SIZE / maxScaledAlt;
                }
                // calculate lat/long lines
                _scaler.calculateLatLongLines();
@@ -136,8 +106,9 @@ public class ThreeDModel
                for (int i=0; i<numPoints; i++)
                {
                        DataPoint point = _track.getPoint(i);
-                       _pointTypes[i] = (point.isWaypoint()?POINT_TYPE_WAYPOINT:POINT_TYPE_NORMAL_POINT);
-                       _pointHeights[i] = (byte) (point.getAltitude().getValue(Altitude.FORMAT_METRES) / 500);
+                       _pointTypes[i] = (point.isWaypoint()?POINT_TYPE_WAYPOINT:
+                               (point.getSegmentStart()?POINT_TYPE_SEGMENT_START:POINT_TYPE_NORMAL_POINT));
+                       _pointHeights[i] = (byte) (point.getAltitude().getValue(Altitude.Format.METRES) / 500);
                }
        }
 
@@ -170,9 +141,9 @@ public class ThreeDModel
        public double getScaledAltValue(int inIndex)
        {
                // if no altitude, just return 0
-               int altVal = _scaler.getAltValue(inIndex);
+               double altVal = _scaler.getAltValue(inIndex);
                if (altVal < 0) return 0;
-               // scale according to altitude cap
+               // scale according to exaggeration factor
                return altVal * _altFactor;
        }
 
@@ -234,6 +205,6 @@ public class ThreeDModel
         */
        public double getModelSize()
        {
-               return _modelSize;
+               return MODEL_SIZE;
        }
 }