memory squeezing pre-processor (link-identity)
This commit is contained in:
parent
8a6e601811
commit
176beba6f6
3 changed files with 61 additions and 40 deletions
|
@ -17,11 +17,11 @@ public class OsmLinkP
|
||||||
/**
|
/**
|
||||||
* The target is either the next link or the target node
|
* The target is either the next link or the target node
|
||||||
*/
|
*/
|
||||||
private OsmNodeP sourceNode;
|
protected OsmNodeP sourceNode;
|
||||||
private OsmNodeP targetNode;
|
protected OsmNodeP targetNode;
|
||||||
|
|
||||||
private OsmLinkP previous;
|
protected OsmLinkP previous;
|
||||||
private OsmLinkP next;
|
protected OsmLinkP next;
|
||||||
|
|
||||||
|
|
||||||
public OsmLinkP( OsmNodeP source, OsmNodeP target )
|
public OsmLinkP( OsmNodeP source, OsmNodeP target )
|
||||||
|
@ -30,6 +30,10 @@ public class OsmLinkP
|
||||||
targetNode = target;
|
targetNode = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected OsmLinkP()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public final boolean counterLinkWritten( )
|
public final boolean counterLinkWritten( )
|
||||||
{
|
{
|
||||||
return descriptionBitmap == null;
|
return descriptionBitmap == null;
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
import btools.util.ByteDataWriter;
|
import btools.util.ByteDataWriter;
|
||||||
|
|
||||||
public class OsmNodeP implements Comparable<OsmNodeP>
|
public class OsmNodeP extends OsmLinkP implements Comparable<OsmNodeP>
|
||||||
{
|
{
|
||||||
public static final int SIGNLON_BITMASK = 0x80;
|
public static final int SIGNLON_BITMASK = 0x80;
|
||||||
public static final int SIGNLAT_BITMASK = 0x40;
|
public static final int SIGNLAT_BITMASK = 0x40;
|
||||||
|
@ -29,12 +29,6 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
public int ilon;
|
public int ilon;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The links to other nodes
|
|
||||||
*/
|
|
||||||
public OsmLinkP firstlink = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The elevation
|
* The elevation
|
||||||
*/
|
*/
|
||||||
|
@ -46,7 +40,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
public final static int NO_TUNNEL_BIT = 2;
|
public final static int NO_TUNNEL_BIT = 2;
|
||||||
public final static int LCN_BIT = 4;
|
public final static int LCN_BIT = 4;
|
||||||
public final static int CR_BIT = 8;
|
public final static int CR_BIT = 8;
|
||||||
|
|
||||||
public byte wayBits = 0;
|
public byte wayBits = 0;
|
||||||
|
|
||||||
// interface OsmPos
|
// interface OsmPos
|
||||||
|
@ -72,11 +66,36 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// populate and return the inherited link, if available,
|
||||||
|
// else create a new one
|
||||||
|
public OsmLinkP createLink( OsmNodeP source )
|
||||||
|
{
|
||||||
|
if ( sourceNode == null && targetNode == null )
|
||||||
|
{
|
||||||
|
// inherited instance is available, use this
|
||||||
|
sourceNode = source;
|
||||||
|
targetNode = this;
|
||||||
|
source.addLink( this );
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
OsmLinkP link = new OsmLinkP( source, this );
|
||||||
|
addLink( link );
|
||||||
|
source.addLink( link );
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// memory-squeezing-hack: OsmLinkP's "previous" also used as firstlink..
|
||||||
|
|
||||||
public void addLink( OsmLinkP link )
|
public void addLink( OsmLinkP link )
|
||||||
{
|
{
|
||||||
link.setNext( firstlink, this );
|
link.setNext( previous, this );
|
||||||
firstlink = link;
|
previous = link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsmLinkP getFirstLink()
|
||||||
|
{
|
||||||
|
return sourceNode == null && targetNode == null ? previous : this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getNodeDecsription()
|
public byte[] getNodeDecsription()
|
||||||
|
@ -92,15 +111,15 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
// buffer the body to first calc size
|
// buffer the body to first calc size
|
||||||
ByteDataWriter os2 = new ByteDataWriter( abBuf );
|
ByteDataWriter os2 = new ByteDataWriter( abBuf );
|
||||||
os2.writeShort( getSElev() );
|
os2.writeShort( getSElev() );
|
||||||
|
|
||||||
// hack: write node-desc as link tag (copy cycleway-bits)
|
// hack: write node-desc as link tag (copy cycleway-bits)
|
||||||
byte[] nodeDescription = getNodeDecsription();
|
byte[] nodeDescription = getNodeDecsription();
|
||||||
|
|
||||||
for( OsmLinkP link0 = firstlink; link0 != null; link0 = link0.getNext( this ) )
|
for( OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext( this ) )
|
||||||
{
|
{
|
||||||
int ilonref = ilon;
|
int ilonref = ilon;
|
||||||
int ilatref = ilat;
|
int ilatref = ilat;
|
||||||
|
|
||||||
OsmLinkP link = link0;
|
OsmLinkP link = link0;
|
||||||
OsmNodeP origin = this;
|
OsmNodeP origin = this;
|
||||||
int skipDetailBit = link0.descriptionBitmap == null ? SKIPDETAILS_BITMASK : 0;
|
int skipDetailBit = link0.descriptionBitmap == null ? SKIPDETAILS_BITMASK : 0;
|
||||||
|
@ -114,7 +133,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// next link is the one (of two), does does'nt point back
|
// next link is the one (of two), does does'nt point back
|
||||||
for( link = target.firstlink; link != null; link = link.getNext( target ) )
|
for( link = target.getFirstLink(); link != null; link = link.getNext( target ) )
|
||||||
{
|
{
|
||||||
if ( link.getTarget( target ) != origin ) break;
|
if ( link.getTarget( target ) != origin ) break;
|
||||||
}
|
}
|
||||||
|
@ -130,8 +149,8 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
byte[] lastDescription = null;
|
byte[] lastDescription = null;
|
||||||
while( link != null )
|
while( link != null )
|
||||||
{
|
{
|
||||||
if ( link.descriptionBitmap == null && skipDetailBit == 0 ) throw new IllegalArgumentException( "missing way description...");
|
if ( link.descriptionBitmap == null && skipDetailBit == 0 ) throw new IllegalArgumentException( "missing way description...");
|
||||||
|
|
||||||
OsmNodeP target = link.getTarget( origin );
|
OsmNodeP target = link.getTarget( origin );
|
||||||
int tranferbit = target.isTransferNode() ? TRANSFERNODE_BITMASK : 0;
|
int tranferbit = target.isTransferNode() ? TRANSFERNODE_BITMASK : 0;
|
||||||
int nodedescbit = nodeDescription != null ? NODEDESC_BITMASK : 0;
|
int nodedescbit = nodeDescription != null ? NODEDESC_BITMASK : 0;
|
||||||
|
@ -139,9 +158,9 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
int writedescbit = 0;
|
int writedescbit = 0;
|
||||||
if ( skipDetailBit == 0 ) // check if description changed
|
if ( skipDetailBit == 0 ) // check if description changed
|
||||||
{
|
{
|
||||||
int inverseBitByteIndex = writeVarLength ? 0 : 7;
|
int inverseBitByteIndex = writeVarLength ? 0 : 7;
|
||||||
boolean inverseDirection = link.isReverse( origin );
|
boolean inverseDirection = link.isReverse( origin );
|
||||||
byte[] ab = link.descriptionBitmap;
|
byte[] ab = link.descriptionBitmap;
|
||||||
int abLen = ab.length;
|
int abLen = ab.length;
|
||||||
int lastLen = lastDescription == null ? 0 : lastDescription.length;
|
int lastLen = lastDescription == null ? 0 : lastDescription.length;
|
||||||
boolean equalsCurrent = abLen == lastLen;
|
boolean equalsCurrent = abLen == lastLen;
|
||||||
|
@ -151,17 +170,17 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
{
|
{
|
||||||
byte b = ab[i];
|
byte b = ab[i];
|
||||||
if ( i == inverseBitByteIndex && inverseDirection ) b ^= 1;
|
if ( i == inverseBitByteIndex && inverseDirection ) b ^= 1;
|
||||||
if ( b != lastDescription[i] ) { equalsCurrent = false; break; }
|
if ( b != lastDescription[i] ) { equalsCurrent = false; break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !equalsCurrent )
|
if ( !equalsCurrent )
|
||||||
{
|
{
|
||||||
writedescbit = WRITEDESC_BITMASK;
|
writedescbit = WRITEDESC_BITMASK;
|
||||||
lastDescription = new byte[abLen];
|
lastDescription = new byte[abLen];
|
||||||
System.arraycopy( ab, 0, lastDescription, 0 , abLen );
|
System.arraycopy( ab, 0, lastDescription, 0 , abLen );
|
||||||
if ( inverseDirection ) lastDescription[inverseBitByteIndex] ^= 1;
|
if ( inverseDirection ) lastDescription[inverseBitByteIndex] ^= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int bm = tranferbit | writedescbit | nodedescbit | skipDetailBit;
|
int bm = tranferbit | writedescbit | nodedescbit | skipDetailBit;
|
||||||
|
@ -190,14 +209,14 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
}
|
}
|
||||||
|
|
||||||
link.descriptionBitmap = null; // mark link as written
|
link.descriptionBitmap = null; // mark link as written
|
||||||
|
|
||||||
if ( tranferbit == 0)
|
if ( tranferbit == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
os2.writeVarLengthSigned( target.getSElev() -getSElev() );
|
os2.writeVarLengthSigned( target.getSElev() -getSElev() );
|
||||||
// next link is the one (of two), does does'nt point back
|
// next link is the one (of two), does does'nt point back
|
||||||
for( link = target.firstlink; link != null; link = link.getNext( target ) )
|
for( link = target.getFirstLink(); link != null; link = link.getNext( target ) )
|
||||||
{
|
{
|
||||||
if ( link.getTarget( target ) != origin ) break;
|
if ( link.getTarget( target ) != origin ) break;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +227,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
|
|
||||||
// calculate the body size
|
// calculate the body size
|
||||||
int bodySize = os2.size();
|
int bodySize = os2.size();
|
||||||
|
|
||||||
os.ensureCapacity( bodySize + 8 );
|
os.ensureCapacity( bodySize + 8 );
|
||||||
|
|
||||||
os.writeShort( (short)(ilon - lonIdx*62500 - 31250) );
|
os.writeShort( (short)(ilon - lonIdx*62500 - 31250) );
|
||||||
|
@ -237,7 +256,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
||||||
{
|
{
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
for( OsmLinkP link = firstlink; link != null; link = link.getNext( this ) )
|
for( OsmLinkP link = getFirstLink(); link != null; link = link.getNext( this ) )
|
||||||
{
|
{
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,10 +181,8 @@ public class WayLinker extends MapCreatorBase
|
||||||
n2 = nodesMap.get( nid );
|
n2 = nodesMap.get( nid );
|
||||||
if ( n1 != null && n2 != null && n1 != n2 )
|
if ( n1 != null && n2 != null && n1 != n2 )
|
||||||
{
|
{
|
||||||
OsmLinkP link = new OsmLinkP( n1, n2 );
|
OsmLinkP link = n2.createLink( n1 );
|
||||||
link.descriptionBitmap = description;
|
link.descriptionBitmap = description;
|
||||||
n1.addLink( link );
|
|
||||||
n2.addLink( link );
|
|
||||||
}
|
}
|
||||||
if ( n2 != null )
|
if ( n2 != null )
|
||||||
{
|
{
|
||||||
|
@ -214,7 +212,7 @@ public class WayLinker extends MapCreatorBase
|
||||||
LazyArrayOfLists<OsmNodeP> seglists = new LazyArrayOfLists<OsmNodeP>(nLonSegs*nLatSegs);
|
LazyArrayOfLists<OsmNodeP> seglists = new LazyArrayOfLists<OsmNodeP>(nLonSegs*nLatSegs);
|
||||||
for( OsmNodeP n : nodesList )
|
for( OsmNodeP n : nodesList )
|
||||||
{
|
{
|
||||||
if ( n == null || n.firstlink == null || n.isTransferNode() ) continue;
|
if ( n == null || n.getFirstLink() == null || n.isTransferNode() ) continue;
|
||||||
if ( n.ilon < minLon || n.ilon >= maxLon
|
if ( n.ilon < minLon || n.ilon >= maxLon
|
||||||
|| n.ilat < minLat || n.ilat >= maxLat ) continue;
|
|| n.ilat < minLat || n.ilat >= maxLat ) continue;
|
||||||
int lonIdx = (n.ilon-minLon)/1000000;
|
int lonIdx = (n.ilon-minLon)/1000000;
|
||||||
|
|
Loading…
Reference in a new issue