This article is relevant for layers constructed with the TLspLIDARLayerBuilder only. See How to customize the styling of a point cloud if you are working with layers constructed with the TLsp3DTileLayerBuilder.

You can customize the styling of Lightspeed layers constructed with the TLspLIDARLayerBuilder by specifying a TLspPlotStyle on the builder.

The TLspPlotStyle uses the ILcdExpression API for efficient data-dependent customization of the point size, color, opacity, and visibility. See the Introduction to data-driven styling for more information about the ILcdExpression API.

In this example, we also make use of the TLspEyeDomeLightingSettings API in the plot style, to improve depth perception. Eye-dome lighting helps accentuate the shapes of objects by shading their outlines.

//In this example we use a LAS model
//but you can do the same for other point cloud formats which use the TLspLIDARLayerBuilder for visualization
ILcdModelDecoder modelDecoder =
    new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
ILcdModel model = modelDecoder.decode("Data/LAS/terrain_with_buildings.las");

//Retrieve the data type
//See the class javadoc of the TLcdLASModelDecoder for more info
TLcdLASModelDescriptor modelDescriptor = (TLcdLASModelDescriptor) model.getModelDescriptor();
TLcdDataType domainObjectType = modelDescriptor.getDataType();

//Retrieve the height property, and construct a color map based on the range of the height property
TLcdDataProperty heightProperty = domainObjectType.getProperty(TLcdLASModelDescriptor.HEIGHT);
ILcdInterval heightRange = modelDescriptor.getPropertyRange(heightProperty);

ILcdExpression<Float> heightAttribute = attribute(Float.class, heightProperty);
ILcdExpression<Float> fraction = fraction(heightAttribute, (float) heightRange.getMin(), (float) heightRange.getMax());
ILcdExpression<Color> heightColorExpression = mixmap(fraction, TLcdDTEDColorModelFactory.getDefaultColors());

// Create eye-dome lighting settings that will apply a red shade to the view to enhance depth perception
TLspEyeDomeLightingSettings eyeDomeLighting = TLspEyeDomeLightingSettings.newBuilder()
                                                                         .color(Color.RED)
                                                                         .build();

//Set the expression for the color on the TLspPlotStyle
TLspPlotStyle style = TLspPlotStyle.newBuilder()
                                   .modulationColor(heightColorExpression)
                                   .eyeDomeLighting(eyeDomeLighting)
                                   .build();

//Set the plot style on the layer
ILspLayer layer = TLspLIDARLayerBuilder.newBuilder()
                                       .model(model)
                                       .bodyStyles(TLspPaintState.REGULAR, style)
                                       .build();