Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / LiDAR Point Cloud Playback
deck.gl · Business scenario

LiDAR Point Cloud Playback

200,000 street-scene points pre-generated as 8 frames; the cloud sways slightly about its own axis, and playback shows fore-and-aft motion from the vehicle viewpoint.

Open standalone → Chinese notes All business examples
/demos/deckgl-nongis-lidar-replay.htmlLIVE
single HTML file · CDN dependencies onlyinterface labels are in Chinese

Business context

Autonomous driving perception and calibration teams use point cloud playback to check single-frame geometry, verify coordinate transforms and time synchronisation, and to slice scenes for labelling. Data comes from roof or side LiDAR at 100,000 to 200,000 points per frame with x, y, z and intensity. An hour of recording yields hundreds of frames and several GB; playback usually keeps keyframes and downsamples them, and this example pre-generates 8 frames of 200,000 points.

Coordinates are unified first: each LiDAR frame is centred on the vehicle, and frames differ in rotation and translation, so METER_OFFSETS with a single lng/lat origin cannot express them. CARTESIAN local metric coordinates go to OrbitView, where z is height directly. Frames are stored as flat Float32Array, and a frame change copies new coordinates into a reused position array, with updateTriggers re-uploading only the position attribute instead of rebuilding 200,000 objects.

Density is often read as reflectivity or material: point colour is banded by height, so a colour difference does not describe a surface property, and the same wall changes colour between frames. Frame-to-frame sway is small, so apparent object motion may be vehicle pose change rather than a moving target. Downsampling drops thin poles and weak distant returns, so judging missed detections from the thinned cloud understates the difficulty.

How it works

A single frame of 200,000 points has three parts: 60,000 ground points across x ±3.6, y ±1.6 and z 0–0.02; 90,000 facade points split along y = ±1.62 with z 0–2.2; and 50,000 points on the chassis, roof, sides and ends of two cars measuring 0.95 × 0.44 × 0.52. Eight frames are pre-generated, with yaw (f−3.5) × 0.012 rad, about ±2.4 degrees, forward displacement (f−3.5) × 0.03 units, and a z undulation of sin(f·0.8 + x·1.7) × 0.006; each frame is stored as 3 × 200,000 floats, about 2.4 MB. PointCloudLayer uses CARTESIAN coordinates, colours by z across four bands from deep blue to pale yellow, and draws at pointSize 1.5 px.

A frame change writes the target frame's 600,000 coordinates back into the reused point object and creates no new array; the layer id stays lidar-frame and updateTriggers is keyed on the frame index, so deck.gl re-uploads the position attribute without rebuilding the layer. METER_OFFSETS is not used: the sensor centres every frame on the vehicle, frames differ in rotation and translation, and coordinateOrigin accepts only one fixed lng/lat origin, which cannot express per-frame pose; attaching to a map would also require handling Web Mercator's compression of z and ground occlusion. CARTESIAN with OrbitView hands metric local coordinates to the camera directly, with z as height.

ConfigurationWhat it does
coordinateSystem: CARTESIANLocal metric coordinates where z is height directly
8 frames × 200,000 points Float32ArrayAbout 19 MB of stored coordinates; a frame change copies coordinates only
updateTriggers: { getPosition: frame }Re-uploads only the position attribute when the frame index changes
pointSize: 1.5 / sizeUnits: 'pixels'Fixed point size that does not blur into a single mass when zoomed out

Note. Store frame coordinates in a flat Float32Array and keep only indices or a reused position array in the object list, so a frame change costs one memory copy instead of 200,000 allocations.

Source

demos/deckgl-nongis-lidar-replay.html
<!--
  示例:激光点云回放
  要点:20 万点街景预生成 8 帧,OrbitView + CARTESIAN 逐帧回放并保持图层 id 与对象复用
  依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>激光点云回放</title>
<style>
  html,body{height:100%;margin:0;background:#0d1117}
  body{display:flex;flex-direction:column;overflow:hidden;
       font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
  .bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
       display:flex;gap:12px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
  .bar b{color:#58a6ff;font-weight:600}
  .bar label{display:flex;align-items:center;gap:5px;cursor:pointer}
  .bar input[type=checkbox]{accent-color:#4f9ef8}
  .bar input[type=range]{width:140px;accent-color:#4f9ef8}
  .bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:5px;cursor:pointer;
              border:1px solid #303845;background:#1d2531;color:#c8d2e0}
  .bar button:hover{background:#253040}
  .bar button.on{background:#2c4a7a;border-color:#4f8ad6;color:#dfe9ff}
  .bar .sep{width:1px;height:18px;background:#2a313c;margin:0 4px}
  #cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
  <span>帧 <b id="f">1</b> / 8</span>
  <span>点数 <b id="n">—</b></span>
  <span class="sep"></span>
  <button id="prev">上一帧</button>
  <button id="next">下一帧</button>
  <label><input type="checkbox" id="play"> 自动播放</label>
</div>
<canvas id="cv"></canvas>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
  'use strict';

  if (typeof deck === 'undefined') {
    document.body.innerHTML =
      '<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
    return;
  }

  function rng(seed) {
    var a = seed >>> 0;
    return function () {
      a = (a + 0x6D2B79F5) >>> 0;
      var t = Math.imul(a ^ (a >>> 15), 1 | a);
      t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
      return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
    };
  }

  var rand = rng(6612);
  var N = 200000;
  var base = new Float32Array(N * 3);
  var idx = 0;

  function put(x, y, z) {
    base[idx * 3] = x;
    base[idx * 3 + 1] = y;
    base[idx * 3 + 2] = z;
    idx++;
  }

  var i;
  for (i = 0; i < 60000; i++) {
    var gx = -3.6 + rand() * 7.2;
    var gy = -1.6 + rand() * 3.2;
    if (i % 3 === 0) gx = Math.round(gx * 4) / 4;
    else if (i % 3 === 1) gy = Math.round(gy * 4) / 4;
    put(gx, gy, rand() * 0.02);
  }
  for (i = 0; i < 90000; i++) {
    var side = i % 2 === 0 ? -1 : 1;
    put(-3.6 + rand() * 7.2, side * (1.62 + (rand() - 0.5) * 0.05), rand() * 2.2);
  }
  for (i = 0; i < 50000; i++) {
    var car = i % 2;
    var ccx = car === 0 ? -1.1 : 1.35;
    var ccy = car === 0 ? 0.55 : -0.5;
    var u = rand();
    var v = rand();
    var face = i % 5;
    var lx = 0.95, ly = 0.44, lz = 0.52;
    var px, py, pz;
    if (face === 0) {
      px = (u - 0.5) * lx; py = (v - 0.5) * ly; pz = 0.04;
    } else if (face === 1) {
      px = (u - 0.5) * lx; py = (v - 0.5) * ly; pz = lz;
    } else if (face === 2) {
      px = (u - 0.5) * lx; py = ly / 2; pz = 0.04 + v * (lz - 0.04);
    } else if (face === 3) {
      px = (u - 0.5) * lx; py = -ly / 2; pz = 0.04 + v * (lz - 0.04);
    } else {
      px = lx / 2; py = (v - 0.5) * ly; pz = 0.04 + u * (lz - 0.04);
    }
    put(ccx + px, ccy + py, pz);
  }

  var RAMP = [[32, 68, 142], [58, 148, 206], [122, 214, 174], [244, 214, 108]];

  function heightColor(z) {
    var t = z / 2.2;
    t = t < 0 ? 0 : (t > 1 ? 1 : t);
    var k = t * 3;
    var i0 = Math.floor(k);
    if (i0 > 2) i0 = 2;
    var f = k - i0;
    var c0 = RAMP[i0];
    var c1 = RAMP[i0 + 1];
    return [
      Math.round(c0[0] + (c1[0] - c0[0]) * f),
      Math.round(c0[1] + (c1[1] - c0[1]) * f),
      Math.round(c0[2] + (c1[2] - c0[2]) * f),
      228
    ];
  }

  var pts = [];
  for (i = 0; i < N; i++) {
    var z0 = base[i * 3 + 2];
    pts.push({
      p: [base[i * 3], base[i * 3 + 1], z0],
      c: heightColor(z0)
    });
  }

  // 8 帧预生成:绕 z 轴 ±0.042 rad 摆动,前后 ±0.105 单位,z 向 6 mm 起伏
  var frames = [];
  for (var f = 0; f < 8; f++) {
    var yaw = (f - 3.5) * 0.012;
    var cs = Math.cos(yaw);
    var sn = Math.sin(yaw);
    var dx = (f - 3.5) * 0.03;
    var arr = new Float32Array(N * 3);
    for (i = 0; i < N * 3; i += 3) {
      var x = base[i];
      var y = base[i + 1];
      arr[i] = x * cs - y * sn + dx;
      arr[i + 1] = x * sn + y * cs;
      arr[i + 2] = base[i + 2] + Math.sin(f * 0.8 + x * 1.7) * 0.006;
    }
    frames.push(arr);
  }

  document.getElementById('n').textContent = N.toLocaleString();

  var frame = 0, playing = false, lastAdv = 0;

  function buildLayer() {
    return new deck.PointCloudLayer({
      id: 'lidar-frame',
      data: pts,
      coordinateSystem: deck.COORDINATE_SYSTEM.CARTESIAN,
      getPosition: function (d) { return d.p; },
      getColor: function (d) { return d.c; },
      pointSize: 1.5,
      sizeUnits: 'pixels',
      updateTriggers: { getPosition: frame }
    });
  }

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    views: new deck.OrbitView({ target: [0, 0, 1.0] }),
    initialViewState: { target: [0, 0, 1.0], rotationX: 30, rotationOrbit: -32, zoom: 0.25 },
    controller: true,
    layers: [buildLayer()]
  });

  function setFrame(f) {
    frame = f;
    var arr = frames[f];
    for (var k = 0; k < N; k++) {
      var p = pts[k].p;
      p[0] = arr[k * 3];
      p[1] = arr[k * 3 + 1];
      p[2] = arr[k * 3 + 2];
    }
    document.getElementById('f').textContent = f + 1;
    deckgl.setProps({ layers: [buildLayer()] });
  }

  document.getElementById('prev').addEventListener('click', function () {
    setFrame((frame + 7) % 8);
  });
  document.getElementById('next').addEventListener('click', function () {
    setFrame((frame + 1) % 8);
  });
  document.getElementById('play').addEventListener('change', function (e) {
    playing = e.target.checked;
    lastAdv = performance.now();
  });

  function tick(now) {
    if (playing && now - lastAdv > 900) {
      lastAdv = now;
      setFrame((frame + 1) % 8);
    }
    requestAnimationFrame(tick);
  }
  requestAnimationFrame(tick);

  window.__deck = deckgl;
})();
</script>
</body>
</html>
Language: this page is in English; the demo keeps Chinese interface labels and code comments. The Chinese page carries the full notes and the same runnable file.

More business examples

deck.gl · APIPointCloudLayer deck.gl · APIOrbitView deck.gl · APICOORDINATE_SYSTEM