From 0fd5d68eeb840ce2a8fcc883c4b458a7d11edf15 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Tue, 26 Sep 2023 12:19:02 +0200 Subject: [PATCH] Viridis color scheme --- src/Renderer/PointsMaterial.js | 51 ++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Renderer/PointsMaterial.js b/src/Renderer/PointsMaterial.js index 2b8613c9cf..effb4b8e81 100644 --- a/src/Renderer/PointsMaterial.js +++ b/src/Renderer/PointsMaterial.js @@ -28,6 +28,49 @@ export const PNTS_SIZE_MODE = { const white = new THREE.Color(1.0, 1.0, 1.0); +// Viridis color scheme +// Adapted from matplotlib +// https://github.com/matplotlib/matplotlib/blob/d60de5ed4d374d688463a1a49684f6cd1dbdd0d5/lib/matplotlib/_cm_listed.py#L774 +const viridis = [ + '#440154', '#440255', '#440357', '#450558', '#45065a', '#45085b', '#46095c', + '#460b5e', '#460c5f', '#460e61', '#470f62', '#471163', '#471265', '#471466', + '#471567', '#471669', '#47186a', '#48196b', '#481a6c', '#481c6e', '#481d6f', + '#481e70', '#482071', '#482172', '#482273', '#482374', '#472575', '#472676', + '#472777', '#472878', '#472a79', '#472b7a', '#472c7b', '#462d7c', '#462f7c', + '#46307d', '#46317e', '#45327f', '#45347f', '#453580', '#453681', '#443781', + '#443982', '#433a83', '#433b83', '#433c84', '#423d84', '#423e85', '#424085', + '#414186', '#414286', '#404387', '#404487', '#3f4587', '#3f4788', '#3e4888', + '#3e4989', '#3d4a89', '#3d4b89', '#3d4c89', '#3c4d8a', '#3c4e8a', '#3b508a', + '#3b518a', '#3a528b', '#3a538b', '#39548b', '#39558b', '#38568b', '#38578c', + '#37588c', '#37598c', '#365a8c', '#365b8c', '#355c8c', '#355d8c', '#345e8d', + '#345f8d', '#33608d', '#33618d', '#32628d', '#32638d', '#31648d', '#31658d', + '#31668d', '#30678d', '#30688d', '#2f698d', '#2f6a8d', '#2e6b8e', '#2e6c8e', + '#2e6d8e', '#2d6e8e', '#2d6f8e', '#2c708e', '#2c718e', '#2c728e', '#2b738e', + '#2b748e', '#2a758e', '#2a768e', '#2a778e', '#29788e', '#29798e', '#287a8e', + '#287a8e', '#287b8e', '#277c8e', '#277d8e', '#277e8e', '#267f8e', '#26808e', + '#26818e', '#25828e', '#25838d', '#24848d', '#24858d', '#24868d', '#23878d', + '#23888d', '#23898d', '#22898d', '#228a8d', '#228b8d', '#218c8d', '#218d8c', + '#218e8c', '#208f8c', '#20908c', '#20918c', '#1f928c', '#1f938b', '#1f948b', + '#1f958b', '#1f968b', '#1e978a', '#1e988a', '#1e998a', '#1e998a', '#1e9a89', + '#1e9b89', '#1e9c89', '#1e9d88', '#1e9e88', '#1e9f88', '#1ea087', '#1fa187', + '#1fa286', '#1fa386', '#20a485', '#20a585', '#21a685', '#21a784', '#22a784', + '#23a883', '#23a982', '#24aa82', '#25ab81', '#26ac81', '#27ad80', '#28ae7f', + '#29af7f', '#2ab07e', '#2bb17d', '#2cb17d', '#2eb27c', '#2fb37b', '#30b47a', + '#32b57a', '#33b679', '#35b778', '#36b877', '#38b976', '#39b976', '#3bba75', + '#3dbb74', '#3ebc73', '#40bd72', '#42be71', '#44be70', '#45bf6f', '#47c06e', + '#49c16d', '#4bc26c', '#4dc26b', '#4fc369', '#51c468', '#53c567', '#55c666', + '#57c665', '#59c764', '#5bc862', '#5ec961', '#60c960', '#62ca5f', '#64cb5d', + '#67cc5c', '#69cc5b', '#6bcd59', '#6dce58', '#70ce56', '#72cf55', '#74d054', + '#77d052', '#79d151', '#7cd24f', '#7ed24e', '#81d34c', '#83d34b', '#86d449', + '#88d547', '#8bd546', '#8dd644', '#90d643', '#92d741', '#95d73f', '#97d83e', + '#9ad83c', '#9dd93a', '#9fd938', '#a2da37', '#a5da35', '#a7db33', '#aadb32', + '#addc30', '#afdc2e', '#b2dd2c', '#b5dd2b', '#b7dd29', '#bade27', '#bdde26', + '#bfdf24', '#c2df22', '#c5df21', '#c7e01f', '#cae01e', '#cde01d', '#cfe11c', + '#d2e11b', '#d4e11a', '#d7e219', '#dae218', '#dce218', '#dfe318', '#e1e318', + '#e4e318', '#e7e419', '#e9e419', '#ece41a', '#eee51b', '#f1e51c', '#f3e51e', + '#f6e61f', '#f8e621', '#fae622', '#fde724', +]; + /** * Every lidar point can have a classification assigned to it that defines * the type of object that has reflected the laser pulse. Lidar points can be @@ -232,8 +275,12 @@ class PointsMaterial extends THREE.RawShaderMaterial { context.rect(0, 0, width, 1); const gradient = context.createLinearGradient(0, 0, width, 1); - gradient.addColorStop(0, '#000000'); - gradient.addColorStop(1, '#ffffff'); + const scheme = viridis; + const length = scheme.length; + for (let i = 0; i < length; ++i) { + gradient.addColorStop(i / length, scheme[i]); + } + context.fillStyle = gradient; context.fill();