1 | package indoor_sweepline;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 | import java.util.Vector;
|
---|
5 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
6 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
7 | import org.openstreetmap.josm.data.osm.Node;
|
---|
8 |
|
---|
9 |
|
---|
10 | public class BeamGeography
|
---|
11 | {
|
---|
12 | public BeamGeography(DataSet dataSet, ModelGeography target)
|
---|
13 | {
|
---|
14 | partsGeography = new Vector<CorridorGeography>();
|
---|
15 | nodes = new Vector<Node>();
|
---|
16 | this.dataSet = dataSet;
|
---|
17 | this.target = target;
|
---|
18 | }
|
---|
19 |
|
---|
20 |
|
---|
21 | public void appendNodes(int from, int to, String level)
|
---|
22 | {
|
---|
23 | if (from <= to)
|
---|
24 | {
|
---|
25 | for (int i = from; i < to; ++i)
|
---|
26 | {
|
---|
27 | target.appendNode(nodes.elementAt(i));
|
---|
28 | CorridorPart part = parts.elementAt(i);
|
---|
29 | partsGeography.elementAt(i).appendNodes(part.getType(), part.getSide(), level,
|
---|
30 | nodes.elementAt(i).getCoor(), nodes.elementAt(i+1).getCoor(), target);
|
---|
31 | }
|
---|
32 | target.appendNode(nodes.elementAt(to));
|
---|
33 | }
|
---|
34 | else
|
---|
35 | {
|
---|
36 | for (int i = from; i > to; --i)
|
---|
37 | {
|
---|
38 | target.appendNode(nodes.elementAt(i));
|
---|
39 | CorridorPart part = parts.elementAt(i-1);
|
---|
40 | partsGeography.elementAt(i-1).appendNodes(part.getType(), part.getSide(), level,
|
---|
41 | nodes.elementAt(i).getCoor(), nodes.elementAt(i-1).getCoor(), target);
|
---|
42 | }
|
---|
43 | target.appendNode(nodes.elementAt(to));
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | public void adjustNodes(LatLon pivot, Vector<CorridorPart> parts)
|
---|
49 | {
|
---|
50 | this.parts = parts;
|
---|
51 | adjustNode(0, new LatLon(pivot.lat(), pivot.lon()));
|
---|
52 |
|
---|
53 | double offset = 0;
|
---|
54 | for (int i = 0; i < parts.size(); ++i)
|
---|
55 | {
|
---|
56 | adjustPartGeography(i);
|
---|
57 | offset += parts.elementAt(i).width;
|
---|
58 | adjustNode(i+1, new LatLon(addMetersToLat(pivot, offset), pivot.lon()));
|
---|
59 | }
|
---|
60 |
|
---|
61 | // Size reduction not implemented
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | private void adjustNode(int i, LatLon coor)
|
---|
66 | {
|
---|
67 | if (nodes.size() <= i)
|
---|
68 | nodes.setSize(i+1);
|
---|
69 | Node node = nodes.elementAt(i);
|
---|
70 | if (node == null)
|
---|
71 | {
|
---|
72 | node = new Node(coor);
|
---|
73 | dataSet.addPrimitive(node);
|
---|
74 | nodes.setElementAt(node, i);
|
---|
75 | }
|
---|
76 | else
|
---|
77 | node.setCoor(coor);
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | private void adjustPartGeography(int i)
|
---|
82 | {
|
---|
83 | if (partsGeography.size() <= i)
|
---|
84 | partsGeography.setSize(i+1);
|
---|
85 | CorridorGeography partGeography = partsGeography.elementAt(i);
|
---|
86 | if (partGeography == null)
|
---|
87 | {
|
---|
88 | partGeography = new CorridorGeography(dataSet);
|
---|
89 | partsGeography.setElementAt(partGeography, i);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | public LatLon coorAt(int i)
|
---|
95 | {
|
---|
96 | return nodes.elementAt(i).getCoor();
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | private Vector<CorridorPart> parts;
|
---|
101 | private Vector<CorridorGeography> partsGeography;
|
---|
102 | private ModelGeography target;
|
---|
103 | private DataSet dataSet;
|
---|
104 | private Vector<Node> nodes;
|
---|
105 |
|
---|
106 |
|
---|
107 | private static double addMetersToLat(LatLon latLon, double south)
|
---|
108 | {
|
---|
109 | return latLon.lat() - south *(360./4e7);
|
---|
110 | }
|
---|
111 | }
|
---|