Speedup rendering

This commit is contained in:
Victor Shcherb 2012-08-14 00:13:13 +02:00
parent 08ba021591
commit 234825fbbb
3 changed files with 93 additions and 5 deletions

View file

@ -2,7 +2,6 @@ package net.osmand.binary;
import gnu.trove.map.hash.TIntObjectHashMap;
import net.osmand.binary.BinaryMapIndexReader.MapIndex;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.osm.MapRenderingTypes;
public class BinaryMapDataObject {
@ -114,10 +113,6 @@ public class BinaryMapDataObject {
this.area = area;
}
public TagValuePair getTagValue(int indType){
throw new UnsupportedOperationException("This functions is deprecated and should be deleted");
}
public long getId() {
return id;
}

View file

@ -440,6 +440,14 @@ public class OsmandRenderer {
}
rc.visible++;
int len = obj.getPointsLength();
// if(len > 150) {
// int[] ts = obj.getTypes();
// System.err.println("Polygon " + len);
// for(int i=0; i<ts.length; i++) {
// System.err.println(obj.getMapIndex().decodeType(ts[i]));
// }
// return;
// }
for (int i = 0; i < obj.getPointsLength(); i++) {
PointF p = calcPoint(obj, i, rc);
@ -659,11 +667,27 @@ public class OsmandRenderer {
textPoints = new PointF[length];
}
boolean intersect = false;
PointF prev = null;
for (int i = 0; i < length ; i++) {
PointF p = calcPoint(obj, i, rc);
if(textPoints != null) {
textPoints[i] = new PointF(p.x, p.y);
}
if (!intersect) {
if (p.x >= 0 && p.y >= 0 && p.x < rc.width && p.y < rc.height) {
intersect = true;
}
if (!intersect && prev != null) {
if ((p.x < 0 && prev.x < 0) || (p.y < 0 && prev.y < 0) || (p.x > rc.width && prev.x > rc.width)
|| (p.y > rc.height && prev.y > rc.height)) {
intersect = false;
} else {
intersect = true;
}
}
}
if (path == null) {
path = new Path();
path.moveTo(p.x, p.y);
@ -674,6 +698,15 @@ public class OsmandRenderer {
}
path.lineTo(p.x, p.y);
}
prev = p;
}
if (!intersect) {
// System.err.println("Not intersect ");
// int[] ts = obj.getTypes();
// for(int i=0; i<ts.length; i++) {
// System.err.println(obj.getMapIndex().decodeType(ts[i]));
// }
return;
}
if (path != null) {
if(drawOnlyShadow) {

View file

@ -373,6 +373,9 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas
int i = 0;
SkPoint middlePoint;
int middle = length / 2;
float prevx;
float prevy;
bool intersect = false;
for (; i < length; i++) {
calcPoint(mObj->points.at(i), rc);
if (i == 0) {
@ -383,6 +386,27 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas
}
path.lineTo(rc->calcX, rc->calcY);
}
if (!intersect) {
if (rc->calcX >= 0 && rc->calcY >= 0 && rc->calcX < rc->getWidth()&& rc->calcY < rc->getHeight()) {
intersect = true;
}
if (!intersect && i > 0) {
if ((rc->calcX < 0 && prevx < 0) || (rc->calcY < 0 && prevy < 0) ||
(rc->calcX> rc->getWidth() && prevx > rc->getWidth())
|| (rc->calcY > rc->getHeight() && prevy > rc->getHeight())) {
intersect = false;
} else {
intersect = true;
}
}
}
prevx = rc->calcX;
prevy = rc->calcY;
}
if (!intersect) {
return;
}
if (i > 0) {
@ -442,6 +466,10 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas*
rc->visible++;
SkPath path;
int i = 0;
float prevx;
float prevy;
bool intersect = false;
int bounds = 0;
for (; i < length; i++) {
calcPoint(mObj->points.at(i), rc);
if (i == 0) {
@ -451,6 +479,38 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas*
}
xText += rc->calcX;
yText += rc->calcY;
if (!intersect) {
if (rc->calcX >= 0 && rc->calcY >= 0 && rc->calcX < rc->getWidth() && rc->calcY < rc->getHeight()) {
intersect = true;
}
bounds |= (rc->calcX < 0 ? 1 : 0);
bounds |= (rc->calcX >= rc->getWidth() ? 2 : 0);
bounds |= (rc->calcY < 0 ? 4 : 0);
bounds |= (rc->calcY >= rc->getHeight() ? 8 : 0);
if (!intersect && i > 0) {
if ((rc->calcX < 0 && prevx < 0) || (rc->calcY < 0 && prevy < 0)
|| (rc->calcX > rc->getWidth() && prevx > rc->getWidth())
|| (rc->calcY > rc->getHeight() && prevy > rc->getHeight())) {
intersect = false;
} else {
intersect = true;
}
}
}
}
if(!intersect){
if(bounds == 15) {
path.reset();
path.moveTo(0, 0);
path.lineTo(0, rc->getWidth());
path.lineTo(rc->getHeight(), rc->getWidth());
path.lineTo(rc->getHeight(), 0);
path.close();
xText = rc->getWidth() / 2;
yText = rc->getHeight() / 2;
} else {
return;
}
}
std::vector<coordinates> polygonInnerCoordinates = mObj->polygonInnerCoordinates;
if (polygonInnerCoordinates.size() > 0) {