-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlidar_volume.m
63 lines (49 loc) · 1.45 KB
/
lidar_volume.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
%% Calculate volume by LIDAR point cloud
%
% Simple script that calculates volume of terrain object (heap, hill, mountain, etc) by point cloud
%
% Test data was loaded from <https://opentopography.org OpenTopography>
%
% Following toolboxes are necessary:
%
% *Lidar Toolbox*
% *Computer Vision Toolbox*
% Load LIDAR data
clear();
lasReader = lasFileReader(".\lidar_data.laz");
ptCloud = readPointCloud(lasReader);
% _Display point cloud_
ax = pcshow(ptCloud.Location);
ax.GridAlphaMode = "manual";
ax.GridAlpha = 1;
title('LIDAR data', 'FontWeight','Normal','FontSize',18,'Color','white');
% Do filtering
% with pcdenoise(...)
% Convert point cloud to surface
dens = 27800;
x = double(ptCloud.Location((1:dens:end),1));
y = double(ptCloud.Location((1:dens:end),2));
z = double(ptCloud.Location((1:dens:end),3));
sx = double(sum(size(x)));
sy = double(sum(size(y)));
xg = linspace(min(x), max(x), sx);
yg = linspace(min(y), max(y), sy);
[Xg, Yg] = meshgrid(xg, yg);
Zg = griddata(x, y, z, Xg, Yg);
Zg(isnan(Zg))=min(min(Zg));
% Calculate volume
vol = trapz(xg,trapz(yg, Zg));
% Display surface
figure(Color='black');
s = surf(Xg, Yg, Zg);
s.Parent.Color = "black";
s.Parent.XColor = 'white';
s.Parent.YColor = 'white';
s.Parent.ZColor = 'white';
s.Parent.GridAlphaMode = "manual";
s.Parent.GridAlpha = 1;
pbaspect(daspect());
header = sprintf('Volume: %0.5e', vol);
title(header, 'FontWeight','Normal','FontSize',18,'Color','white');
lighting gouraud
shading faceted