Dynamically chose the number of subdivisions based on the size of the Image.

This commit is contained in:
philip
2020-01-14 13:39:52 +00:00
parent c851f6c6bf
commit d2b0599177
3 changed files with 10 additions and 5 deletions

View File

@@ -47,7 +47,7 @@ class ReprojImage extends ImageBase {
const triangulation = new Triangulation(
sourceProj, targetProj, limitedTargetExtent, maxSourceExtent,
sourceResolution * errorThresholdInPixels);
sourceResolution * errorThresholdInPixels, targetResolution);
const sourceExtent = triangulation.calculateSourceExtent();
const sourceImage = getImageFunction(sourceExtent, sourceResolution, pixelRatio);

View File

@@ -160,7 +160,7 @@ class ReprojTile extends Tile {
*/
this.triangulation_ = new Triangulation(
sourceProj, targetProj, limitedTargetExtent, maxSourceExtent,
sourceResolution * errorThresholdInPixels);
sourceResolution * errorThresholdInPixels, targetResolution);
if (this.triangulation_.getTriangles().length === 0) {
// no valid triangles -> EMPTY

View File

@@ -1,7 +1,7 @@
/**
* @module ol/reproj/Triangulation
*/
import {boundingExtent, createEmpty, extendCoordinate, getBottomLeft, getBottomRight,
import {boundingExtent, createEmpty, extendCoordinate, getArea, getBottomLeft, getBottomRight,
getTopLeft, getTopRight, getWidth, intersects} from '../extent.js';
import {modulo} from '../math.js';
import {getTransform} from '../proj.js';
@@ -49,8 +49,9 @@ class Triangulation {
* @param {import("../extent.js").Extent} targetExtent Target extent to triangulate.
* @param {import("../extent.js").Extent} maxSourceExtent Maximal source extent that can be used.
* @param {number} errorThreshold Acceptable error (in source units).
* @param {number} destinationResolution The (optional) resolution of the destination.
*/
constructor(sourceProj, targetProj, targetExtent, maxSourceExtent, errorThreshold) {
constructor(sourceProj, targetProj, targetExtent, maxSourceExtent, errorThreshold, destinationResolution) {
/**
* @type {import("../proj/Projection.js").default}
@@ -138,11 +139,15 @@ class Triangulation {
const sourceBottomRight = this.transformInv_(destinationBottomRight);
const sourceBottomLeft = this.transformInv_(destinationBottomLeft);
const maxSubdivision = MAX_SUBDIVISION + (destinationResolution ?
Math.max(0, Math.ceil(Math.log2(getArea(targetExtent) / (destinationResolution * destinationResolution * 256 * 256))))
: 0);
this.addQuad_(
destinationTopLeft, destinationTopRight,
destinationBottomRight, destinationBottomLeft,
sourceTopLeft, sourceTopRight, sourceBottomRight, sourceBottomLeft,
MAX_SUBDIVISION);
maxSubdivision);
if (this.wrapsXInSource_) {
let leftBound = Infinity;