52
52
log.info("new RouteCenter at " + centralPoint.toDegreeString() +
53
53
", nodes: " + nodes.size() + " tabA: " + tabA.size() +
54
54
" tabB: " + tabB.size());
56
// update lat/lon offsets; update arcs with table indices; populate tabC
58
* update arcs with table indices; populate tabC
60
private void updateOffsets(){
57
61
for (RouteNode node : nodes) {
58
62
node.setOffsets(centralPoint);
59
63
for (RouteArc arc : node.arcsIteration()) {
60
64
arc.setIndexA(tabA.getIndex(arc));
65
arc.setInternal(nodes.contains(arc.getDest()));
61
66
if (!arc.isInternal())
62
67
arc.setIndexB(tabB.getIndex(arc.getDest()));
64
for (RouteRestriction restr : node.getRestrictions())
70
for (RouteRestriction restr : node.getRestrictions()){
71
if (restr.getArcs().size() >= 3){
72
// only restrictions with more than 2 arcs can contain further arcs
73
for (RouteArc arc : restr.getArcs()){
74
if (arc.getSource() == node)
76
arc.setIndexA(tabA.getIndex(arc));
77
arc.setInternal(nodes.contains(arc.getDest()));
78
if (!arc.isInternal())
79
arc.setIndexB(tabB.getIndex(arc.getDest()));
65
82
restr.setOffsetC(tabC.addRestriction(restr));
67
85
// update size of tabC offsets, now that tabC has been populated
68
86
tabC.propagateSizeBytes();
72
90
* Write a route center.
74
92
* writer.position() is relative to the start of NOD 1.
75
93
* Space for Table A is reserved but not written. See writeTableA.
77
public void write(ImgFileWriter writer) {
95
public void write(ImgFileWriter writer, int[] classBoundaries) {
78
96
assert !nodes.isEmpty(): "RouteCenter without nodes";
80
for (RouteNode node : nodes)
98
int centerPos = writer.position();
99
for (RouteNode node : nodes){
81
100
node.write(writer);
83
int mult = 1 << NODHeader.DEF_ALIGN;
85
// Get the position of the tables, and position there.
86
int roundpos = (writer.position() + mult - 1)
87
>> NODHeader.DEF_ALIGN
88
<< NODHeader.DEF_ALIGN;
89
int tablesOffset = roundpos + mult;
101
int group = node.getGroup();
104
if (centerPos < classBoundaries[group-1]){
105
// update positions (loop is used because style might not use all classes
106
for (int i = group-1; i >= 0; i--){
107
if (centerPos < classBoundaries[i] )
108
classBoundaries[i] = centerPos;
112
int alignment = 1 << NODHeader.DEF_ALIGN;
113
int alignMask = alignment - 1;
115
// Calculate the position of the tables.
116
int tablesOffset = (writer.position() + alignment) & ~alignMask;
90
117
log.debug("write table a at offset", Integer.toHexString(tablesOffset));
92
119
// Go back and fill in all the table offsets