Save point clouds to disk
Use the Point Cloud Message Saver component to subscribe to a topic and save messages of type PointCloud2Msg
as PCD or LAS files.
Add the Point Cloud Message Saver component
You can export point clouds generated by your sensors as PCD or LAS files by performing the following:
- Select any GameObject in your scene.
- Select Add Component in the Inspector, and choose Point Cloud Message Saver.
Set Topic to the topic the sensor is publishing to. The topic must be of type
PointCloud2Msg
.Enter Play mode.
Select Open next to Save Directory to open your file browser where the file has been saved.
Configure the save directory
Set the Save Directory to the path where you want to save the point cloud files to. You can use the browse button (denoted by ...) to use a file dialog to find the desired path.
If you leave the path empty, the path defaults to Application.dataPath.
Configure the saving behavior
The Point Cloud Message Saver uses the File Name pattern you specify, replacing %n
(if found) with a zero-padded four-digit index of the capture.
The extension of the point cloud file can be chosen by setting the File Type drop down to the desired type, which can be either PCD for .pcd file extension or LAS for .las file extension.
By default, any existing file with the same name is overwritten. Disable Overwrite to skip to the next available file index.
Save point clouds automatically
By default, Capture On Start is enabled, which instructs the Point Cloud Message Saver to start saving point clouds automatically when the simulation starts.
Set Number Of Captures to specify the number of files you want to save. Set it to 0 to save files until the simulation stops.
You might want to skip the first few files generated by your sensors, which can be done by setting Start Time to the simulation time when the export should start.
Distributed Rendering considerations
If you are using Distributed Rendering to improve performance, you can configure the Point Cloud Message Saver so that each Client saves point cloud files locally for the sensor it is rendering. Note that Distributed Rendering is currently only compatible with the Raster-based LiDAR.
- Add the Point Cloud Message Saver component to the same GameObject as the Distribution Affinity component used to specify on which render node the sensor runs.
- Consider changing the File Name property to include the group ID. For example, set File Name to
point_cloud_2_%n
if the Distribution Affinity group for the sensor is set to2
.
Limit the number of files saved
By default, all files are saved to disk, up to the number you specify in Number Of Captures. If the sensor update rate is high, this might generate too much disk activity and slow down the simulation.
To limit the number of files saved per second, set Time Between Captures to the minimum number of seconds that must elapse before saving the next file.
Save files interactively
The Runtime Controls appear in the Inspector when you enter Play mode in the Editor. You can use Start and Stop to control file export interactively.
You can use the Point Cloud Message Saver to save files from the Editor during Play mode:
- Disable Capture On Start.
- Set Start Time to
0
. - Enter Play mode.
- Use the visualization suite to determine when it's appropriate to save the point cloud file.
- Use Start in the Runtime Controls to save the file to the type you have set.
The Status indicates the current state of the Point Cloud Message Saver.
Status | Description |
---|---|
Ready | The export hasn't started yet. |
In progress | The Point Cloud Message Saver is waiting for more point cloud messages to save. |
Success | The files have been saved successfully. |
Stopped | You manually stopped the last file export before it had time to complete. |
Timed out | No message was received on the specified topic during the last file export. Ensure Topic corresponds to the sensor's output topic. |
Exception | An exception occurred during the last file export. Check the console or the logs for more details. |
Viewing saved files
Point cloud files can be difficult to interpret as is, so they can be visualized using external tools like this website for LAS files or this website for PCD files, or by writing custom scripts such as the following Python script for PCD files:
from open3d import *
def main():
cloud = io.read_point_cloud("PATH-TO-PCD-FILE.pcd") # Read point cloud
visualization.draw_geometries([cloud]) # Visualize point cloud
if __name__ == "__main__":
main()
Point Cloud Message Saver Inspector reference
Property | Description |
---|---|
Topic | The topic to save messages from. The topic's message type must be PointCloud2Msg . |
Number Of Captures | The number of files to save. Set to 0 to save files indefinitely. |
Start Time | The delay in seconds to wait before acquiring the first file. Set to 0 to capture the first received message. |
Time Between Captures | The minimum time in seconds to wait between messages, skipping intermediate messages if necessary. Set to 0 to never skip messages. Has no effect when exporting only 1 file. |
Save Directory | The path used to save files. If left empty, defaults to Application.dataPath. |
File Name | The file name pattern used for files. If found, %n is replaced by the file index. Can't be empty. |
File Type | The file extension to save to. The extension can be either .pcd or .las . |
Overwrite | Whether to overwrite destination files if they exist. If File Name doesn't contain %n , this option is ignored and the file is always overwritten. |
Capture On Start | Whether to automatically start the export when entering Play mode or when launching the executable. |
Log To Console | Whether to log information messages to the console. |