GeometryBuffer: (#453)
+ renamed buffer positions + update docs + expand toString for meshes/tris
This commit is contained in:
@@ -269,8 +269,8 @@ public class GeoJsonTileDecoder implements ITileDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeLastPoint() {
|
private void removeLastPoint() {
|
||||||
mMapElement.pointPos -= 2;
|
mMapElement.pointNextPos -= 2;
|
||||||
mMapElement.index[mMapElement.indexPos] -= 2;
|
mMapElement.index[mMapElement.indexCurrentPos] -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseLineString(JsonParser jp)
|
private void parseLineString(JsonParser jp)
|
||||||
|
|||||||
@@ -484,8 +484,8 @@ public class TileDecoder extends PbfDecoder {
|
|||||||
|
|
||||||
// only add last point if it is di
|
// only add last point if it is di
|
||||||
int ppos = cnt * 2;
|
int ppos = cnt * 2;
|
||||||
if (elem.points[elem.pointPos - ppos] != curX
|
if (elem.points[elem.pointNextPos - ppos] != curX
|
||||||
|| elem.points[elem.pointPos - ppos + 1] != curY)
|
|| elem.points[elem.pointNextPos - ppos + 1] != curY)
|
||||||
elem.addPoint(curX / mScale, curY / mScale);
|
elem.addPoint(curX / mScale, curY / mScale);
|
||||||
|
|
||||||
lastClip = false;
|
lastClip = false;
|
||||||
@@ -525,10 +525,10 @@ public class TileDecoder extends PbfDecoder {
|
|||||||
if (isPoly && isOuter && simplify && !testBBox(xmax - xmin, ymax - ymin)) {
|
if (isPoly && isOuter && simplify && !testBBox(xmax - xmin, ymax - ymin)) {
|
||||||
//log.debug("skip small poly "+ elem.indexPos + " > "
|
//log.debug("skip small poly "+ elem.indexPos + " > "
|
||||||
// + (xmax - xmin) * (ymax - ymin));
|
// + (xmax - xmin) * (ymax - ymin));
|
||||||
elem.pointPos -= elem.index[elem.indexPos];
|
elem.pointNextPos -= elem.index[elem.indexCurrentPos];
|
||||||
if (elem.indexPos > 0) {
|
if (elem.indexCurrentPos > 0) {
|
||||||
elem.indexPos -= 2;
|
elem.indexCurrentPos -= 2;
|
||||||
elem.index[elem.indexPos + 1] = -1;
|
elem.index[elem.indexCurrentPos + 1] = -1;
|
||||||
} else {
|
} else {
|
||||||
elem.type = GeometryType.NONE;
|
elem.type = GeometryType.NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,8 +266,8 @@ public class TileDecoder implements ITileDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeLastPoint() {
|
private void removeLastPoint() {
|
||||||
mMapElement.pointPos -= 2;
|
mMapElement.pointNextPos -= 2;
|
||||||
mMapElement.index[mMapElement.indexPos] -= 2;
|
mMapElement.index[mMapElement.indexCurrentPos] -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseLineString(JsonParser jp) throws IOException {
|
private void parseLineString(JsonParser jp) throws IOException {
|
||||||
|
|||||||
@@ -56,23 +56,35 @@ public class GeometryBuffer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The points.
|
* The points.
|
||||||
|
* <p>
|
||||||
|
* POLY/LINE: store point in order of polygon with
|
||||||
|
* points[2 * n + 0] = x; points[2 * n + 1] = y; n is a N.
|
||||||
|
* <p>
|
||||||
|
* MESH: store points anywhere with
|
||||||
|
* points[3 * n + 0] = x; points[3 * n + 1] = y; points[3 * n + 2] = z; n ∈ ℕ0.
|
||||||
*/
|
*/
|
||||||
public float[] points;
|
public float[] points;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The indexes.
|
* The indexes.
|
||||||
|
* <p>
|
||||||
|
* POLY/LINE: store 2 * number of points of each polygon / line. Point is (x, y).
|
||||||
|
* <p>
|
||||||
|
* MESH: store point indices of triangle (p1, p2, p3) with
|
||||||
|
* index[3 * n + 0] = p1; index[3 * n + 1] = p2; index[3 * n + 2] = p3; n ∈ ℕ0.
|
||||||
|
* Point p is (x, y, z).
|
||||||
*/
|
*/
|
||||||
public int[] index;
|
public int[] index;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current index position.
|
* The current index position.
|
||||||
*/
|
*/
|
||||||
public int indexPos;
|
public int indexCurrentPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current position in points array.
|
* The next position to insert a point in points array (equal to array size).
|
||||||
*/
|
*/
|
||||||
public int pointPos;
|
public int pointNextPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current geometry type.
|
* The current geometry type.
|
||||||
@@ -111,8 +123,8 @@ public class GeometryBuffer {
|
|||||||
this.points = points;
|
this.points = points;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.type = GeometryType.NONE;
|
this.type = GeometryType.NONE;
|
||||||
this.indexPos = 0;
|
this.indexCurrentPos = 0;
|
||||||
this.pointPos = 0;
|
this.pointNextPos = 0;
|
||||||
this.pointLimit = points.length - 2;
|
this.pointLimit = points.length - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +157,7 @@ public class GeometryBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getNumPoints() {
|
public int getNumPoints() {
|
||||||
return pointPos >> 1;
|
return pointNextPos >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,8 +165,8 @@ public class GeometryBuffer {
|
|||||||
*/
|
*/
|
||||||
public GeometryBuffer clear() {
|
public GeometryBuffer clear() {
|
||||||
index[0] = 0;
|
index[0] = 0;
|
||||||
indexPos = 0;
|
indexCurrentPos = 0;
|
||||||
pointPos = 0;
|
pointNextPos = 0;
|
||||||
type = GeometryType.NONE;
|
type = GeometryType.NONE;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -166,13 +178,13 @@ public class GeometryBuffer {
|
|||||||
* @param y the y ordinate
|
* @param y the y ordinate
|
||||||
*/
|
*/
|
||||||
public GeometryBuffer addPoint(float x, float y) {
|
public GeometryBuffer addPoint(float x, float y) {
|
||||||
if (pointPos > pointLimit)
|
if (pointNextPos > pointLimit)
|
||||||
ensurePointSize((pointPos >> 1) + 1, true);
|
ensurePointSize((pointNextPos >> 1) + 1, true);
|
||||||
|
|
||||||
points[pointPos++] = x;
|
points[pointNextPos++] = x;
|
||||||
points[pointPos++] = y;
|
points[pointNextPos++] = y;
|
||||||
|
|
||||||
index[indexPos] += 2;
|
index[indexCurrentPos] += 2;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +200,10 @@ public class GeometryBuffer {
|
|||||||
return type == GeometryType.POINT;
|
return type == GeometryType.POINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTris() {
|
||||||
|
return type == GeometryType.TRIS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the point x,y at position pos.
|
* Sets the point x,y at position pos.
|
||||||
*
|
*
|
||||||
@@ -214,19 +230,19 @@ public class GeometryBuffer {
|
|||||||
setOrCheckMode(GeometryType.LINE);
|
setOrCheckMode(GeometryType.LINE);
|
||||||
|
|
||||||
/* ignore */
|
/* ignore */
|
||||||
if (index[indexPos] > 0) {
|
if (index[indexCurrentPos] > 0) {
|
||||||
|
|
||||||
/* start next */
|
/* start next */
|
||||||
if ((index[0] >= 0) && (++indexPos >= index.length))
|
if ((index[0] >= 0) && (++indexCurrentPos >= index.length))
|
||||||
ensureIndexSize(indexPos, true);
|
ensureIndexSize(indexCurrentPos, true);
|
||||||
|
|
||||||
/* initialize with zero points */
|
/* initialize with zero points */
|
||||||
index[indexPos] = 0;
|
index[indexCurrentPos] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set new end marker */
|
/* set new end marker */
|
||||||
if (index.length > indexPos + 1)
|
if (index.length > indexCurrentPos + 1)
|
||||||
index[indexPos + 1] = -1;
|
index[indexCurrentPos + 1] = -1;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,23 +253,23 @@ public class GeometryBuffer {
|
|||||||
boolean start = (type == GeometryType.NONE);
|
boolean start = (type == GeometryType.NONE);
|
||||||
setOrCheckMode(GeometryType.POLY);
|
setOrCheckMode(GeometryType.POLY);
|
||||||
|
|
||||||
if ((indexPos + 3) > index.length)
|
if ((indexCurrentPos + 3) > index.length)
|
||||||
ensureIndexSize(indexPos + 2, true);
|
ensureIndexSize(indexCurrentPos + 2, true);
|
||||||
|
|
||||||
if (!start && index[indexPos] != 0) {
|
if (!start && index[indexCurrentPos] != 0) {
|
||||||
/* end polygon */
|
/* end polygon */
|
||||||
index[++indexPos] = 0;
|
index[++indexCurrentPos] = 0;
|
||||||
|
|
||||||
/* next polygon start */
|
/* next polygon start */
|
||||||
indexPos++;
|
indexCurrentPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize with zero points */
|
/* initialize with zero points */
|
||||||
index[indexPos] = 0;
|
index[indexCurrentPos] = 0;
|
||||||
|
|
||||||
/* set new end marker */
|
/* set new end marker */
|
||||||
if (index.length > indexPos + 1)
|
if (index.length > indexCurrentPos + 1)
|
||||||
index[indexPos + 1] = -1;
|
index[indexCurrentPos + 1] = -1;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -264,19 +280,19 @@ public class GeometryBuffer {
|
|||||||
public void startHole() {
|
public void startHole() {
|
||||||
checkMode(GeometryType.POLY);
|
checkMode(GeometryType.POLY);
|
||||||
|
|
||||||
if ((indexPos + 2) > index.length)
|
if ((indexCurrentPos + 2) > index.length)
|
||||||
ensureIndexSize(indexPos + 1, true);
|
ensureIndexSize(indexCurrentPos + 1, true);
|
||||||
|
|
||||||
/* initialize with zero points */
|
/* initialize with zero points */
|
||||||
index[++indexPos] = 0;
|
index[++indexCurrentPos] = 0;
|
||||||
|
|
||||||
/* set new end marker */
|
/* set new end marker */
|
||||||
if (index.length > indexPos + 1)
|
if (index.length > indexCurrentPos + 1)
|
||||||
index[indexPos + 1] = -1;
|
index[indexCurrentPos + 1] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeometryBuffer translate(float dx, float dy) {
|
public GeometryBuffer translate(float dx, float dy) {
|
||||||
for (int i = 0; i < pointPos; i += 2) {
|
for (int i = 0; i < pointNextPos; i += 2) {
|
||||||
points[i] += dx;
|
points[i] += dx;
|
||||||
points[i + 1] += dy;
|
points[i + 1] += dy;
|
||||||
}
|
}
|
||||||
@@ -284,7 +300,7 @@ public class GeometryBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GeometryBuffer scale(float scaleX, float scaleY) {
|
public GeometryBuffer scale(float scaleX, float scaleY) {
|
||||||
for (int i = 0; i < pointPos; i += 2) {
|
for (int i = 0; i < pointNextPos; i += 2) {
|
||||||
points[i] *= scaleX;
|
points[i] *= scaleX;
|
||||||
points[i + 1] *= scaleY;
|
points[i + 1] *= scaleY;
|
||||||
}
|
}
|
||||||
@@ -439,24 +455,43 @@ public class GeometryBuffer {
|
|||||||
for (int i = 0; i < index.length; i++) {
|
for (int i = 0; i < index.length; i++) {
|
||||||
if (index[i] < 0)
|
if (index[i] < 0)
|
||||||
break;
|
break;
|
||||||
if (index[i] == 0)
|
|
||||||
continue;
|
|
||||||
sb.append(":");
|
|
||||||
sb.append(index[i]);
|
|
||||||
sb.append('\n');
|
|
||||||
|
|
||||||
for (int j = 0; j < index[i]; j += 2) {
|
if (!isTris()) {
|
||||||
sb.append('[')
|
if (index[i] == 0)
|
||||||
.append(points[o + j])
|
continue;
|
||||||
.append(',')
|
sb.append("POLY (")
|
||||||
.append(points[o + j + 1])
|
.append(i)
|
||||||
|
.append(") { ");
|
||||||
|
|
||||||
|
for (int j = 0; j < index[i]; j += 2) {
|
||||||
|
sb.append('[')
|
||||||
|
.append(points[o + j])
|
||||||
|
.append(", ")
|
||||||
|
.append(points[o + j + 1])
|
||||||
|
.append(']');
|
||||||
|
|
||||||
|
if (j % 4 == 0)
|
||||||
|
sb.append('\n');
|
||||||
|
}
|
||||||
|
sb.append(" } \tnumPoints:")
|
||||||
|
.append(index[i])
|
||||||
|
.append('\n');
|
||||||
|
o += index[i];
|
||||||
|
} else {
|
||||||
|
if (i % 3 == 0)
|
||||||
|
sb.append("TRIS { ");
|
||||||
|
sb.append('\t')
|
||||||
|
.append(index[i])
|
||||||
|
.append('[')
|
||||||
|
.append(points[3 * index[i]])
|
||||||
|
.append(", ")
|
||||||
|
.append(points[3 * index[i] + 1])
|
||||||
|
.append(", ")
|
||||||
|
.append(points[3 * index[i] + 2])
|
||||||
.append(']');
|
.append(']');
|
||||||
|
if (i % 3 == 2)
|
||||||
if (j % 4 == 0)
|
sb.append(" }\n");
|
||||||
sb.append('\n');
|
|
||||||
}
|
}
|
||||||
sb.append('\n');
|
|
||||||
o += index[i];
|
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,22 +77,22 @@ public class MapElement extends GeometryBuffer {
|
|||||||
* @return a deep copy of this MapElement
|
* @return a deep copy of this MapElement
|
||||||
*/
|
*/
|
||||||
public MapElement clone() {
|
public MapElement clone() {
|
||||||
int indexSize = this.indexPos + 1;
|
int indexSize = this.indexCurrentPos + 1;
|
||||||
for (int i = 0; i < this.index.length; i++) {
|
for (int i = 0; i < this.index.length; i++) {
|
||||||
if (this.index[i] == -1) {
|
if (this.index[i] == -1) {
|
||||||
indexSize = i;
|
indexSize = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float[] copyPoints = Arrays.copyOf(this.points, this.pointPos);
|
float[] copyPoints = Arrays.copyOf(this.points, this.pointNextPos);
|
||||||
int[] copyIndex = Arrays.copyOf(this.index, indexSize);
|
int[] copyIndex = Arrays.copyOf(this.index, indexSize);
|
||||||
|
|
||||||
MapElement copy = new MapElement(copyPoints, copyIndex);
|
MapElement copy = new MapElement(copyPoints, copyIndex);
|
||||||
copy.tags.set(this.tags.asArray());
|
copy.tags.set(this.tags.asArray());
|
||||||
copy.pointPos = this.pointPos;
|
copy.pointNextPos = this.pointNextPos;
|
||||||
copy.labelPosition = this.labelPosition;
|
copy.labelPosition = this.labelPosition;
|
||||||
copy.setLayer(this.layer);
|
copy.setLayer(this.layer);
|
||||||
copy.indexPos = this.indexPos;
|
copy.indexCurrentPos = this.indexCurrentPos;
|
||||||
copy.type = this.type;
|
copy.type = this.type;
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class MeshBucket extends RenderBucket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addMesh(GeometryBuffer geom) {
|
public void addMesh(GeometryBuffer geom) {
|
||||||
numPoints += geom.pointPos;
|
numPoints += geom.pointNextPos;
|
||||||
if (tess == null)
|
if (tess == null)
|
||||||
tess = new TessJNI(8);
|
tess = new TessJNI(8);
|
||||||
|
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ public abstract class PbfDecoder implements ITileDecoder {
|
|||||||
|
|
||||||
bufferPos = pos;
|
bufferPos = pos;
|
||||||
|
|
||||||
geom.pointPos = cnt;
|
geom.pointNextPos = cnt;
|
||||||
|
|
||||||
// return number of points read
|
// return number of points read
|
||||||
return (cnt >> 1);
|
return (cnt >> 1);
|
||||||
|
|||||||
@@ -723,8 +723,8 @@ public class MapDatabase implements ITileDataSource {
|
|||||||
int[] buffer = mIntBuffer;
|
int[] buffer = mIntBuffer;
|
||||||
mReadBuffer.readSignedInt(buffer, length);
|
mReadBuffer.readSignedInt(buffer, length);
|
||||||
|
|
||||||
float[] outBuffer = e.ensurePointSize(e.pointPos + length, true);
|
float[] outBuffer = e.ensurePointSize(e.pointNextPos + length, true);
|
||||||
int outPos = e.pointPos;
|
int outPos = e.pointNextPos;
|
||||||
int lat, lon;
|
int lat, lon;
|
||||||
|
|
||||||
/* first node latitude single-delta offset */
|
/* first node latitude single-delta offset */
|
||||||
@@ -772,7 +772,7 @@ public class MapDatabase implements ITileDataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.pointPos = outPos;
|
e.pointNextPos = outPos;
|
||||||
|
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ public class TileDecoder extends PbfDecoder {
|
|||||||
Integer.valueOf(cnt));
|
Integer.valueOf(cnt));
|
||||||
fail = true;
|
fail = true;
|
||||||
}
|
}
|
||||||
mElem.pointPos = cnt;
|
mElem.pointNextPos = cnt;
|
||||||
} else {
|
} else {
|
||||||
mElem.ensurePointSize(coordCnt, false);
|
mElem.ensurePointSize(coordCnt, false);
|
||||||
int cnt = decodeInterleavedPoints(mElem, mScaleFactor);
|
int cnt = decodeInterleavedPoints(mElem, mScaleFactor);
|
||||||
|
|||||||
@@ -54,12 +54,12 @@ public class SimplifyVW {
|
|||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
if (heap.length < geom.pointPos >> 1)
|
if (heap.length < geom.pointNextPos >> 1)
|
||||||
heap = new Item[geom.pointPos >> 1];
|
heap = new Item[geom.pointNextPos >> 1];
|
||||||
|
|
||||||
first = prev = push(0, Float.MAX_VALUE);
|
first = prev = push(0, Float.MAX_VALUE);
|
||||||
|
|
||||||
for (int i = 2; i < geom.pointPos - 2; i += 2) {
|
for (int i = 2; i < geom.pointNextPos - 2; i += 2) {
|
||||||
it = push(i, area(geom.points, i - 2, i, i + 2));
|
it = push(i, area(geom.points, i - 2, i, i + 2));
|
||||||
prev.next = it;
|
prev.next = it;
|
||||||
it.prev = prev;
|
it.prev = prev;
|
||||||
@@ -67,7 +67,7 @@ public class SimplifyVW {
|
|||||||
prev = it;
|
prev = it;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item last = push(geom.pointPos - 2, Float.MAX_VALUE);
|
Item last = push(geom.pointNextPos - 2, Float.MAX_VALUE);
|
||||||
|
|
||||||
// sorter.doSort(heap, DistanceComparator, 0, size);
|
// sorter.doSort(heap, DistanceComparator, 0, size);
|
||||||
// for (int i = 0; i < size; i++)
|
// for (int i = 0; i < size; i++)
|
||||||
@@ -102,8 +102,8 @@ public class SimplifyVW {
|
|||||||
first.prev = null;
|
first.prev = null;
|
||||||
it = first;
|
it = first;
|
||||||
|
|
||||||
float[] points = new float[geom.pointPos];
|
float[] points = new float[geom.pointNextPos];
|
||||||
System.arraycopy(geom.points, 0, points, 0, geom.pointPos);
|
System.arraycopy(geom.points, 0, points, 0, geom.pointNextPos);
|
||||||
|
|
||||||
geom.clear();
|
geom.clear();
|
||||||
geom.startPolygon();
|
geom.startPolygon();
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class TileClipper {
|
|||||||
|
|
||||||
clipEdge(out, geom, LineClipper.BOTTOM);
|
clipEdge(out, geom, LineClipper.BOTTOM);
|
||||||
|
|
||||||
if ((geom.indexPos == 0) && (geom.index[0] < 6))
|
if ((geom.indexCurrentPos == 0) && (geom.index[0] < 6))
|
||||||
return false;
|
return false;
|
||||||
} else if (geom.isLine()) {
|
} else if (geom.isLine()) {
|
||||||
|
|
||||||
@@ -81,12 +81,12 @@ public class TileClipper {
|
|||||||
System.arraycopy(out.index, 0, idx, 0, numLines);
|
System.arraycopy(out.index, 0, idx, 0, numLines);
|
||||||
geom.index[numLines] = -1;
|
geom.index[numLines] = -1;
|
||||||
|
|
||||||
float pts[] = geom.ensurePointSize(out.pointPos >> 1, false);
|
float pts[] = geom.ensurePointSize(out.pointNextPos >> 1, false);
|
||||||
System.arraycopy(out.points, 0, pts, 0, out.pointPos);
|
System.arraycopy(out.points, 0, pts, 0, out.pointNextPos);
|
||||||
geom.indexPos = out.indexPos;
|
geom.indexCurrentPos = out.indexCurrentPos;
|
||||||
geom.pointPos = out.pointPos;
|
geom.pointNextPos = out.pointNextPos;
|
||||||
|
|
||||||
if ((geom.indexPos == 0) && (geom.index[0] < 4))
|
if ((geom.indexCurrentPos == 0) && (geom.index[0] < 4))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user