Skip to content
Permalink
Browse files
merged #132, added more tests, moved relation code into encoder (just…
… using relation flags); some minor fixes
  • Loading branch information
Peter committed Dec 22, 2013
1 parent 4424116 commit 574ba813ed46a9f547c90bd1bee6c4011425d3fe
Show file tree
Hide file tree
Showing 22 changed files with 841 additions and 750 deletions.

Large diffs are not rendered by default.

@@ -311,9 +311,6 @@ public InstructionList calcInstructions()
final int tmpNode = getFromNode();
forEveryEdge(new EdgeVisitor()
{
String name = null;
int pavement;
int wayType;
/*
* We need three points to make directions
*
@@ -334,12 +331,15 @@ public InstructionList calcInstructions()
* considering orientation belonging to the interval
* [ - pi + previousOrientation , + pi + previousOrientation ]
*/
double prevLat = graph.getLatitude(tmpNode);
double prevLon = graph.getLongitude(tmpNode);
double prevOrientation;
double tmpDistance = Double.NaN;
long tmpTime;
PointList points = new PointList();
private double prevLat = graph.getLatitude(tmpNode);
private double prevLon = graph.getLongitude(tmpNode);
private double prevOrientation;
private double tmpDistance = Double.NaN;
private long tmpTime;
private PointList points = new PointList();
private String name = null;
private int pavementCode;
private int wayTypeCode;

@Override
public void next( EdgeIteratorState edge, int index )
@@ -369,11 +369,11 @@ public void next( EdgeIteratorState edge, int index )
{
// very first instruction
name = edge.getName();
pavement = encoder.getPavementCode(edge.getFlags());
wayType = encoder.getWayTypeCode(edge.getFlags());
pavementCode = encoder.getPavementCode(edge.getFlags());
wayTypeCode = encoder.getWayTypeCode(edge.getFlags());

add(edge, wayGeo);
cachedWays.add(new Instruction(Instruction.CONTINUE_ON_STREET, name, wayType, pavement, tmpDistance, tmpTime, points));
cachedWays.add(new Instruction(Instruction.CONTINUE_ON_STREET, name, wayTypeCode, pavementCode, tmpDistance, tmpTime, points));
} else
{
double tmpOrientation;
@@ -396,15 +396,15 @@ public void next( EdgeIteratorState edge, int index )
int tmppavement = encoder.getPavementCode(edge.getFlags());
int tmpwayType = encoder.getWayTypeCode(edge.getFlags());
if ((!name.equals(tmpName))
|| (pavement != tmppavement)
|| (wayType != tmpwayType))
|| (pavementCode != tmppavement)
|| (wayTypeCode != tmpwayType))
{
tmpDistance = Double.NaN;
points = new PointList();
add(edge, wayGeo);
name = tmpName;
pavement = tmppavement;
wayType = tmpwayType;
pavementCode = tmppavement;
wayTypeCode = tmpwayType;
double delta = Math.abs(tmpOrientation - prevOrientation);
int indication;
if (delta < 0.2)
@@ -437,7 +437,7 @@ public void next( EdgeIteratorState edge, int index )

}

cachedWays.add(new Instruction(indication, name, wayType, pavement, tmpDistance, tmpTime, points));
cachedWays.add(new Instruction(indication, name, wayTypeCode, pavementCode, tmpDistance, tmpTime, points));
} else
{
add(edge, wayGeo);
@@ -40,6 +40,9 @@
public abstract class AbstractFlagEncoder implements FlagEncoder
{
private final static Logger logger = LoggerFactory.getLogger(AbstractFlagEncoder.class);
private long nodeBitMask;
private long wayBitMask;
private long relBitMask;
protected long forwardBit = 0;
protected long backwardBit = 0;
protected long directionBitMask = 0;
@@ -75,9 +78,7 @@ public AbstractFlagEncoder()
static int parseSpeed( String str )
{
if (Helper.isEmpty(str))
{
return -1;
}

try
{
@@ -120,13 +121,23 @@ static int parseSpeed( String str )
}

/**
* Define 2 reserved bits for routing and internal bits for parsing.
* Defines the bits for the node flags, which are currently used for barriers only.
* <p>
* @return incremented shift value pointing behind the last used bit
*/
public int defineNodeBits( int index, int shift )
{
return shift;
}

/**
* Defines bits used for edge flags used for access, speed etc.
* <p/>
* @param index
* @param shift bit offset for the first bit used by this encoder
* @return incremented shift value pointing behind the last used bit
*/
public int defineBits( int index, int shift )
public int defineWayBits( int index, int shift )
{
// define the first 2 bits in flags for routing
forwardBit = 1 << shift;
@@ -140,27 +151,37 @@ public int defineBits( int index, int shift )

return shift + 2;
}


/**
* Defines the bits which are used for relation flags.
* <p>
* @return incremented shift value pointing behind the last used bit
*/
public int defineRelationBits( int index, int shift )
{
return shift;
}

/**
* Analyze the properties of a relation and create the routing flags for the second read step
* <p/>
*/
public abstract int handleRelationTags( OSMRelation relation );
public abstract long handleRelationTags( OSMRelation relation, long oldRelationFlags );

/**
* Decide whether a way is routable for a given mode of travel
* <p/>
* @param way
* @return the assigned bit of the mode of travel if it is accepted or 0 for not accepted
*/
public abstract long isAllowed( OSMWay way );

/**
* Analyze properties of a way and create the routing flags
* <p/>
* @param allowed
*/
public abstract long handleWayTags( long allowed, OSMWay way, int relationweigth);
public abstract long handleWayTags( OSMWay way, long allowed, long relationFlags );

/**
* Parse tags on nodes, looking for barriers.
@@ -196,17 +217,17 @@ public boolean canBeOverwritten( long flags1, long flags2 )
}

@Override
public int getPavementCode(long flags)
public int getPavementCode( long flags )
{
return -1;
}

@Override
public int getWayTypeCode(long flags)
public int getWayTypeCode( long flags )
{
return -1;
}

public long swapDirection( long flags )
{
long dir = flags & directionBitMask;
@@ -360,4 +381,27 @@ protected long handleFerry( OSMWay way, int unknownSpeed, int shortTripsSpeed, i
return speedEncoder.setValue(0, shortTripsSpeed);
}
}

void setWayBitMask( int usedBits, int shift )
{
wayBitMask = (1L << usedBits) - 1;
wayBitMask <<= shift;
}

long getWayBitMask()
{
return wayBitMask;
}

void setRelBitMask( int usedBits, int shift )
{
relBitMask = (1L << usedBits) - 1;
relBitMask <<= shift;
}

void setNodeBitMask( int usedBits, int shift )
{
nodeBitMask = (1L << usedBits) - 1;
nodeBitMask <<= shift;
}
}

0 comments on commit 574ba81

Please sign in to comment.