diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java index fa4c1ae3..4e86d3ee 100644 --- a/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java +++ b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java @@ -269,8 +269,8 @@ public class GeoJsonTileDecoder implements ITileDecoder { } private void removeLastPoint() { - mMapElement.pointPos -= 2; - mMapElement.index[mMapElement.indexPos] -= 2; + mMapElement.pointNextPos -= 2; + mMapElement.index[mMapElement.indexCurrentPos] -= 2; } private void parseLineString(JsonParser jp) diff --git a/vtm-extras/src/org/oscim/tiling/source/mapnik/TileDecoder.java b/vtm-extras/src/org/oscim/tiling/source/mapnik/TileDecoder.java index de9eb773..da7a6787 100644 --- a/vtm-extras/src/org/oscim/tiling/source/mapnik/TileDecoder.java +++ b/vtm-extras/src/org/oscim/tiling/source/mapnik/TileDecoder.java @@ -484,8 +484,8 @@ public class TileDecoder extends PbfDecoder { // only add last point if it is di int ppos = cnt * 2; - if (elem.points[elem.pointPos - ppos] != curX - || elem.points[elem.pointPos - ppos + 1] != curY) + if (elem.points[elem.pointNextPos - ppos] != curX + || elem.points[elem.pointNextPos - ppos + 1] != curY) elem.addPoint(curX / mScale, curY / mScale); lastClip = false; @@ -525,10 +525,10 @@ public class TileDecoder extends PbfDecoder { if (isPoly && isOuter && simplify && !testBBox(xmax - xmin, ymax - ymin)) { //log.debug("skip small poly "+ elem.indexPos + " > " // + (xmax - xmin) * (ymax - ymin)); - elem.pointPos -= elem.index[elem.indexPos]; - if (elem.indexPos > 0) { - elem.indexPos -= 2; - elem.index[elem.indexPos + 1] = -1; + elem.pointNextPos -= elem.index[elem.indexCurrentPos]; + if (elem.indexCurrentPos > 0) { + elem.indexCurrentPos -= 2; + elem.index[elem.indexCurrentPos + 1] = -1; } else { elem.type = GeometryType.NONE; } diff --git a/vtm-json/src/org/oscim/tiling/source/geojson/TileDecoder.java b/vtm-json/src/org/oscim/tiling/source/geojson/TileDecoder.java index 2ca9cb9a..ab6396e8 100644 --- a/vtm-json/src/org/oscim/tiling/source/geojson/TileDecoder.java +++ b/vtm-json/src/org/oscim/tiling/source/geojson/TileDecoder.java @@ -266,8 +266,8 @@ public class TileDecoder implements ITileDecoder { } private void removeLastPoint() { - mMapElement.pointPos -= 2; - mMapElement.index[mMapElement.indexPos] -= 2; + mMapElement.pointNextPos -= 2; + mMapElement.index[mMapElement.indexCurrentPos] -= 2; } private void parseLineString(JsonParser jp) throws IOException { diff --git a/vtm/src/org/oscim/core/GeometryBuffer.java b/vtm/src/org/oscim/core/GeometryBuffer.java index 556dc936..7647da66 100644 --- a/vtm/src/org/oscim/core/GeometryBuffer.java +++ b/vtm/src/org/oscim/core/GeometryBuffer.java @@ -56,23 +56,35 @@ public class GeometryBuffer { /** * The points. + *

+ * POLY/LINE: store point in order of polygon with + * points[2 * n + 0] = x; points[2 * n + 1] = y; n is a N. + *

+ * 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; /** * The indexes. + *

+ * POLY/LINE: store 2 * number of points of each polygon / line. Point is (x, y). + *

+ * 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; /** * 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. @@ -111,8 +123,8 @@ public class GeometryBuffer { this.points = points; this.index = index; this.type = GeometryType.NONE; - this.indexPos = 0; - this.pointPos = 0; + this.indexCurrentPos = 0; + this.pointNextPos = 0; this.pointLimit = points.length - 2; } @@ -145,7 +157,7 @@ public class GeometryBuffer { } public int getNumPoints() { - return pointPos >> 1; + return pointNextPos >> 1; } /** @@ -153,8 +165,8 @@ public class GeometryBuffer { */ public GeometryBuffer clear() { index[0] = 0; - indexPos = 0; - pointPos = 0; + indexCurrentPos = 0; + pointNextPos = 0; type = GeometryType.NONE; return this; } @@ -166,13 +178,13 @@ public class GeometryBuffer { * @param y the y ordinate */ public GeometryBuffer addPoint(float x, float y) { - if (pointPos > pointLimit) - ensurePointSize((pointPos >> 1) + 1, true); + if (pointNextPos > pointLimit) + ensurePointSize((pointNextPos >> 1) + 1, true); - points[pointPos++] = x; - points[pointPos++] = y; + points[pointNextPos++] = x; + points[pointNextPos++] = y; - index[indexPos] += 2; + index[indexCurrentPos] += 2; return this; } @@ -188,6 +200,10 @@ public class GeometryBuffer { return type == GeometryType.POINT; } + public boolean isTris() { + return type == GeometryType.TRIS; + } + /** * Sets the point x,y at position pos. * @@ -214,19 +230,19 @@ public class GeometryBuffer { setOrCheckMode(GeometryType.LINE); /* ignore */ - if (index[indexPos] > 0) { + if (index[indexCurrentPos] > 0) { /* start next */ - if ((index[0] >= 0) && (++indexPos >= index.length)) - ensureIndexSize(indexPos, true); + if ((index[0] >= 0) && (++indexCurrentPos >= index.length)) + ensureIndexSize(indexCurrentPos, true); /* initialize with zero points */ - index[indexPos] = 0; + index[indexCurrentPos] = 0; } /* set new end marker */ - if (index.length > indexPos + 1) - index[indexPos + 1] = -1; + if (index.length > indexCurrentPos + 1) + index[indexCurrentPos + 1] = -1; return this; } @@ -237,23 +253,23 @@ public class GeometryBuffer { boolean start = (type == GeometryType.NONE); setOrCheckMode(GeometryType.POLY); - if ((indexPos + 3) > index.length) - ensureIndexSize(indexPos + 2, true); + if ((indexCurrentPos + 3) > index.length) + ensureIndexSize(indexCurrentPos + 2, true); - if (!start && index[indexPos] != 0) { + if (!start && index[indexCurrentPos] != 0) { /* end polygon */ - index[++indexPos] = 0; + index[++indexCurrentPos] = 0; /* next polygon start */ - indexPos++; + indexCurrentPos++; } /* initialize with zero points */ - index[indexPos] = 0; + index[indexCurrentPos] = 0; /* set new end marker */ - if (index.length > indexPos + 1) - index[indexPos + 1] = -1; + if (index.length > indexCurrentPos + 1) + index[indexCurrentPos + 1] = -1; return this; } @@ -264,19 +280,19 @@ public class GeometryBuffer { public void startHole() { checkMode(GeometryType.POLY); - if ((indexPos + 2) > index.length) - ensureIndexSize(indexPos + 1, true); + if ((indexCurrentPos + 2) > index.length) + ensureIndexSize(indexCurrentPos + 1, true); /* initialize with zero points */ - index[++indexPos] = 0; + index[++indexCurrentPos] = 0; /* set new end marker */ - if (index.length > indexPos + 1) - index[indexPos + 1] = -1; + if (index.length > indexCurrentPos + 1) + index[indexCurrentPos + 1] = -1; } 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 + 1] += dy; } @@ -284,7 +300,7 @@ public class GeometryBuffer { } 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 + 1] *= scaleY; } @@ -439,24 +455,43 @@ public class GeometryBuffer { for (int i = 0; i < index.length; i++) { if (index[i] < 0) break; - if (index[i] == 0) - continue; - sb.append(":"); - sb.append(index[i]); - sb.append('\n'); - for (int j = 0; j < index[i]; j += 2) { - sb.append('[') - .append(points[o + j]) - .append(',') - .append(points[o + j + 1]) + if (!isTris()) { + if (index[i] == 0) + continue; + sb.append("POLY (") + .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(']'); - - if (j % 4 == 0) - sb.append('\n'); + if (i % 3 == 2) + sb.append(" }\n"); } - sb.append('\n'); - o += index[i]; } return sb.toString(); } diff --git a/vtm/src/org/oscim/core/MapElement.java b/vtm/src/org/oscim/core/MapElement.java index 7b6398ab..871d2280 100644 --- a/vtm/src/org/oscim/core/MapElement.java +++ b/vtm/src/org/oscim/core/MapElement.java @@ -77,22 +77,22 @@ public class MapElement extends GeometryBuffer { * @return a deep copy of this MapElement */ public MapElement clone() { - int indexSize = this.indexPos + 1; + int indexSize = this.indexCurrentPos + 1; for (int i = 0; i < this.index.length; i++) { if (this.index[i] == -1) { indexSize = i; break; } } - float[] copyPoints = Arrays.copyOf(this.points, this.pointPos); + float[] copyPoints = Arrays.copyOf(this.points, this.pointNextPos); int[] copyIndex = Arrays.copyOf(this.index, indexSize); MapElement copy = new MapElement(copyPoints, copyIndex); copy.tags.set(this.tags.asArray()); - copy.pointPos = this.pointPos; + copy.pointNextPos = this.pointNextPos; copy.labelPosition = this.labelPosition; copy.setLayer(this.layer); - copy.indexPos = this.indexPos; + copy.indexCurrentPos = this.indexCurrentPos; copy.type = this.type; return copy; } diff --git a/vtm/src/org/oscim/renderer/bucket/MeshBucket.java b/vtm/src/org/oscim/renderer/bucket/MeshBucket.java index b15e9951..3579a93f 100644 --- a/vtm/src/org/oscim/renderer/bucket/MeshBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/MeshBucket.java @@ -53,7 +53,7 @@ public class MeshBucket extends RenderBucket { } public void addMesh(GeometryBuffer geom) { - numPoints += geom.pointPos; + numPoints += geom.pointNextPos; if (tess == null) tess = new TessJNI(8); diff --git a/vtm/src/org/oscim/tiling/source/PbfDecoder.java b/vtm/src/org/oscim/tiling/source/PbfDecoder.java index a51ed4e6..34574065 100644 --- a/vtm/src/org/oscim/tiling/source/PbfDecoder.java +++ b/vtm/src/org/oscim/tiling/source/PbfDecoder.java @@ -244,7 +244,7 @@ public abstract class PbfDecoder implements ITileDecoder { bufferPos = pos; - geom.pointPos = cnt; + geom.pointNextPos = cnt; // return number of points read return (cnt >> 1); diff --git a/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java b/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java index 4198b8ff..f35d3a2a 100644 --- a/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java +++ b/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java @@ -723,8 +723,8 @@ public class MapDatabase implements ITileDataSource { int[] buffer = mIntBuffer; mReadBuffer.readSignedInt(buffer, length); - float[] outBuffer = e.ensurePointSize(e.pointPos + length, true); - int outPos = e.pointPos; + float[] outBuffer = e.ensurePointSize(e.pointNextPos + length, true); + int outPos = e.pointNextPos; int lat, lon; /* first node latitude single-delta offset */ @@ -772,7 +772,7 @@ public class MapDatabase implements ITileDataSource { } } - e.pointPos = outPos; + e.pointNextPos = outPos; return cnt; } diff --git a/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java b/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java index 42707579..4f3e7780 100644 --- a/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java +++ b/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java @@ -328,7 +328,7 @@ public class TileDecoder extends PbfDecoder { Integer.valueOf(cnt)); fail = true; } - mElem.pointPos = cnt; + mElem.pointNextPos = cnt; } else { mElem.ensurePointSize(coordCnt, false); int cnt = decodeInterleavedPoints(mElem, mScaleFactor); diff --git a/vtm/src/org/oscim/utils/geom/SimplifyVW.java b/vtm/src/org/oscim/utils/geom/SimplifyVW.java index e37a3e30..0afe6a5d 100644 --- a/vtm/src/org/oscim/utils/geom/SimplifyVW.java +++ b/vtm/src/org/oscim/utils/geom/SimplifyVW.java @@ -54,12 +54,12 @@ public class SimplifyVW { size = 0; - if (heap.length < geom.pointPos >> 1) - heap = new Item[geom.pointPos >> 1]; + if (heap.length < geom.pointNextPos >> 1) + heap = new Item[geom.pointNextPos >> 1]; 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)); prev.next = it; it.prev = prev; @@ -67,7 +67,7 @@ public class SimplifyVW { 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); // for (int i = 0; i < size; i++) @@ -102,8 +102,8 @@ public class SimplifyVW { first.prev = null; it = first; - float[] points = new float[geom.pointPos]; - System.arraycopy(geom.points, 0, points, 0, geom.pointPos); + float[] points = new float[geom.pointNextPos]; + System.arraycopy(geom.points, 0, points, 0, geom.pointNextPos); geom.clear(); geom.startPolygon(); diff --git a/vtm/src/org/oscim/utils/geom/TileClipper.java b/vtm/src/org/oscim/utils/geom/TileClipper.java index 68ffebfa..82c47c8c 100644 --- a/vtm/src/org/oscim/utils/geom/TileClipper.java +++ b/vtm/src/org/oscim/utils/geom/TileClipper.java @@ -68,7 +68,7 @@ public class TileClipper { clipEdge(out, geom, LineClipper.BOTTOM); - if ((geom.indexPos == 0) && (geom.index[0] < 6)) + if ((geom.indexCurrentPos == 0) && (geom.index[0] < 6)) return false; } else if (geom.isLine()) { @@ -81,12 +81,12 @@ public class TileClipper { System.arraycopy(out.index, 0, idx, 0, numLines); geom.index[numLines] = -1; - float pts[] = geom.ensurePointSize(out.pointPos >> 1, false); - System.arraycopy(out.points, 0, pts, 0, out.pointPos); - geom.indexPos = out.indexPos; - geom.pointPos = out.pointPos; + float pts[] = geom.ensurePointSize(out.pointNextPos >> 1, false); + System.arraycopy(out.points, 0, pts, 0, out.pointNextPos); + geom.indexCurrentPos = out.indexCurrentPos; + geom.pointNextPos = out.pointNextPos; - if ((geom.indexPos == 0) && (geom.index[0] < 4)) + if ((geom.indexCurrentPos == 0) && (geom.index[0] < 4)) return false; } return true;