Ignore:
Timestamp:
2014-10-04T17:28:45+02:00 (10 years ago)
Author:
donvip
Message:

[josm_plugins] fix various compilation warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleVertex.java

    r30344 r30701  
    1010
    1111public class EleVertex {
    12     private static final int NPOINTS = 3;
    13     private static final double MIN_DIST = 90;
    14 
    15     private double avrgEle = Double.NaN;
    16     private double area = Double.NaN;
    17     private final EleCoordinate[] points = new EleCoordinate[NPOINTS];
    18 
    19     public EleVertex(EleCoordinate p1, EleCoordinate p2, EleCoordinate p3) {
    20         points[0] = p1;
    21         points[1] = p2;
    22         points[2] = p3;
    23 
    24         // compute elevation
    25         double z = 0D;
    26         boolean eleValid = true;
    27         for (EleCoordinate point : points) {
    28             if (ElevationHelper.isValidElevation(p1.getEle())) {
    29                 z += point.getEle();
    30             } else {
    31                 eleValid = false;
    32                 break;
    33             }
    34         }
    35 
    36         if (eleValid) {
    37             avrgEle = z / NPOINTS;
    38         } else {
    39             avrgEle = ElevationHelper.NO_ELEVATION;
    40         }
    41 
    42         // compute the (approx.!) area of the vertex using heron's formula
    43         double a = p1.greatCircleDistance(p2);
    44         double b = p2.greatCircleDistance(p3);
    45         double c = p1.greatCircleDistance(p3);
    46 
    47         double s = (a + b + c) / 2D;
    48         double sq = s * (s - a) * (s - b) * (s - c);
    49         area = Math.sqrt(sq);
    50     }
    51 
    52     public List<EleVertex> divide() {
    53         TriangleEdge[] edges = new TriangleEdge[NPOINTS];
    54 
    55         int k = 0;
    56         for (int i = 0; i < points.length; i++) {
    57             EleCoordinate c1 = points[i];
    58 
    59             for (int j = i + 1; j < points.length; j++) {
    60                 EleCoordinate c2 = points[j];
    61 
    62                 edges[k++] = new TriangleEdge(i, j, c1.greatCircleDistance(c2));
    63             }
    64         }
    65 
    66         /*
     12        private static final int NPOINTS = 3;
     13        private static final double MIN_DIST = 90;
     14
     15        private double avrgEle = Double.NaN;
     16        private double area = Double.NaN;
     17        private final EleCoordinate[] points = new EleCoordinate[NPOINTS];
     18
     19        public EleVertex(EleCoordinate p1, EleCoordinate p2, EleCoordinate p3) {
     20                points[0] = p1;
     21                points[1] = p2;
     22                points[2] = p3;
     23
     24                // compute elevation
     25                double z = 0D;
     26                boolean eleValid = true;
     27                for (EleCoordinate point : points) {
     28                        if (ElevationHelper.isValidElevation(p1.getEle())) {
     29                                z += point.getEle();
     30                        } else {
     31                                eleValid = false;
     32                                break;
     33                        }
     34                }
     35
     36                if (eleValid) {
     37                        avrgEle = z / NPOINTS;
     38                } else {
     39                        avrgEle = ElevationHelper.NO_ELEVATION;
     40                }
     41
     42                // compute the (approx.!) area of the vertex using heron's formula
     43                double a = p1.greatCircleDistance(p2);
     44                double b = p2.greatCircleDistance(p3);
     45                double c = p1.greatCircleDistance(p3);
     46
     47                double s = (a + b + c) / 2D;
     48                double sq = s * (s - a) * (s - b) * (s - c);
     49                area = Math.sqrt(sq);
     50        }
     51
     52        public List<EleVertex> divide() {
     53                TriangleEdge[] edges = new TriangleEdge[NPOINTS];
     54
     55                int k = 0;
     56                for (int i = 0; i < points.length; i++) {
     57                        EleCoordinate c1 = points[i];
     58
     59                        for (int j = i + 1; j < points.length; j++) {
     60                                EleCoordinate c2 = points[j];
     61
     62                                edges[k++] = new TriangleEdge(i, j, c1.greatCircleDistance(c2));
     63                        }
     64                }
     65
     66                /*
    6767    for (int i = 0; i < edges.length; i++) {
    6868        TriangleEdge triangleEdge = edges[i];
     
    7070    }*/
    7171
    72         // sort by distance
    73         Arrays.sort(edges);
    74         // pick the longest edge
    75         TriangleEdge longest = edges[0];
    76 
    77 
    78         //System.out.println("Longest " + longest);
    79         EleCoordinate pI = points[longest.getI()];
    80         EleCoordinate pJ = points[longest.getJ()];
    81         EleCoordinate pK = points[longest.getK()];
    82         EleCoordinate newP = getMid(pI, pJ);
    83         /*
     72                // sort by distance
     73                Arrays.sort(edges);
     74                // pick the longest edge
     75                TriangleEdge longest = edges[0];
     76
     77
     78                //System.out.println("Longest " + longest);
     79                EleCoordinate pI = points[longest.getI()];
     80                EleCoordinate pJ = points[longest.getJ()];
     81                EleCoordinate pK = points[longest.getK()];
     82                EleCoordinate newP = getMid(pI, pJ);
     83                /*
    8484    System.out.println(pI);
    8585    System.out.println(pJ);
    8686    System.out.println(pK);
    8787    System.out.println(newP);
    88         */
    89         List<EleVertex> res = new ArrayList<EleVertex>();
    90         res.add(new EleVertex(pI, pK, newP));
    91         res.add(new EleVertex(pJ, pK, newP));
    92 
    93         return res;
    94     }
    95 
    96     /**
    97     * Checks if vertex requires further processing or is finished. Currently this
    98     * method returns <code>true</code>, if the average deviation is < 5m
    99     *
    100     * @return true, if is finished
    101     */
    102     public boolean isFinished() {
    103         double z = 0D;
     88                */
     89                List<EleVertex> res = new ArrayList<EleVertex>();
     90                res.add(new EleVertex(pI, pK, newP));
     91                res.add(new EleVertex(pJ, pK, newP));
     92
     93                return res;
     94        }
     95
     96        /**
     97        * Checks if vertex requires further processing or is finished. Currently this
     98        * method returns <code>true</code>, if the average deviation is < 5m
     99        *
     100        * @return true, if is finished
     101        */
     102        public boolean isFinished() {
     103                /*double z = 0D;
    104104        double avrgEle = getEle();
    105105
    106106        for (EleCoordinate point : points) {
    107107            z += (avrgEle - point.getEle()) * (avrgEle - point.getEle());
    108         }
    109 
    110         // TODO: Check for proper limit
    111         return /*z < 75 || */getArea() < (30 * 30); // = 3 * 25
    112     }
    113 
    114     /**
    115     * Gets the approximate area of this vertex in square meters.
    116     *
    117     * @return the area
    118     */
    119     public double getArea() {
    120         return area;
    121     }
    122 
    123     /**
    124     * Gets the (linear interpolated) mid point of c1 and c2.
    125     *
    126     * @param c1 the first coordinate
    127     * @param c2 the second coordinate
    128     * @return the mid point
    129     */
    130     public EleCoordinate getMid(EleCoordinate c1, EleCoordinate c2) {
    131         double x = (c1.getX() + c2.getX()) / 2.0;
    132         double y = (c1.getY() + c2.getY()) / 2.0;
    133 
    134         double z = (c1.getEle() + c2.getEle()) / 2.0;
    135         if (c1.greatCircleDistance(c2) > MIN_DIST) {
    136             double hgtZ = ElevationHelper.getSrtmElevation(new LatLon(y, x));
    137 
    138             if (ElevationHelper.isValidElevation(hgtZ)) {
    139                 z = hgtZ;
    140             }
    141         }
    142 
    143         return new EleCoordinate(y, x, z);
    144     }
    145 
    146     /**
    147     * Gets the coordinate for the given index.
    148     *
    149     * @param index the index between 0 and NPOINTS:
    150     * @return the elevation coordinate instance
    151     * @throws IllegalArgumentException, if index is invalid
    152     */
    153     public EleCoordinate get(int index) {
    154         if (index < 0 || index >= NPOINTS) throw new IllegalArgumentException("Invalid index: " + index);
    155 
    156         return points[index];
    157     }
    158 
    159     /**
    160     * Gets the average elevation of this vertex.
    161     *
    162     * @return the ele
    163     */
    164     public double getEle() {
    165 
    166         return avrgEle;
    167     }
    168 
    169     @Override
    170     public String toString() {
    171         return "EleVertex [avrgEle=" + avrgEle + ", area=" + area + ", points="
    172                 + Arrays.toString(points) + "]";
    173     }
    174 
    175 
    176 
    177 
    178     class TriangleEdge implements Comparable<TriangleEdge> {
    179         private final int i;
    180         private final int j;
    181         private final double dist;
    182 
    183         public TriangleEdge(int i, int j, double dist) {
    184             super();
    185             this.i = i;
    186             this.j = j;
    187             this.dist = dist;
    188         }
    189 
    190         public int getI() {
    191             return i;
    192         }
    193 
    194         public int getJ() {
    195             return j;
    196         }
    197 
    198         public int getK() {
    199             if (i == 0) {
    200                 return j == 1 ? 2 : 1;
    201             } else if (i == 1) {
    202                 return j == 0 ? 2 : 0;
    203             } else {
    204                 return j == 0 ? 1 : 0;
    205             }
    206         }
    207 
    208         public double getDist() {
    209             return dist;
    210         }
    211 
    212         @Override
    213         public int compareTo(TriangleEdge o) {
    214             return (int) (o.getDist() - dist);
    215         }
    216 
    217         @Override
    218         public String toString() {
    219             return "TriangleEdge [i=" + i + ", j=" + j + ", dist=" + dist + "]";
    220         }
    221     }
     108        }*/
     109
     110                // TODO: Check for proper limit
     111                return /*z < 75 || */getArea() < (30 * 30); // = 3 * 25
     112        }
     113
     114        /**
     115        * Gets the approximate area of this vertex in square meters.
     116        *
     117        * @return the area
     118        */
     119        public double getArea() {
     120                return area;
     121        }
     122
     123        /**
     124        * Gets the (linear interpolated) mid point of c1 and c2.
     125        *
     126        * @param c1 the first coordinate
     127        * @param c2 the second coordinate
     128        * @return the mid point
     129        */
     130        public EleCoordinate getMid(EleCoordinate c1, EleCoordinate c2) {
     131                double x = (c1.getX() + c2.getX()) / 2.0;
     132                double y = (c1.getY() + c2.getY()) / 2.0;
     133
     134                double z = (c1.getEle() + c2.getEle()) / 2.0;
     135                if (c1.greatCircleDistance(c2) > MIN_DIST) {
     136                        double hgtZ = ElevationHelper.getSrtmElevation(new LatLon(y, x));
     137
     138                        if (ElevationHelper.isValidElevation(hgtZ)) {
     139                                z = hgtZ;
     140                        }
     141                }
     142
     143                return new EleCoordinate(y, x, z);
     144        }
     145
     146        /**
     147        * Gets the coordinate for the given index.
     148        *
     149        * @param index the index between 0 and NPOINTS:
     150        * @return the elevation coordinate instance
     151        * @throws IllegalArgumentException, if index is invalid
     152        */
     153        public EleCoordinate get(int index) {
     154                if (index < 0 || index >= NPOINTS) throw new IllegalArgumentException("Invalid index: " + index);
     155
     156                return points[index];
     157        }
     158
     159        /**
     160        * Gets the average elevation of this vertex.
     161        *
     162        * @return the ele
     163        */
     164        public double getEle() {
     165
     166                return avrgEle;
     167        }
     168
     169        @Override
     170        public String toString() {
     171                return "EleVertex [avrgEle=" + avrgEle + ", area=" + area + ", points="
     172                                + Arrays.toString(points) + "]";
     173        }
     174
     175
     176
     177
     178        class TriangleEdge implements Comparable<TriangleEdge> {
     179                private final int i;
     180                private final int j;
     181                private final double dist;
     182
     183                public TriangleEdge(int i, int j, double dist) {
     184                        super();
     185                        this.i = i;
     186                        this.j = j;
     187                        this.dist = dist;
     188                }
     189
     190                public int getI() {
     191                        return i;
     192                }
     193
     194                public int getJ() {
     195                        return j;
     196                }
     197
     198                public int getK() {
     199                        if (i == 0) {
     200                                return j == 1 ? 2 : 1;
     201                        } else if (i == 1) {
     202                                return j == 0 ? 2 : 0;
     203                        } else {
     204                                return j == 0 ? 1 : 0;
     205                        }
     206                }
     207
     208                public double getDist() {
     209                        return dist;
     210                }
     211
     212                @Override
     213                public int compareTo(TriangleEdge o) {
     214                        return (int) (o.getDist() - dist);
     215                }
     216
     217                @Override
     218                public String toString() {
     219                        return "TriangleEdge [i=" + i + ", j=" + j + ", dist=" + dist + "]";
     220                }
     221        }
    222222}
Note: See TracChangeset for help on using the changeset viewer.