]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbctrlplot.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbctrlplot.m
1 function nrbctrlplot (nurbs)
2
3 % NRBCTRLPLOT: Plot a NURBS entity along with its control points.
4
5 % Calling Sequence:
6
7 %   nrbctrlplot (nurbs)
8
9 % INPUT:
10
11 %   nurbs: NURBS curve or surface, see nrbmak.
12
13 % Example:
14 %
15 %   Plot the test curve and test surface with their control polygon and
16 %    control net, respectively
17 %
18 %   nrbctrlplot(nrbtestcrv)
19 %   nrbctrlplot(nrbtestsrf)
20 %
21 % See also:
22
23 %   nrbkntplot
24 %
25 %    Copyright (C) 2011 Rafael Vazquez
26 %
27 %    This program is free software: you can redistribute it and/or modify
28 %    it under the terms of the GNU General Public License as published by
29 %    the Free Software Foundation, either version 2 of the License, or
30 %    (at your option) any later version.
31
32 %    This program is distributed in the hope that it will be useful,
33 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
34 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35 %    GNU General Public License for more details.
36 %
37 %    You should have received a copy of the GNU General Public License
38 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
39
40 if (nargin < 1)
41   error ('nrbctrlplot: Need a NURBS to plot!');
42 end
43
44 % Default values
45 light='on';
46 cmap='summer';
47
48 colormap (cmap);
49
50 hold_flag = ishold;
51
52 if (iscell (nurbs.knots))
53   if (size (nurbs.knots,2) == 3)
54     error ('nrbctrlplot: not implemented for NURBS volumes');
55   elseif (size (nurbs.knots,2) == 2) % plot a NURBS surface
56
57     nsub = 100;
58     nrbplot (nurbs, [nsub nsub], 'light', light, 'colormap', cmap);
59     hold on
60
61 % And plot the control net
62     for ii = 1:size (nurbs.coefs, 2)
63       coefs = reshape (nurbs.coefs(1:3,ii,:), 3, []);
64       weights = reshape (nurbs.coefs(4,ii,:), 1, []);
65       plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'k--')
66       plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'r.','MarkerSize',20)
67     end
68     for jj = 1:size (nurbs.coefs, 3)
69       coefs = reshape (nurbs.coefs(1:3,:,jj), 3, []);
70       weights = reshape (nurbs.coefs(4,:,jj), 1, []);
71       plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'k--')
72       plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'r.','MarkerSize',20)
73     end
74   end
75 else % plot a NURBS curve
76   nsub = 1000;
77   nrbplot (nurbs, nsub);
78   hold on
79
80 % And plot the control polygon
81   coefs = nurbs.coefs(1:3,:);
82   weights = nurbs.coefs(4,:);
83   plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'k--')
84   plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'r.','MarkerSize',20)
85 end
86
87 if (~hold_flag)
88   hold off
89 end
90
91 end
92
93 %!demo
94 %! crv = nrbtestcrv;
95 %! nrbctrlplot(crv)
96 %! title('Test curve')
97 %! hold off
98
99 %!demo
100 %! srf = nrbtestsrf;
101 %! nrbctrlplot(srf)
102 %! title('Test surface')
103 %! hold off
104