LiDAR 3D Point Cloud of Geospatial Data

Demonstrates how to visualize LiDAR UAV Data from the Defra survey using SciChart.js. A 1km x 1km slice of London is visualised as a 3D point-cloud with contour map overlaid. A heatmap legend on the right indicates the heightmap.

src/drawExample.ts
import {
    CameraController,
    EColorMapMode,
    EDrawMeshAs,
    EMeshPaletteMode,
    ETitlePosition,
    GradientColorPalette,
    HeatmapLegend,
    linearColorMapLerp,
    MouseWheelZoomModifier3D,
    NumericAxis3D,
    OrbitModifier3D,
    PixelPointMarker3D,
    ScatterRenderableSeries3D,
    SciChart3DSurface,
    SurfaceMeshRenderableSeries3D,
    TLinearColorMap,
    UniformGridDataSeries3D,
    Vector3,
    XyzDataSeries3D,
    zeroArray2D,
} from "scichart";
import { AscData, AscReader } from "./AscReader";
import { appTheme, createChartTheme } from "./appTheme";
import { fetchLidarData } from "./ExampleDataProvider";

type TMetadata = {
    vertexColor: number;
    pointScale: number;
};

export const drawExample = async (rootElement: string | HTMLDivElement) => {
    // Load data from the server
    const dataFromServer = await getDataFromServer();

    // Create a SciChart3DSurface
    const { wasmContext, sciChart3DSurface } = await SciChart3DSurface.create(rootElement, {
        theme: appTheme.SciChartJsTheme,
    });
    sciChart3DSurface.worldDimensions = new Vector3(1000, 200, 1000);

    // Create and attach a camera to the 3D Viewport
    sciChart3DSurface.camera = new CameraController(wasmContext, {
        position: new Vector3(800, 1000, 800),
        target: new Vector3(0, 50, 0),
    });

    // Add an X,Y,Z axis to the viewport
    sciChart3DSurface.xAxis = new NumericAxis3D(wasmContext, { axisTitle: "X Distance (Meters)" });
    sciChart3DSurface.yAxis = new NumericAxis3D(wasmContext, { axisTitle: "Height (Meters)" });
    sciChart3DSurface.zAxis = new NumericAxis3D(wasmContext, { axisTitle: "Z Distance (Meters)" });

    // Create a ScatterRenderableSeries3D and configure as a point cloud with 1px markers
    sciChart3DSurface.renderableSeries.add(
        new ScatterRenderableSeries3D(wasmContext, {
            pointMarker: new PixelPointMarker3D(wasmContext),
            dataSeries: new XyzDataSeries3D(wasmContext, {
                xValues: dataFromServer.ascData.XValues,
                yValues: dataFromServer.ascData.YValues,
                zValues: dataFromServer.ascData.ZValues,
                metadata: dataFromServer.meta,
            }),
            opacity: 1,
        })
    );

    // Also render the point-cloud data as a heightmap / topology map with contours
    sciChart3DSurface.renderableSeries.add(
        new SurfaceMeshRenderableSeries3D(wasmContext, {
            dataSeries: new UniformGridDataSeries3D(wasmContext, {
                xStart: 0,
                xStep: dataFromServer.ascData.CellSize,
                zStart: 0,
                zStep: dataFromServer.ascData.CellSize,
                yValues: dataFromServer.heightValues2D,
            }),
            minimum: 0,
            maximum: 50,
            drawSkirt: true,
            opacity: 0.7,
            meshColorPalette: new GradientColorPalette(wasmContext, {
                gradientStops: [
                    { offset: 1, color: appTheme.VividPink },
                    { offset: 0.9, color: appTheme.VividOrange },
                    { offset: 0.7, color: appTheme.MutedRed },
                    { offset: 0.5, color: appTheme.VividGreen },
                    { offset: 0.3, color: appTheme.VividSkyBlue },
                    { offset: 0.2, color: appTheme.Indigo },
                    { offset: 0, color: appTheme.DarkIndigo },
                ],
            }),
            contourStroke: appTheme.PaleSkyBlue,
            meshPaletteMode: EMeshPaletteMode.HEIGHT_MAP_INTERPOLATED,
            contourStrokeThickness: 2,
            drawMeshAs: EDrawMeshAs.SOLID_WITH_CONTOURS,
        })
    );

    // Add interactivity modifiers for orbiting and zooming with the mousewheel
    sciChart3DSurface.chartModifiers.add(new MouseWheelZoomModifier3D());
    sciChart3DSurface.chartModifiers.add(new OrbitModifier3D());

    return { sciChartSurface: sciChart3DSurface, wasmContext };
};

export const drawHeatmapLegend = async (rootElement: string | HTMLDivElement) => {
    const { heatmapLegend, wasmContext } = await HeatmapLegend.create(rootElement, {
        theme: createChartTheme({
            sciChartBackground: appTheme.DarkIndigo + "BB",
            loadingAnimationBackground: appTheme.DarkIndigo + "BB",
        }),
        yAxisOptions: {
            isInnerAxis: true,
            labelStyle: {
                fontSize: 12,
                color: appTheme.ForegroundColor,
            },
            axisBorder: {
                borderRight: 1,
                color: appTheme.ForegroundColor + "77",
            },
            majorTickLineStyle: {
                color: appTheme.ForegroundColor,
                tickSize: 6,
                strokeThickness: 1,
            },
            minorTickLineStyle: {
                color: appTheme.ForegroundColor,
                tickSize: 3,
                strokeThickness: 1,
            },
        },
        colorMap: {
            minimum: 0,
            maximum: 50,
            gradientStops: [
                { offset: 1, color: appTheme.VividPink },
                { offset: 0.9, color: appTheme.VividOrange },
                { offset: 0.7, color: appTheme.MutedRed },
                { offset: 0.5, color: appTheme.VividGreen },
                { offset: 0.3, color: appTheme.VividSkyBlue },
                { offset: 0.2, color: appTheme.Indigo },
                { offset: 0, color: appTheme.DarkIndigo },
            ],
        },
    });

    heatmapLegend.innerSciChartSurface.sciChartSurface.title = "Height (m)";

    heatmapLegend.innerSciChartSurface.sciChartSurface.titleStyle = {
        fontSize: 12,
        color: appTheme.ForegroundColor,
        position: ETitlePosition.Bottom,
    };

    return { sciChartSurface: heatmapLegend.innerSciChartSurface.sciChartSurface };
};

async function getDataFromServer() {
    // The LinearColorMap type in SciChart allows you to generate a colour map based on a
    // minimum and maximum value, e.g. min=0, max=50 means the gradient brush below is mapped into that range
    //
    const colorMap: TLinearColorMap = {
        Minimum: 0,
        Maximum: 50,
        Mode: EColorMapMode.Interpolated,
        GradientStops: [
            { color: appTheme.DarkIndigo, offset: 0 },
            { color: appTheme.Indigo, offset: 0.2 },
            { color: appTheme.VividSkyBlue, offset: 0.3 },
            { color: appTheme.VividGreen, offset: 0.5 },
            { color: appTheme.MutedRed, offset: 0.7 },
            { color: appTheme.VividOrange, offset: 0.9 },
            { color: appTheme.VividPink, offset: 0 },
        ],
    };

    // Read the ASC Lidar data file with optional color map data
    const reader: AscReader = new AscReader((height) => {
        // Linearly interpolate each heightValue into a colour and return to the ASCReader
        // This will be injected into the SciChart XyzDataSeries3D to colour points in the point-cloud
        return linearColorMapLerp(colorMap, height);
    });

    // See our source-code file tq3080_DSM_2M.js for format on this ASC Point cloud data
    // find the source online at github: https://github.com/ABTSoftware/SciChart.JS.Examples/blob/master/Examples/src/server/Data/t
    const rawData = await fetchLidarData();
    const ascData: AscData = reader.parse(await rawData.text());

    // Prepare metadata to contain the color values from ASCData
    const meta: TMetadata[] = ascData.ColorValues.map((c) => ({
        vertexColor: c,
        pointScale: 0,
    }));

    // Prepare heightValues2D for the uniform surface mesh (transform point cloud to 2d array of heights)
    const heightValues2D = zeroArray2D([ascData.NumberRows, ascData.NumberColumns]);
    for (let index = 0, z = 0; z < ascData.NumberRows; z++) {
        for (let x = 0; x < ascData.NumberColumns; x++) {
            heightValues2D[z][x] = ascData.YValues[index++];
        }
    }

    return {
        ascData,
        meta,
        heightValues2D,
    };
}

LiDAR 3D Point Cloud Demo (JavaScript)

Overview

This example demonstrates a sophisticated 3D LiDAR point cloud visualization using SciChart.js in a JavaScript environment. It renders both a scatter 3D point-cloud and a corresponding 3D topological (heightmap) mesh with an integrated heatmap legend, providing a comprehensive view of geospatial data in real time.

Technical Implementation

The implementation starts with asynchronous data loading via async/await. The LiDAR data, stored in the ASC file format, is parsed by a custom helper class (AscReader) that converts the textual data into numerical arrays suitable for charting. This processing includes generating X, Y, and Z coordinate arrays and applying an optional linear color mapping function (using linearColorMapLerp) to map height values to colors. The parsed data is then fed into two primary series: a ScatterRenderableSeries3D and a SurfaceMeshRenderableSeries3D. The scatter series uses a pixel point marker to depict individual points in the point cloud with color information embedded via metadata. Meanwhile, the surface mesh uses a UniformGridDataSeries3D to transform the point cloud into a 2D height map for contour visualization. Configuration of the 3D scene is handled by setting world dimensions using a Vector3 instance (e.g. new Vector3(1000, 200, 1000)) and attaching a CameraController for interactive camera manipulation. Developers can refer to the SciChartSurface Camera documentation for further details on 3D scene configuration.

Features and Capabilities

Key features include:

  • Real-time Data Streaming and Asynchronous Loading: The use of async/await ensures that large datasets are loaded without blocking UI updates.

  • 3D Point Cloud Rendering: A scatter renderable series is used to display individual LiDAR points, leveraging the Scatter 3D Chart Type for high-performance WebGL rendering.

  • Topological Mesh and Heightmap Generation: The UniformGridDataSeries3D forms the basis of a surface mesh renderable series, with gradient color palettes provided by a GradientColorPalette. This is particularly useful for visualizing terrain and contours as described in the SurfaceMesh 3D Chart Type documentation.

  • Heatmap Legend Integration: A dedicated heatmap legend is created and synchronized with the mesh renderable series. For more detailed usage, please consult the HeatmapLegend documentation.

  • Interactive 3D Controls: The example enhances user interactivity with 3D modifiers such as MouseWheelZoomModifier3D and OrbitModifier3D, enabling intuitive zooming and panning. This mirrors best practices for 3D camera control in SciChart.js.

Integration and Best Practices

By using JavaScript for instantiation and configuration, this example avoids framework-specific abstractions, ensuring that developers get direct access to all lower-level SciChart.js APIs. Performance optimizations are a priority; the example follows recommendations from the Performance Tips & Tricks documentation to efficiently render large point clouds. Additionally, data transformation techniques, such as converting one-dimensional arrays into 2D height maps (using functions like zeroArray2D), are implemented to ensure smooth integration between raw LiDAR data and visual rendering.

Overall, this demo provides a robust reference for creating interactive, high-performance 3D LiDAR visualizations using SciChart.js in JavaScript, offering insights into asynchronous data handling, advanced color mapping, and detailed 3D scene configuration.