-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcshow.m
165 lines (146 loc) · 5.26 KB
/
pcshow.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function ax = pcshow(varargin)
%pcshow Plot 3-D point cloud.
% pcshow(ptCloud) displays points with locations and colors
% stored in the pointCloud object ptCloud. Use this function to display
% static point cloud data.
%
% pcshow(xyzPoints) displays points at the locations that are
% contained in an M-by-3 or M-by-N-by-3 xyzPoints matrix. The matrix,
% xyzPoints, contains M or M-by-N [x,y,z] points. The color of each point
% is determined by its Z value, which is linearly mapped to a color in
% the current colormap.
%
% pcshow(xyzPoints,C) displays points at the locations that are
% contained in the M-by-3 or M-by-N-by-3 xyzPoints matrix with colors
% specified by C. To specify the same color for all points, C must be a
% color string or a 1-by-3 RGB vector. To specify a different color for
% each point, C must be one of the following:
% - A vector or M-by-N matrix containing values that are linearly mapped
% to a color in the current colormap.
% - An M-by-3 or M-by-N-by-3 matrix containing RGB values for each point.
%
% ax = pcshow(...) returns the plot's axes.
%
% pcshow(...,Name,Value) uses additional options specified by one
% or more Name,Value pair arguments below:
%
% 'MarkerSize' A positive scalar specifying the approximate
% diameter of the point marker in points, a unit
% defined by MATLAB graphics.
%
% Default: 6
%
% 'VerticalAxis' A string specifying the vertical axis, whose value
% is 'X', 'Y' or 'Z'.
%
% Default: 'Z'
%
% 'VerticalAxisDir' A string specifying the direction of the vertical
% axis, whose value is 'Up' or 'Down'.
%
% Default: 'Up'
%
% 'Parent' Specify an output axes for displaying the
% visualization.
%
% Notes
% -----
% Points with NaN or inf coordinates will not be plotted.
%
% A 'MarkerSize' greater than 6 points may reduce rendering performance.
%
% cameratoolbar will be automatically turned on in the current figure.
%
% Class Support
% -------------
% ptCloud must be a pointCloud object. xyzPoints must be numeric. C must
% be a color string or numeric.
%
% Example: Plot spherical point cloud with color
% -----------------------------------------------------------------
% % Generate a sphere consisting of 600-by-600 faces
% numFaces = 600;
% [x,y,z] = sphere(numFaces);
% ptCloud = pointCloud([x(:),y(:),z(:)]);
%
% % plot the sphere with the default color map
% figure
% pcshow(ptCloud)
% title('Sphere with the default color map')
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
%
% % load an image for texture mapping
% I = imread('visionteam1.jpg');
%
% % resize and flip the image for mapping the coordinates
% J = flipud(imresize(I, size(x)));
% colorPtCloud = pointCloud([x(:),y(:),z(:)], 'Color', reshape(J, [], 3));
%
% % plot the sphere with the color texture
% figure
% pcshow(colorPtCloud);
% title('Sphere with the color texture')
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
%
% See also pointCloud, pcplayer, reconstructScene, triangulate, plot3, scatter3
% Copyright 2013-2014 The MathWorks, Inc.
[X, Y, Z, C, markerSize, vertAxis, vertAxisDir, currentAxes] = ...
validateAndParseInputs(varargin{:});
% Plot to the specified axis, or create a new one
if isempty(currentAxes)
currentAxes = newplot;
end
% Get the current figure handle
hFigure = get(currentAxes,'Parent');
% Check the renderer
if strcmpi(hFigure.Renderer, 'painters')
error(message('vision:pointcloud:badRenderer'));
end
if isempty(C)
scatter3(currentAxes, X, Y, Z, markerSize, Z, '.');
elseif (ischar(C) || isequal(size(C),[1,3]))
try
plot3(currentAxes, X, Y, Z, '.', 'Color', C, 'MarkerSize', markerSize);
grid(currentAxes, 'on');
catch exception
throwAsCaller(exception);
end
else
scatter3(currentAxes, X, Y, Z, markerSize, C, '.');
end
% Lower and upper limit of auto downsampling.
ptCloudThreshold = [1920*1080, 1e8];
% Initialize point cloud viewer controls.
initializePCSceneControl(hFigure, currentAxes, vertAxis,...
vertAxisDir, ptCloudThreshold, true);
if nargout > 0
ax = currentAxes;
end
end
%==========================================================================
function [X, Y, Z, C, markerSize, vertAxis, vertAxisDir, ax] = validateAndParseInputs(varargin)
% Validate and parse inputs
narginchk(1, 10);
% the 2nd argument is C only if the number of arguments is even and the
% first argument is not a pointCloud object
if ~bitget(nargin, 1) && ~isa(varargin{1}, 'pointCloud')
[X, Y, Z, C] = validateAndParseInputsXYZC(mfilename, varargin{1:2});
pvpairs = varargin(3:end);
else
[X, Y, Z, C] = validateAndParseInputsXYZC(mfilename, varargin{1});
pvpairs = varargin(2:end);
end
parser = getSharedParamParser(mfilename);
parser.addParameter('Parent', [], ...
@vision.internal.inputValidation.validateAxesHandle);
parser.parse(pvpairs{:});
params = parser.Results;
markerSize = params.MarkerSize;
ax = params.Parent;
vertAxis = params.VerticalAxis;
vertAxisDir = params.VerticalAxisDir;
end