Alternative reprojection triangulation strategy
The quads are now subdivided more granually (to 2 instead of 4), which usually leads to reduced number of triangles and higher performance.
This commit is contained in:
+2
-2
@@ -189,9 +189,9 @@ ol.RASTER_REPROJ_MAX_SOURCE_TILES = 100;
|
|||||||
* @define {number} Maximum number of subdivision steps during raster
|
* @define {number} Maximum number of subdivision steps during raster
|
||||||
* reprojection triangulation. Prevents high memory usage and large
|
* reprojection triangulation. Prevents high memory usage and large
|
||||||
* number of proj4 calls when for certain transformations and areas.
|
* number of proj4 calls when for certain transformations and areas.
|
||||||
* At most `2*(4^this)` triangles are created. Default is `5`.
|
* At most `2*(2^this)` triangles are created. Default is `10`.
|
||||||
*/
|
*/
|
||||||
ol.RASTER_REPROJ_MAX_SUBDIVISION = 5;
|
ol.RASTER_REPROJ_MAX_SUBDIVISION = 10;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -185,10 +185,10 @@ ol.reproj.Triangulation.prototype.addQuadIfValid_ = function(a, b, c, d,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (maxSubdiv > 0) {
|
if (maxSubdiv > 0) {
|
||||||
var center = [(a[0] + c[0]) / 2, (a[1] + c[1]) / 2];
|
|
||||||
var centerSrc = this.transformInv_(center);
|
|
||||||
|
|
||||||
if (!needsSubdivision) {
|
if (!needsSubdivision) {
|
||||||
|
var center = [(a[0] + c[0]) / 2, (a[1] + c[1]) / 2];
|
||||||
|
var centerSrc = this.transformInv_(center);
|
||||||
|
|
||||||
var dx;
|
var dx;
|
||||||
if (wrapsX) {
|
if (wrapsX) {
|
||||||
goog.asserts.assert(!goog.isNull(this.sourceWorldWidth_));
|
goog.asserts.assert(!goog.isNull(this.sourceWorldWidth_));
|
||||||
@@ -205,24 +205,27 @@ ol.reproj.Triangulation.prototype.addQuadIfValid_ = function(a, b, c, d,
|
|||||||
needsSubdivision = centerSrcErrorSquared > this.errorThresholdSquared_;
|
needsSubdivision = centerSrcErrorSquared > this.errorThresholdSquared_;
|
||||||
}
|
}
|
||||||
if (needsSubdivision) {
|
if (needsSubdivision) {
|
||||||
var ab = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
|
if (Math.abs(a[0] - c[0]) <= Math.abs(a[1] - c[1])) {
|
||||||
var abSrc = this.transformInv_(ab);
|
var bc = [(b[0] + c[0]) / 2, (b[1] + c[1]) / 2];
|
||||||
var bc = [(b[0] + c[0]) / 2, (b[1] + c[1]) / 2];
|
var bcSrc = this.transformInv_(bc);
|
||||||
var bcSrc = this.transformInv_(bc);
|
var da = [(d[0] + a[0]) / 2, (d[1] + a[1]) / 2];
|
||||||
var cd = [(c[0] + d[0]) / 2, (c[1] + d[1]) / 2];
|
var daSrc = this.transformInv_(da);
|
||||||
var cdSrc = this.transformInv_(cd);
|
|
||||||
var da = [(d[0] + a[0]) / 2, (d[1] + a[1]) / 2];
|
|
||||||
var daSrc = this.transformInv_(da);
|
|
||||||
|
|
||||||
this.addQuadIfValid_(a, ab, center, da,
|
this.addQuadIfValid_(a, b, bc, da,
|
||||||
aSrc, abSrc, centerSrc, daSrc, maxSubdiv - 1);
|
aSrc, bSrc, bcSrc, daSrc, maxSubdiv - 1);
|
||||||
this.addQuadIfValid_(ab, b, bc, center,
|
this.addQuadIfValid_(da, bc, c, d,
|
||||||
abSrc, bSrc, bcSrc, centerSrc, maxSubdiv - 1);
|
daSrc, bcSrc, cSrc, dSrc, maxSubdiv - 1);
|
||||||
this.addQuadIfValid_(center, bc, c, cd,
|
} else {
|
||||||
centerSrc, bcSrc, cSrc, cdSrc, maxSubdiv - 1);
|
var ab = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
|
||||||
this.addQuadIfValid_(da, center, cd, d,
|
var abSrc = this.transformInv_(ab);
|
||||||
daSrc, centerSrc, cdSrc, dSrc, maxSubdiv - 1);
|
var cd = [(c[0] + d[0]) / 2, (c[1] + d[1]) / 2];
|
||||||
|
var cdSrc = this.transformInv_(cd);
|
||||||
|
|
||||||
|
this.addQuadIfValid_(a, ab, cd, d,
|
||||||
|
aSrc, abSrc, cdSrc, dSrc, maxSubdiv - 1);
|
||||||
|
this.addQuadIfValid_(ab, b, c, cd,
|
||||||
|
abSrc, bSrc, cSrc, cdSrc, maxSubdiv - 1);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user