Skip to content

Commit fa74f28

Browse files
committed
feat(PointCloud): filtering points based on classification
1 parent 641ed6d commit fa74f28

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

src/Renderer/PointsMaterial.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,15 @@ function recomputeTexture(scheme, texture, nbClass) {
123123
for (let i = 0; i < width; i++) {
124124
let color;
125125
let opacity;
126-
let visible = true;
127126

128127
if (scheme[i]) {
129128
color = scheme[i].color;
130-
visible = scheme[i].visible;
131129
opacity = scheme[i].opacity;
132130
} else if (scheme[i % nbClass]) {
133131
color = scheme[i % nbClass].color;
134-
visible = scheme[i % nbClass].visible;
135132
opacity = scheme[i % nbClass].opacity;
136133
} else if (scheme.DEFAULT) {
137134
color = scheme.DEFAULT.color;
138-
visible = scheme.DEFAULT.visible;
139135
opacity = scheme.DEFAULT.opacity;
140136
} else {
141137
color = white;
@@ -146,9 +142,9 @@ function recomputeTexture(scheme, texture, nbClass) {
146142
data[j + 0] = parseInt(255 * color.r, 10);
147143
data[j + 1] = parseInt(255 * color.g, 10);
148144
data[j + 2] = parseInt(255 * color.b, 10);
149-
data[j + 3] = visible ? parseInt(255 * opacity, 10) : 0;
145+
data[j + 3] = parseInt(255 * opacity, 10);
150146

151-
needTransparency = needTransparency || opacity < 1 || !visible;
147+
needTransparency = needTransparency || opacity < 1;
152148
}
153149
texture.needsUpdate = true;
154150
return needTransparency;
@@ -258,13 +254,22 @@ class PointsMaterial extends THREE.ShaderMaterial {
258254
textureLUT.magFilter = THREE.NearestFilter;
259255
CommonMaterial.setUniformProperty(this, 'discreteTexture', textureLUT);
260256

257+
// add texture to apply visibility.
258+
const dataVisi = new Uint8Array(256 * 1);
259+
const textureVisi = new THREE.DataTexture(dataVisi, 256, 1, THREE.RedFormat);
260+
261+
textureVisi.needsUpdate = true;
262+
textureVisi.magFilter = THREE.NearestFilter;
263+
CommonMaterial.setUniformProperty(this, 'visiTexture', textureVisi);
264+
261265
// Classification and other discrete values scheme
262266
this.classificationScheme = classificationScheme;
263267
this.discreteScheme = discreteScheme;
264268

265269
// Update classification and discrete Texture
266270
this.recomputeClassification();
267271
this.recomputeDiscreteTexture();
272+
this.recomputeVisibleTexture();
268273

269274
// Gradient texture for continuous values
270275
this.gradient = gradient;
@@ -386,6 +391,35 @@ class PointsMaterial extends THREE.ShaderMaterial {
386391
});
387392
}
388393

394+
recomputeVisibleTexture() {
395+
const texture = this.visiTexture;
396+
const scheme = this.classificationScheme;
397+
398+
const data = texture.image.data;
399+
const width = texture.image.width;
400+
401+
for (let i = 0; i < width; i++) {
402+
let visible;
403+
404+
if (scheme[i]) {
405+
visible = scheme[i].visible;
406+
} else if (scheme.DEFAULT) {
407+
visible = scheme.DEFAULT.visible;
408+
} else {
409+
visible = true;
410+
}
411+
412+
data[i] = visible ? 255 : 0;
413+
}
414+
texture.needsUpdate = true;
415+
416+
417+
this.dispatchEvent({
418+
type: 'material_property_changed',
419+
target: this.uniforms,
420+
});
421+
}
422+
389423
enablePicking(picking) {
390424
this.picking = picking;
391425
this.blending = picking ? THREE.NoBlending : THREE.NormalBlending;

src/Renderer/Shader/PointsFS.glsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <logdepthbuf_pars_fragment>
99
#include <clipping_planes_pars_fragment>
1010

11+
varying float visible;
12+
1113
uniform vec3 diffuse;
1214
uniform float opacity;
1315

@@ -18,6 +20,9 @@ void main() {
1820

1921
// Early discard (clipping planes and shape)
2022
#include <clipping_planes_pars_fragment>
23+
if (visible < 0.5) {
24+
discard;
25+
}
2126
if (shape == PNTS_SHAPE_CIRCLE) {
2227
//circular rendering in glsl
2328
if ((length(gl_PointCoord - 0.5) > 0.5)) {

src/Renderer/Shader/PointsVS.glsl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
#include <logdepthbuf_pars_vertex>
55
#include <clipping_planes_pars_vertex>
66
varying vec4 vColor; // color_pars_vertex
7+
varying float visible;
78

89
#ifdef USE_POINTS_UV
910
varying vec2 vUv;
1011
uniform mat3 uvTransform;
1112
#endif
1213

13-
#define NB_CLASS 8.
14+
#define SOURCE_ID_GROUP 8.
1415

1516
uniform float size;
1617
uniform float scale;
@@ -25,6 +26,8 @@ uniform vec2 angleRange;
2526
uniform sampler2D classificationTexture;
2627
uniform sampler2D discreteTexture;
2728
uniform sampler2D gradientTexture;
29+
uniform sampler2D visiTexture;
30+
2831
uniform int sizeMode;
2932
uniform float minAttenuatedSize;
3033
uniform float maxAttenuatedSize;
@@ -39,12 +42,14 @@ attribute float numberOfReturns;
3942
attribute float scanAngle;
4043

4144
void main() {
45+
vec2 uv = vec2(classification/255., 0.5);
46+
visible = texture2D(visiTexture, uv).r;
47+
4248
vColor = vec4(1.0);
4349
if (picking) {
4450
vColor = unique_id;
4551
} else {
4652
if (mode == PNTS_MODE_CLASSIFICATION) {
47-
vec2 uv = vec2(classification/255., 0.5);
4853
vColor = texture2D(classificationTexture, uv);
4954
} else if (mode == PNTS_MODE_NORMAL) {
5055
vColor.rgb = abs(normal);
@@ -84,7 +89,7 @@ void main() {
8489
vec2 uv = vec2(numberOfReturns/255., 0.5);
8590
vColor = texture2D(discreteTexture, uv);
8691
} else if (mode == PNTS_MODE_POINT_SOURCE_ID) {
87-
vec2 uv = vec2(mod(pointSourceID, NB_CLASS)/255., 0.5);
92+
vec2 uv = vec2(mod(pointSourceID, SOURCE_ID_GROUP)/255., 0.5);
8893
vColor = texture2D(discreteTexture, uv);
8994
} else if (mode == PNTS_MODE_SCAN_ANGLE) {
9095
float i = (scanAngle - angleRange.x) / (angleRange.y - angleRange.x);

utils/debug/PointCloudDebug.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ export default {
8080
layer.material.mode = PNTS_MODE[value];
8181
update();
8282
});
83+
84+
const classeUI = styleUI.addFolder('Classe Visibility').close();
85+
Object.entries(layer.material.classificationScheme).forEach((classe) => {
86+
classeUI.add(classe[1], 'visible').name(classe[1].name)
87+
.onChange(() => {
88+
layer.material.recomputeVisibleTexture();
89+
update();
90+
});
91+
});
92+
8393
const gradiantsNames = Object.keys(layer.material.gradients);
8494
styleUI.add({ gradient: gradiantsNames[0] }, 'gradient', gradiantsNames).name('gradient')
8595
.onChange((value) => {

0 commit comments

Comments
 (0)