MATLAB Examples

Contents

Introduction

There are two methods available to visualize point clouds. The first method plots a point cloud directly from showPointCloud and the second shows how to plot a point cloud using scatter3 and the set command.

Method 1: Running showPointCloud takes more time to plot than set, but is more direct. Better for one time point cloud visualizations.

Method 2: Initializing a scatter3 handle and then running the set command results in quicker plotting. Better for point cloud visualizations that repeat i.e. a loop.

close all

load pointCloudFrame;
load colorMapFrame;

Method 1: Visualization of point cloud using showPointCloud

Optimal for one-time visualizations of a point cloud due to ease of syntax. Does not run as quickly as scatter3 and set as shown in Method 2.

figure;

% plot the Point Cloud using a 3D Scatter Plot
tic
showPointCloud(pointCloudFrame,colorMapFrame);
t1 = toc;
fprintf('Time taken to execute showPointCloud is: %g\n',t1)

% set figure properties
title('Point Cloud Visualization using showPointCloud')
xlabel('x axis');
ylabel('y axis');
zlabel('z axis');
% set axis properties
axis([0 4000 -4000 4000 -4000 4000]);
view([-79.5000   50.0000]);
grid on;
Time taken to execute showPointCloud is: 0.141607

Method 2: Visualization of a point cloud using scatter3 and set

Optimal for fast streaming visualization of a point cloud

figure;

% initialize a 3D Scatter plot
h3ds = scatter3(0,0,0,'Marker','.');

% set figure properties
title('Point Cloud Visualization using scatter3');
xlabel('X Axis');
ylabel('Y Axis');
zlabel('Z Axis');
% set axis properties
axis([0 4000 -4000 4000 -4000 4000]);
view([-79.5000   50.0000]);
grid on;

ti = 0;
dt = 1;
tf = 1;
for tidx = ti:dt:tf
    % plot the 3D Point Cloud
    tic
    set(h3ds,'XData',pointCloudFrame(:,1),'YData',pointCloudFrame(:,2),'ZData',pointCloudFrame(:,3),...
               'CData',colorMapFrame);
    t2 = toc;
end
fprintf('Time taken to execute set command on scatter3 plot is: %g\n',t2)
Time taken to execute set command on scatter3 plot is: 0.00273102

Conclusion

Notice the difference in time taken by the showPointCloudand set command.

fprintf('Time taken for showPointCloud is %f seconds\n',t1);
fprintf('Time taken for set command is %f seconds\n',t2);
Time taken for showPointCloud is 0.141607 seconds
Time taken for set command is 0.002731 seconds

For visualizations of Point Clouds, use showPointCloud for one-time visualizations and scatter3 with the set command for streaming visualizations.