DriveWorks SDK Reference
5.8.83 Release
For Test and Development only

Point Cloud Assembler

This tutorial demonstrates how to accumulate dwLidarDecodedPacketEx to a lidar spin point cloud.

Create point cloud assembler module:

// Enable GPU accumulation
params.enableCuda = true;
// Set number of point cloud layers to 3, one per lidar return
params.mapping.numLayers = 3;
params.mapping.layerType[0] = DW_LIDAR_RETURN_TYPE_STRONGEST;
params.mapping.layerType[1] = DW_LIDAR_RETURN_TYPE_FIRST;
params.mapping.layerType[2] = DW_LIDAR_RETURN_TYPE_LAST;
// Set auxiliary channels mapping, one channel per aux data array
params.mapping.numAuxChannels = 3;
params.mapping.auxType[0] = DW_LIDAR_AUX_DATA_TYPE_TIME;
params.mapping.auxType[1] = DW_LIDAR_AUX_DATA_TYPE_LINEID;
params.mapping.auxType[2] = DW_LIDAR_AUX_DATA_TYPE_NOISELEVEL;
// Get properties of a lidar sensor
dwLidarProperties lidarProps{};
dwSensorLidar_getProperties(&lidarProps, sensor);
dwPointCloudAssembler_initialize(&assembler, &params, &lidarProps, context);
DW_API_PUBLIC dwStatus dwSensorLidar_getProperties(dwLidarProperties *const lidarProperties, dwSensorHandle_t const sensor)
Gets information about the Lidar sensor.
@ DW_LIDAR_AUX_DATA_TYPE_LINEID
Definition: Lidar.h:98
@ DW_LIDAR_AUX_DATA_TYPE_TIME
Definition: Lidar.h:91
@ DW_LIDAR_AUX_DATA_TYPE_NOISELEVEL
Definition: Lidar.h:95
@ DW_LIDAR_RETURN_TYPE_FIRST
Definition: Lidar.h:69
@ DW_LIDAR_RETURN_TYPE_STRONGEST
Definition: Lidar.h:71
@ DW_LIDAR_RETURN_TYPE_LAST
Definition: Lidar.h:70
Defines the properties of the lidar.
Definition: Lidar.h:152
bool enableCuda
If set to true, assembling to GPU memory.
DW_API_PUBLIC dwStatus dwPointCloudAssembler_initialize(dwPointCloudAssemblerHandle_t *const obj, dwPointCloudAssemblerParams const *const params, dwLidarProperties const *const lidarProperties, dwContextHandle_t const ctx)
Initialize point cloud assembler module.
struct dwPointCloudAssemblerObject * dwPointCloudAssemblerHandle_t
Initialization parameters.

Create output point cloud and bind it to assembler.

// Get number of available lidar returns
uint32_t const numAvailableReturns = lidarProps.availableReturns != DW_LIDAR_RETURN_TYPE_ANY ? static_cast<uint32_t>(std::bitset<32U>(lidarProps.availableReturns).count()) : 1U;
// Get number of points in single return
uint32_t const pointsPerLayer = lidarProps.pointsPerSpin / numAvailableReturns;
// Array containing aux channel element sizes
uint32_t const auxChannelElementSizes[] = {
sizeof(dwTime_t), // time element size
sizeof(uint16_t), // lineId element size
sizeof(float32_t) // noise level element size
};
// Create point cloud
dwPointCloud outputPointCloud{};
dwPointCloud_create(&outputPointCloud, // output point cloud
DW_POINTCLOUD_FORMAT_XYZI, // format of a point, xyzi of rthi
DW_MEMORY_TYPE_CUDA, // memory type, CUDA or CPU
pointsPerLayer, // maximum number of points in single lidar return
3U, // number of requested returns
auxChannelElementSizes, // size of aux channel elements
3U); // number of auxiliary channels
// Bind created point cloud
dwPointCloudAssembler_bindOutput(&outputPointCloud, assembler);
// Set CUDA stream
float float32_t
Specifies POD types.
Definition: Types.h:70
int64_t dwTime_t
Specifies a timestamp unit, in microseconds.
Definition: Types.h:82
@ DW_MEMORY_TYPE_CUDA
CUDA memory.
Definition: Types.h:191
@ DW_LIDAR_RETURN_TYPE_ANY
Definition: Lidar.h:67
DW_API_PUBLIC dwStatus dwPointCloud_create(dwPointCloud *pointCloud, dwPointCloudFormat const format, dwMemoryType const memoryType, uint32_t const maxPointsPerLayer, uint32_t const numRequestedLayers, uint32_t const *auxChannelsElemSize, uint32_t const numRequestedAuxChannels)
Create point cloud with layers and aux channel information.
DW_API_PUBLIC dwStatus dwPointCloudAssembler_setCUDAStream(cudaStream_t const stream, dwPointCloudAssemblerHandle_t const obj)
Set CUDA stream of point cloud assembler.
DW_API_PUBLIC dwStatus dwPointCloudAssembler_bindOutput(dwPointCloud *const pointCloud, dwPointCloudAssemblerHandle_t const obj)
Bind output point cloud.
@ DW_POINTCLOUD_FORMAT_XYZI
Cartesian 3D coordinate + intensity.
Definition: PointCloud.h:61
Defines point cloud data structure.
Definition: PointCloud.h:99

To continuously collect the decoded lidar packet until it reaches the scanComplete flag:

bool hasFullSpinReady = false;
dwPointCloudAssembler_isReady(&hasFullSpinReady, assembler);
while (!hasFullSpinReady)
{
// get decoded lidar packet
dwSensorLidar_readPacektEx(&lidarPacket, sensor);
// add packet to assembler
dwPointCloudAssembler_addLidarPacket(lidarPacket, assembler);
// update complete flag
dwPointCloudAssembler_isReady(&hasFullSpinReady, assembler);
}
// Assemble the data
// use `outputPointCloud` for other tasks
......
DW_API_PUBLIC dwStatus dwPointCloudAssembler_addLidarPacket(dwLidarDecodedPacket const *const packet, dwPointCloudAssemblerHandle_t const obj)
Push lidar packet to point cloud assembler.
DW_API_PUBLIC dwStatus dwPointCloudAssembler_process(dwPointCloudAssemblerHandle_t const obj)
Perform processing of accumulated data.
DW_API_PUBLIC dwStatus dwPointCloudAssembler_isReady(bool *const isReady, dwPointCloudAssemblerConstHandle_t const obj)
Indicate that lidar frame has been accumulated.

Release the module:

dwPointCloud_destroy(&outputPointCloud);
DW_API_PUBLIC dwStatus dwPointCloud_destroy(dwPointCloud *pointCloud)
Destroy point cloud buffers.
DW_API_PUBLIC dwStatus dwPointCloudAssembler_release(dwPointCloudAssemblerHandle_t const obj)
Release point cloud assembler.