removed some old stuff, added profiler, minor performance tuning
This commit is contained in:
parent
42e9ddbdd1
commit
f70dd3c3ac
22 changed files with 234 additions and 802 deletions
|
|
@ -35,8 +35,6 @@ public final class NodesCache
|
|||
private OsmFile[][] fileRows;
|
||||
private ArrayList<MicroCache> segmentList = new ArrayList<MicroCache>();
|
||||
|
||||
public DistanceChecker distanceChecker;
|
||||
|
||||
public WaypointMatcher waypointMatcher;
|
||||
|
||||
public boolean first_file_access_failed = false;
|
||||
|
|
@ -212,7 +210,7 @@ public final class NodesCache
|
|||
long id = node.getIdFromPos();
|
||||
if ( segment.getAndClear( id ) )
|
||||
{
|
||||
node.parseNodeBody( segment, nodesMap, distanceChecker );
|
||||
node.parseNodeBody( segment, nodesMap );
|
||||
}
|
||||
|
||||
if ( garbageCollectionEnabled ) // garbage collection
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import java.io.RandomAccessFile;
|
|||
|
||||
import btools.codec.DataBuffers;
|
||||
import btools.codec.MicroCache;
|
||||
import btools.codec.MicroCache1;
|
||||
import btools.codec.MicroCache2;
|
||||
import btools.codec.TagValueValidator;
|
||||
import btools.codec.WaypointMatcher;
|
||||
|
|
@ -152,10 +151,6 @@ final class OsmFile
|
|||
|
||||
int crcData = Crc32.crc( ab, 0, asize - 4 );
|
||||
int crcFooter = new ByteDataReader( ab, asize - 4 ).readInt();
|
||||
if ( crcData == crcFooter )
|
||||
{
|
||||
return reallyDecode ? new MicroCache1( ab, lonIdx, latIdx ) : null;
|
||||
}
|
||||
if ( ( crcData ^ 2 ) == crcFooter )
|
||||
{
|
||||
return reallyDecode ? new MicroCache2( dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher ) : null;
|
||||
|
|
|
|||
|
|
@ -26,21 +26,17 @@ public class OsmLink
|
|||
|
||||
public boolean counterLinkWritten;
|
||||
|
||||
public boolean hasNewGeometry; // preliminary
|
||||
|
||||
public byte state;
|
||||
|
||||
public void setGeometry( byte[] geometry )
|
||||
{
|
||||
this.geometry = geometry;
|
||||
hasNewGeometry = true;
|
||||
}
|
||||
|
||||
final public OsmTransferNode decodeFirsttransfer( OsmNode sourceNode )
|
||||
{
|
||||
if ( geometry == null ) return null;
|
||||
if ( hasNewGeometry )
|
||||
{
|
||||
if ( geometry == null ) return null;
|
||||
|
||||
OsmTransferNode firstTransferNode = null;
|
||||
OsmTransferNode lastTransferNode = null;
|
||||
OsmNode startnode = counterLinkWritten ? targetNode : sourceNode;
|
||||
|
|
@ -53,7 +49,6 @@ public class OsmLink
|
|||
OsmTransferNode trans = new OsmTransferNode();
|
||||
trans.ilon = olon + r.readVarLengthSigned();
|
||||
trans.ilat = olat + r.readVarLengthSigned();
|
||||
trans.descriptionBitmap = descriptionBitmap;
|
||||
trans.selev = (short)(oselev + r.readVarLengthSigned());
|
||||
olon = trans.ilon;
|
||||
olat = trans.ilat;
|
||||
|
|
@ -77,14 +72,6 @@ public class OsmLink
|
|||
}
|
||||
}
|
||||
return firstTransferNode;
|
||||
}
|
||||
return OsmTransferNode.decode( geometry );
|
||||
}
|
||||
|
||||
final public void encodeFirsttransfer( OsmTransferNode firsttransfer )
|
||||
{
|
||||
if ( firsttransfer == null ) geometry = null;
|
||||
else geometry = OsmTransferNode.encode( firsttransfer );
|
||||
}
|
||||
|
||||
final public void addLinkHolder( OsmLinkHolder holder )
|
||||
|
|
|
|||
|
|
@ -6,22 +6,11 @@
|
|||
package btools.mapaccess;
|
||||
|
||||
import btools.codec.MicroCache;
|
||||
import btools.codec.MicroCache1;
|
||||
import btools.codec.MicroCache2;
|
||||
import btools.util.ByteArrayUnifier;
|
||||
|
||||
public class OsmNode implements OsmPos
|
||||
{
|
||||
public static final int EXTERNAL_BITMASK = 0x80; // old semantic
|
||||
public static final int SIGNLON_BITMASK = 0x80;
|
||||
public static final int SIGNLAT_BITMASK = 0x40;
|
||||
public static final int TRANSFERNODE_BITMASK = 0x20;
|
||||
public static final int WRITEDESC_BITMASK = 0x10;
|
||||
public static final int SKIPDETAILS_BITMASK = 0x08;
|
||||
public static final int NODEDESC_BITMASK = 0x04;
|
||||
public static final int RESERVED1_BITMASK = 0x02;
|
||||
public static final int RESERVED2_BITMASK = 0x01;
|
||||
|
||||
public OsmNode()
|
||||
{
|
||||
}
|
||||
|
|
@ -146,21 +135,17 @@ public class OsmNode implements OsmPos
|
|||
return "" + getIdFromPos();
|
||||
}
|
||||
|
||||
public void parseNodeBody( MicroCache mc, OsmNodesMap hollowNodes, DistanceChecker dc )
|
||||
public void parseNodeBody( MicroCache mc, OsmNodesMap hollowNodes )
|
||||
{
|
||||
if ( mc instanceof MicroCache1 )
|
||||
if ( mc instanceof MicroCache2 )
|
||||
{
|
||||
parseNodeBody1( (MicroCache1) mc, hollowNodes, dc );
|
||||
}
|
||||
else if ( mc instanceof MicroCache2 )
|
||||
{
|
||||
parseNodeBody2( (MicroCache2) mc, hollowNodes, dc );
|
||||
parseNodeBody2( (MicroCache2) mc, hollowNodes );
|
||||
}
|
||||
else
|
||||
throw new IllegalArgumentException( "unknown cache version: " + mc.getClass() );
|
||||
}
|
||||
|
||||
public void parseNodeBody2( MicroCache2 mc, OsmNodesMap hollowNodes, DistanceChecker dc )
|
||||
public void parseNodeBody2( MicroCache2 mc, OsmNodesMap hollowNodes )
|
||||
{
|
||||
ByteArrayUnifier abUnifier = hollowNodes.getByteArrayUnifier();
|
||||
|
||||
|
|
@ -184,10 +169,6 @@ public class OsmNode implements OsmPos
|
|||
}
|
||||
byte[] geometry = mc.readDataUntil( endPointer );
|
||||
|
||||
// preliminary hack: way-point-matching not here (done at decoding time)
|
||||
if ( dc != null )
|
||||
continue;
|
||||
|
||||
if ( linklon == ilon && linklat == ilat )
|
||||
{
|
||||
continue; // skip self-ref
|
||||
|
|
@ -236,186 +217,10 @@ public class OsmNode implements OsmPos
|
|||
rlink.setGeometry( geometry );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
hollowNodes.remove( this );
|
||||
}
|
||||
|
||||
public void parseNodeBody1( MicroCache1 is, OsmNodesMap hollowNodes, DistanceChecker dc )
|
||||
{
|
||||
ByteArrayUnifier abUnifier = hollowNodes.getByteArrayUnifier();
|
||||
|
||||
selev = is.readShort();
|
||||
|
||||
while (is.hasMoreData())
|
||||
{
|
||||
int ilonref = ilon;
|
||||
int ilatref = ilat;
|
||||
|
||||
boolean counterLinkWritten = false;
|
||||
OsmTransferNode firstTransferNode = null;
|
||||
OsmTransferNode lastTransferNode = null;
|
||||
int linklon;
|
||||
int linklat;
|
||||
byte[] description = null;
|
||||
for ( ;; )
|
||||
{
|
||||
int bitField = is.readByte();
|
||||
int dlon = is.readVarLengthUnsigned();
|
||||
int dlat = is.readVarLengthUnsigned();
|
||||
if ( ( bitField & SIGNLON_BITMASK ) != 0 )
|
||||
{
|
||||
dlon = -dlon;
|
||||
}
|
||||
if ( ( bitField & SIGNLAT_BITMASK ) != 0 )
|
||||
{
|
||||
dlat = -dlat;
|
||||
}
|
||||
linklon = ilonref + dlon;
|
||||
linklat = ilatref + dlat;
|
||||
ilonref = linklon;
|
||||
ilatref = linklat;
|
||||
// read variable length or old 8 byte fixed, and ensure that 8 bytes is
|
||||
// only fixed
|
||||
if ( ( bitField & WRITEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
byte[] ab = new byte[is.readByte()];
|
||||
is.readFully( ab );
|
||||
description = abUnifier.unify( ab );
|
||||
}
|
||||
if ( ( bitField & NODEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
byte[] ab = new byte[is.readByte()];
|
||||
is.readFully( ab );
|
||||
nodeDescription = abUnifier.unify( ab );
|
||||
}
|
||||
if ( ( bitField & RESERVED1_BITMASK ) != 0 )
|
||||
{
|
||||
byte[] ab = new byte[is.readByte()];
|
||||
is.readFully( ab );
|
||||
}
|
||||
if ( ( bitField & RESERVED2_BITMASK ) != 0 )
|
||||
{
|
||||
byte[] ab = new byte[is.readByte()];
|
||||
is.readFully( ab );
|
||||
}
|
||||
if ( ( bitField & SKIPDETAILS_BITMASK ) != 0 )
|
||||
{
|
||||
counterLinkWritten = true;
|
||||
}
|
||||
|
||||
if ( description == null && !counterLinkWritten )
|
||||
throw new IllegalArgumentException( "internal error: missing way description!" );
|
||||
|
||||
boolean isTransfer = ( bitField & TRANSFERNODE_BITMASK ) != 0;
|
||||
if ( isTransfer )
|
||||
{
|
||||
OsmTransferNode trans = new OsmTransferNode();
|
||||
trans.ilon = linklon;
|
||||
trans.ilat = linklat;
|
||||
trans.descriptionBitmap = description;
|
||||
trans.selev = (short) ( selev + is.readVarLengthSigned() );
|
||||
if ( lastTransferNode == null )
|
||||
{
|
||||
firstTransferNode = trans;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastTransferNode.next = trans;
|
||||
}
|
||||
lastTransferNode = trans;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// performance shortcut: ignore link if out of reach
|
||||
if ( dc != null && !counterLinkWritten )
|
||||
{
|
||||
if ( !dc.isWithinRadius( ilon, ilat, firstTransferNode, linklon, linklat ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ( linklon == ilon && linklat == ilat )
|
||||
{
|
||||
continue; // skip self-ref
|
||||
}
|
||||
|
||||
// first check the known links for that target
|
||||
OsmLink link = getCompatibleLink( linklon, linklat, counterLinkWritten, 2 );
|
||||
if ( link == null ) // .. not found, then check the hollow nodes
|
||||
{
|
||||
long targetNodeId = ( (long) linklon ) << 32 | linklat;
|
||||
OsmNode tn = hollowNodes.get( targetNodeId ); // target node
|
||||
if ( tn == null ) // node not yet known, create a new hollow proxy
|
||||
{
|
||||
tn = new OsmNode( linklon, linklat );
|
||||
tn.setHollow();
|
||||
hollowNodes.put( tn );
|
||||
}
|
||||
link = new OsmLink();
|
||||
link.targetNode = tn;
|
||||
link.counterLinkWritten = counterLinkWritten;
|
||||
link.state = 1;
|
||||
addLink( link );
|
||||
}
|
||||
|
||||
// now we have a link with a target node -> get the reverse link
|
||||
OsmLink rlink = link.targetNode.getCompatibleLink( ilon, ilat, !counterLinkWritten, 1 );
|
||||
if ( rlink == null ) // .. not found, create it
|
||||
{
|
||||
rlink = new OsmLink();
|
||||
rlink.targetNode = this;
|
||||
rlink.counterLinkWritten = !counterLinkWritten;
|
||||
rlink.state = 2;
|
||||
link.targetNode.addLink( rlink );
|
||||
}
|
||||
|
||||
if ( !counterLinkWritten )
|
||||
{
|
||||
// we have the data for that link, so fill both the link ..
|
||||
link.descriptionBitmap = description;
|
||||
link.encodeFirsttransfer( firstTransferNode );
|
||||
|
||||
// .. and the reverse
|
||||
if ( rlink.counterLinkWritten )
|
||||
{
|
||||
rlink.descriptionBitmap = description; // default for no
|
||||
// transfer-nodes
|
||||
OsmTransferNode previous = null;
|
||||
OsmTransferNode rtrans = null;
|
||||
for ( OsmTransferNode trans = firstTransferNode; trans != null; trans = trans.next )
|
||||
{
|
||||
if ( previous == null )
|
||||
{
|
||||
rlink.descriptionBitmap = trans.descriptionBitmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
previous.descriptionBitmap = trans.descriptionBitmap;
|
||||
}
|
||||
rtrans = new OsmTransferNode();
|
||||
rtrans.ilon = trans.ilon;
|
||||
rtrans.ilat = trans.ilat;
|
||||
rtrans.selev = trans.selev;
|
||||
rtrans.next = previous;
|
||||
rtrans.descriptionBitmap = description;
|
||||
previous = rtrans;
|
||||
}
|
||||
rlink.encodeFirsttransfer( rtrans );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ( dc == null )
|
||||
{
|
||||
hollowNodes.remove( this );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHollow()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,144 +5,15 @@
|
|||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
import btools.util.ByteDataReader;
|
||||
import btools.util.ByteDataWriter;
|
||||
|
||||
|
||||
|
||||
public final class OsmTransferNode
|
||||
{
|
||||
/**
|
||||
* The description bitmap is mainly the way description
|
||||
* used to calculate the costfactor
|
||||
*/
|
||||
public byte[] descriptionBitmap;
|
||||
|
||||
public OsmTransferNode next;
|
||||
|
||||
public int ilon;
|
||||
public int ilat;
|
||||
public short selev;
|
||||
|
||||
private static final int BIT_DESC = 1;
|
||||
private static final int BIT_ILONHIGH = 2;
|
||||
private static final int BIT_ILATHIGH = 4;
|
||||
private static final int BIT_STOP = 8;
|
||||
|
||||
// encode this transfer-node into a byte array
|
||||
public static byte[] encode( OsmTransferNode tn )
|
||||
{
|
||||
byte[] currentDesc = null;
|
||||
int currentILonHigh = 0;
|
||||
int currentILatHigh = 0;
|
||||
OsmTransferNode n = tn;
|
||||
|
||||
// first loop to calc size
|
||||
int size = 1; // stop-bit
|
||||
|
||||
while( n != null )
|
||||
{
|
||||
if ( n.descriptionBitmap == null ) throw new IllegalArgumentException( "transfernode-encode: description is null" );
|
||||
|
||||
if( n.descriptionBitmap != currentDesc )
|
||||
{
|
||||
currentDesc = n.descriptionBitmap;
|
||||
size += 1 + currentDesc.length;
|
||||
}
|
||||
if( ( n.ilon >> 16 ) != currentILonHigh )
|
||||
{
|
||||
size += 2;
|
||||
currentILonHigh = n.ilon >> 16;
|
||||
}
|
||||
if( (n.ilat >> 16) != currentILatHigh )
|
||||
{
|
||||
size += 2;
|
||||
currentILatHigh = n.ilat >> 16;
|
||||
}
|
||||
size += 7;
|
||||
n = n.next;
|
||||
}
|
||||
|
||||
byte[] ab = new byte[size];
|
||||
ByteDataWriter os = new ByteDataWriter( ab );
|
||||
|
||||
currentDesc = null;
|
||||
currentILonHigh = 0;
|
||||
currentILatHigh = 0;
|
||||
n = tn;
|
||||
while( n != null )
|
||||
{
|
||||
int mode = 0;
|
||||
if( n.descriptionBitmap != currentDesc )
|
||||
{
|
||||
mode |= BIT_DESC;
|
||||
currentDesc = n.descriptionBitmap;
|
||||
}
|
||||
if( ( n.ilon >> 16 ) != currentILonHigh )
|
||||
{
|
||||
mode |= BIT_ILONHIGH;
|
||||
currentILonHigh = n.ilon >> 16;
|
||||
}
|
||||
if( (n.ilat >> 16) != currentILatHigh )
|
||||
{
|
||||
mode |= BIT_ILATHIGH;
|
||||
currentILatHigh = n.ilat >> 16;
|
||||
}
|
||||
os.writeByte( mode);
|
||||
if ( (mode & BIT_DESC) != 0 ) { os.writeByte( currentDesc.length ); os.write( currentDesc ); }
|
||||
if ( (mode & BIT_ILONHIGH) != 0 ) os.writeShort( currentILonHigh );
|
||||
if ( (mode & BIT_ILATHIGH) != 0 ) os.writeShort( currentILatHigh );
|
||||
os.writeShort( n.ilon );
|
||||
os.writeShort( n.ilat );
|
||||
os.writeShort( n.selev );
|
||||
n = n.next;
|
||||
}
|
||||
os.writeByte( BIT_STOP );
|
||||
return ab;
|
||||
}
|
||||
|
||||
// decode a transfer-node from a byte array
|
||||
public static OsmTransferNode decode( byte[] ab )
|
||||
{
|
||||
ByteDataReader is = new ByteDataReader( ab );
|
||||
|
||||
OsmTransferNode firstNode = null;
|
||||
OsmTransferNode lastNode = null;
|
||||
byte[] currentDesc = null;
|
||||
int currentILonHigh = 0;
|
||||
int currentILatHigh = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
byte mode = is.readByte();
|
||||
if ( (mode & BIT_STOP ) != 0 ) break;
|
||||
|
||||
OsmTransferNode n = new OsmTransferNode();
|
||||
if ( (mode & BIT_DESC) != 0 ) { int dlen = is.readByte(); currentDesc = new byte[dlen]; is.readFully( currentDesc ); }
|
||||
if ( (mode & BIT_ILONHIGH) != 0 ) currentILonHigh = is.readShort();
|
||||
if ( (mode & BIT_ILATHIGH) != 0 ) currentILatHigh = is.readShort();
|
||||
n.descriptionBitmap = currentDesc;
|
||||
if ( n.descriptionBitmap == null ) throw new IllegalArgumentException( "transfernode-decode: description is null" );
|
||||
int ilon = is.readShort() & 0xffff; ilon |= currentILonHigh << 16;
|
||||
int ilat = is.readShort() & 0xffff; ilat |= currentILatHigh << 16;
|
||||
n.ilon = ilon;
|
||||
n.ilat = ilat;
|
||||
n.selev = is.readShort();
|
||||
|
||||
if ( ilon != n.ilon ) System.out.println( "ilon=" + ilon + " n.ilon=" + n.ilon );
|
||||
if ( ilat != n.ilat ) System.out.println( "ilat=" + ilat + " n.ilat=" + n.ilat );
|
||||
|
||||
if ( lastNode != null )
|
||||
{
|
||||
lastNode.next = n;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstNode = n;
|
||||
}
|
||||
lastNode = n;
|
||||
}
|
||||
return firstNode;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue