Skip to content

Commit

Permalink
refactor(review): split recomputeDiscret() and recomputeClassif()
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Feb 8, 2024
1 parent 9ad59ef commit f0e2bb8
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions src/Renderer/PointsMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class PointsMaterial extends THREE.RawShaderMaterial {
* @param {THREE.Vector2} [options.elevationRange=new THREE.Vector2(0, 1000)] elevation range.
* @param {THREE.Vector2} [options.angleRange=new THREE.Vector2(-90, 90)] scan angle range.
* @param {boolean} [options.applyOpacityClassication=false] apply opacity classification on all display mode.
* @param {Classification} [options.classification] - define points classification.
* @param {Scheme} [options.classification] - define points classification color.
* @param {Scheme} [options.discretScheme] - define points value and a color.
* @param {number} [options.sizeMode=PNTS_SIZE_MODE.VALUE] point cloud size mode. Only 'VALUE' or 'ATTENUATED' are possible. VALUE use constant size, ATTENUATED compute size depending on distance from point to camera.
* @param {number} [options.minAttenuatedSize=3] minimum scale used by 'ATTENUATED' size mode
* @param {number} [options.maxAttenuatedSize=10] maximum scale used by 'ATTENUATED' size mode
Expand All @@ -146,7 +147,7 @@ class PointsMaterial extends THREE.RawShaderMaterial {
const angleRange = options.angleRange || new THREE.Vector2(-90, 90);
const oiMaterial = options.orientedImageMaterial;
const classifScheme = options.classification || ClassificationScheme.DEFAULT;
const otherScheme = options.other || DiscretScheme.DEFAULT;
const discretScheme = options.discretScheme || DiscretScheme.DEFAULT;
const applyOpacityClassication = options.applyOpacityClassication == undefined ? false : options.applyOpacityClassication;
const size = options.size || 0;
const mode = options.mode || PNTS_MODE.COLOR;
Expand All @@ -161,7 +162,7 @@ class PointsMaterial extends THREE.RawShaderMaterial {
delete options.angleRange;
delete options.orientedImageMaterial;
delete options.classifScheme;
delete options.otherScheme;
delete options.discretScheme;
delete options.applyOpacityClassication;
delete options.size;
delete options.mode;
Expand Down Expand Up @@ -213,10 +214,11 @@ class PointsMaterial extends THREE.RawShaderMaterial {

// Classification scheme
this.classifScheme = classifScheme;
this.otherScheme = otherScheme;
this.discretScheme = discretScheme;

// Update classification
// Update classification aand discrete Texture
this.recomputeClassification();
this.recomputeDiscreteTexture();

// Gradient
const gradientTexture = generateGradientTexture(Gradients[_gradient]);
Expand Down Expand Up @@ -283,43 +285,50 @@ class PointsMaterial extends THREE.RawShaderMaterial {
data[j + 3] = visible ? parseInt(255 * opacity, 10) : 0;
}

const other = this.otherScheme;
const nbClass = Object.keys(other).length;
const data2 = this.discretTexture.image.data;
const width2 = this.discretTexture.image.width;
this.classificationTexture.needsUpdate = true;
this.dispatchEvent({
type: 'material_property_changed',
target: this.uniforms,
});
}

recomputeDiscreteTexture() {
const data = this.discretTexture.image.data;
const width = this.discretTexture.image.width;

const discretScheme = this.discretScheme;
const nbClass = Object.keys(discretScheme).length;

for (let i = 0; i < width2; i++) {
for (let i = 0; i < width; i++) {
let color;
let opacity;
let visible = true;

if (other[i]) {
color = other[i].color;
visible = other[i].visible;
opacity = other[i].opacity;
} else if (other[i % nbClass]) {
color = other[i % nbClass].color;
visible = other[i % nbClass].visible;
opacity = other[i % nbClass].opacity;
} else if (other.DEFAULT) {
color = other.DEFAULT.color;
visible = other.DEFAULT.visible;
opacity = other.DEFAULT.opacity;
if (discretScheme[i]) {
color = discretScheme[i].color;
visible = discretScheme[i].visible;
opacity = discretScheme[i].opacity;
} else if (discretScheme[i % nbClass]) {
color = discretScheme[i % nbClass].color;
visible = discretScheme[i % nbClass].visible;
opacity = discretScheme[i % nbClass].opacity;
} else if (discretScheme.DEFAULT) {
color = discretScheme.DEFAULT.color;
visible = discretScheme.DEFAULT.visible;
opacity = discretScheme.DEFAULT.opacity;
} else {
color = white;
opacity = 1.0;
}

const j = 4 * i;
data2[j + 0] = parseInt(255 * color.r, 10);
data2[j + 1] = parseInt(255 * color.g, 10);
data2[j + 2] = parseInt(255 * color.b, 10);
data2[j + 3] = visible ? parseInt(255 * opacity, 10) : 0;
data[j + 0] = parseInt(255 * color.r, 10);
data[j + 1] = parseInt(255 * color.g, 10);
data[j + 2] = parseInt(255 * color.b, 10);
data[j + 3] = visible ? parseInt(255 * opacity, 10) : 0;
}

this.classificationTexture.needsUpdate = true;
this.discretTexture.needsUpdate = true;

this.dispatchEvent({
type: 'material_property_changed',
target: this.uniforms,
Expand Down

0 comments on commit f0e2bb8

Please sign in to comment.