Skip to content

Commit

Permalink
feat(XbilParser): gestion nodata in elevation layer (elevation set to 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff authored and mgermerie committed Apr 14, 2023
1 parent 1985078 commit 20075b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
16 changes: 3 additions & 13 deletions src/Parser/XbilParser.js
Expand Up @@ -87,21 +87,11 @@ export function checkNodeElevationTextureValidity(data, noDataValue) {
data[l - Math.sqrt(l)] > noDataValue;
}

function getIndiceWithPitch(i, pitch, w) {
// Return corresponding indice in parent tile using pitch
const currentX = (i % w) / w; // normalized
const currentY = Math.floor(i / w) / w; // normalized
const newX = pitch.x + currentX * pitch.z;
const newY = pitch.y + currentY * pitch.w;
const newIndice = Math.floor(newY * w) * w + Math.floor(newX * w);
return newIndice;
}

// This function replaces noDataValue by significant values from parent texture
export function insertSignificantValuesFromParent(data, dataParent, noDataValue, pitch) {
// This function replaces noDataValue by significant values from parent texture (or 0)
export function insertSignificantValuesFromParent(data, dataParent = () => 0, noDataValue) {
for (let i = 0, l = data.length; i < l; ++i) {
if (data[i] === noDataValue) {
data[i] = dataParent[getIndiceWithPitch(i, pitch, 256)];
data[i] = dataParent(i);
}
}
}
22 changes: 18 additions & 4 deletions src/Renderer/RasterTile.js
Expand Up @@ -7,6 +7,15 @@ export const EMPTY_TEXTURE_ZOOM = -1;

const pitch = new THREE.Vector4();

function getIndiceWithPitch(i, pitch, w) {
// Return corresponding indice in parent tile using pitch
const currentX = (i % w) / w; // normalized
const currentY = Math.floor(i / w) / w; // normalized
const newX = pitch.x + currentX * pitch.z;
const newY = pitch.y + currentY * pitch.w;
const newIndice = Math.floor(newY * w) * w + Math.floor(newX * w);
return newIndice;
}

/**
* A `RasterTile` is part of raster [`Layer`]{@link Layer} data.
Expand Down Expand Up @@ -205,13 +214,18 @@ export class RasterElevationTile extends RasterTile {
if (nodatavalue == undefined) {
return;
}
// replace no datat value with parent texture value.
// replace no data value with parent texture value or 0 (if no significant value found).
const parentTexture = this.textures[0];
const parentDataElevation = parentTexture && parentTexture.image && parentTexture.image.data;
const dataElevation = texture.image && texture.image.data;
if (dataElevation && parentDataElevation && !checkNodeElevationTextureValidity(dataElevation, nodatavalue)) {
texture.extent.offsetToParent(parentTexture.extent, pitch);
insertSignificantValuesFromParent(dataElevation, parentDataElevation, nodatavalue, pitch);

if (dataElevation && !checkNodeElevationTextureValidity(dataElevation, nodatavalue)) {
insertSignificantValuesFromParent(dataElevation, parentDataElevation && dataParent(texture, parentTexture, parentDataElevation, pitch), nodatavalue);
}
}
}

function dataParent(texture, parentTexture, parentDataElevation, pitch) {
texture.extent.offsetToParent(parentTexture.extent, pitch);
return i => parentDataElevation[getIndiceWithPitch(i, pitch, 256)];
}

0 comments on commit 20075b8

Please sign in to comment.