-
Notifications
You must be signed in to change notification settings - Fork 31
/
fillbox.m
92 lines (83 loc) · 2.47 KB
/
fillbox.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
function varargout=fillbox(lrtbmat,colvec,varargin)
% plothandles=FILLBOX(lrtbmat,colvec,opt)
%
% lrtbmat mX4 for m boxes whose Left Right Top Bottom you give
% colvec an mX3 RGB matrix
% an mX1 or 1Xm vector of strings
% 1 scalar (automatic indexing) or 1 letter string
% an mX1 or 1Xm vector of scalars
% opt 0 planar plot [default]
% 1 makes a three-dimensional plot
%
% EXAMPLE I:
%
% lrtb=[50 100 80 100];
% load clown; image(X); hold on; a=fillbox(lrtb,'w')
% b=boxmid(lrtb); c=text(b(1),b(2),'Clown');
% set(c,'HorizontalA','center','FontS',15)
% set(a,'FaceColor','y','EdgeColor','b')
%
% EXAMPLE II:
%
% lrtbmat=[10 20 20 10 ; 20 30 21 11 ; 31 41 29 22 ; 12 14 3 0];
% fillbox(lrtbmat,2)
% fillbox(lrtbmat,[1 2 3 4])
% fillbox(lrtbmat,'y')
% fillbox(lrtbmat,'ykbr')
% fillbox(lrtbmat,['y' 'k' 'b' 'r'])
% fillbox(lrtbmat,[{'y'},{'k'},{'b'},{'r'}])
% fillbox(lrtbmat,rand(size(lrtbmat,1),3))
%
% FILL3 gets fed MXN matrix for N polygons of order M
%
% SEE ALSO: EXT2LRTB
%
% TESTED ON: MATLAB Version: 8.3.0.532 (R2014a)
%
% Last modified by fjsimons-at-alum.mit.edu, 05/26/2021
defval('colvec',grey(8))
if size(lrtbmat,2)~=4; error('LRTB not mX4'); end
if ischar(colvec) | iscell(colvec)
colvec=getcol(colvec);
if size(colvec,1)==1; colvec=repmat(colvec,size(lrtbmat,1),1);end
else
% If it's a matrix
if prod(size(colvec))~=1 % Not just a number
if (size(colvec,2)~=3 | size(colvec,1)~=size(lrtbmat,1)) ...
& prod(size(colvec))~=size(lrtbmat,1)
error('Input color matrix is not in right format')
end
end
end
% Need to get it to give you a color specification.
if prod(size(colvec))~=size(lrtbmat,1)
colvec=colvec';
else
colvec=colvec(:)';
end
[m,n]=size(lrtbmat);
[left,right,top,bottom]=...
deal(lrtbmat(:,1),lrtbmat(:,2),lrtbmat(:,3),lrtbmat(:,4));
EKS=[left left right right]';
WAI=[top bottom bottom top]';
indo=repmat(1:size(EKS,2)',3,1);
indo=indo(:)';
% Plotting
if nargin>2
if prod(size(colvec))==1 | size(colvec,1)==1
plothandles=fill3(EKS,WAI,repmat(1,4,size(EKS,2)),colvec);
else
stev=sprintf('EKS(:,%i),WAI(:,%i),[1 ; 1; 1; 1],colvec(:,%i)'',',indo);
eval(['plothandles=fill3(' stev(1:end-1) ');'])
end
else
if prod(size(colvec))==1| size(colvec,1)==1
plothandles=fill(EKS,WAI,colvec);
else
stev=sprintf('EKS(:,%i),WAI(:,%i),colvec(:,%i)'',',indo);
eval(['plothandles=fill(' stev(1:end-1) ');'])
end
end
% Produce output
varns={plothandles};
varargout=varns(1:nargout);