]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbkntplot.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbkntplot.m
1 function nrbkntplot (nurbs)
2
3 % NRBKNTPLOT: Plot a NURBS entity with the knots subdivision.
4
5 % Calling Sequence:
6
7 %   nrbkntplot(nurbs)
8
9 % INPUT:
10
11 %   nurbs: NURBS curve, surface or volume, see nrbmak.
12
13 % Example:
14 %
15 %   Plot the test surface with its knot vector
16 %
17 %   nrbkntplot(nrbtestsrf)
18 %
19 % See also:
20
21 %   nrbctrlplot
22 %
23 %    Copyright (C) 2011 Rafael Vazquez
24 %
25 %    This program is free software: you can redistribute it and/or modify
26 %    it under the terms of the GNU General Public License as published by
27 %    the Free Software Foundation, either version 2 of the License, or
28 %    (at your option) any later version.
29
30 %    This program is distributed in the hope that it will be useful,
31 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
32 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 %    GNU General Public License for more details.
34 %
35 %    You should have received a copy of the GNU General Public License
36 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
37
38 if (nargin < 1)
39   error ('nrbkntplot: Need a NURBS to plot!');
40 end
41
42 % Default values
43 light='on';
44 cmap='summer';
45
46 colormap (cmap);
47
48 hold_flag = ishold;
49
50 if (iscell (nurbs.knots))
51  if (size (nurbs.knots,2) == 2) % plot a NURBS surface
52    nsub = 100;
53    nrbplot (nurbs, [nsub nsub], 'light', light, 'colormap', cmap);
54    hold on
55
56    % And plot the knots
57    knt1 = unique (nurbs.knots{1});
58    knt2 = unique (nurbs.knots{2});
59    p1 = nrbeval (nurbs, {knt1, linspace(0.0,1.0,nsub)});
60    p2 = nrbeval (nurbs, {linspace(0.0,1.0,nsub), knt2});
61
62   if (any (nurbs.coefs(3,:)))
63     % surface in a 3D space
64     for ii = 1:numel(knt1)
65       plot3 (squeeze(p1(1,ii,:)), squeeze(p1(2,ii,:)), squeeze(p1(3,ii,:)));
66     end
67     for ii = 1:numel(knt2)
68       plot3 (squeeze(p2(1,:,ii)), squeeze(p2(2,:,ii)), squeeze(p2(3,:,ii))); 
69     end
70   else
71     % plain surface
72     for ii = 1:numel(knt1)
73       plot (squeeze(p1(1,ii,:)), squeeze (p1(2,ii,:))); 
74     end
75     for ii = 1:numel(knt2)
76       plot (p2(1,:,ii),p2(2,:,ii));
77     end
78   end
79
80
81
82  elseif (size (nurbs.knots,2) == 3) % plot a NURBS volume
83    nsub = 30;
84    nrbplot (nurbs, [nsub nsub nsub], 'light', light, 'colormap', cmap);
85    hold on
86
87    % And plot the knots
88    knt1 = unique (nurbs.knots{1});
89    knt2 = unique (nurbs.knots{2});
90    knt3 = unique (nurbs.knots{3});
91    kv_face1 = nrbeval (nurbs, {0, knt2, linspace(0.0,1.0,nsub)});
92    kw_face1 = nrbeval (nurbs, {0, linspace(0.0,1.0,nsub), knt3});
93    kv_face2 = nrbeval (nurbs, {1, knt2, linspace(0.0,1.0,nsub)});
94    kw_face2 = nrbeval (nurbs, {1, linspace(0.0,1.0,nsub), knt3});
95    ku_face3 = nrbeval (nurbs, {knt1, 0, linspace(0.0,1.0,nsub)});
96    kw_face3 = nrbeval (nurbs, {linspace(0.0,1.0,nsub), 0, knt3});
97    ku_face4 = nrbeval (nurbs, {knt1, 1, linspace(0.0,1.0,nsub)});
98    kw_face4 = nrbeval (nurbs, {linspace(0.0,1.0,nsub), 1, knt3});
99    ku_face5 = nrbeval (nurbs, {knt1, linspace(0.0,1.0,nsub), 0});
100    kv_face5 = nrbeval (nurbs, {linspace(0.0,1.0,nsub), knt2, 0});
101    ku_face6 = nrbeval (nurbs, {knt1, linspace(0.0,1.0,nsub), 1});
102    kv_face6 = nrbeval (nurbs, {linspace(0.0,1.0,nsub), knt2, 1});
103
104    for ii = 1:numel(knt1)
105      plot3 (squeeze (ku_face3(1,ii,:,:)), squeeze (ku_face3(2,ii,:,:)), squeeze (ku_face3(3,ii,:,:))); 
106      plot3 (squeeze (ku_face4(1,ii,:,:)), squeeze (ku_face4(2,ii,:,:)), squeeze (ku_face4(3,ii,:,:))); 
107      plot3 (squeeze (ku_face5(1,ii,:,:)), squeeze (ku_face5(2,ii,:,:)), squeeze (ku_face5(3,ii,:,:))); 
108      plot3 (squeeze (ku_face6(1,ii,:,:)), squeeze (ku_face6(2,ii,:,:)), squeeze (ku_face6(3,ii,:,:))); 
109    end
110    for ii = 1:numel(knt2)
111      plot3 (squeeze (kv_face1(1,:,ii,:)), squeeze (kv_face1(2,:,ii,:)), squeeze (kv_face1(3,:,ii,:))); 
112      plot3 (squeeze (kv_face2(1,:,ii,:)), squeeze (kv_face2(2,:,ii,:)), squeeze (kv_face2(3,:,ii,:))); 
113      plot3 (squeeze (kv_face5(1,:,ii,:)), squeeze (kv_face5(2,:,ii,:)), squeeze (kv_face5(3,:,ii,:))); 
114      plot3 (squeeze (kv_face6(1,:,ii,:)), squeeze (kv_face6(2,:,ii,:)), squeeze (kv_face6(3,:,ii,:))); 
115    end
116    for ii = 1:numel(knt3)
117      plot3 (squeeze (kw_face1(1,:,:,ii)), squeeze(kw_face1(2,:,:,ii)), squeeze (kw_face1(3,:,:,ii))); 
118      plot3 (squeeze (kw_face2(1,:,:,ii)), squeeze(kw_face2(2,:,:,ii)), squeeze (kw_face2(3,:,:,ii))); 
119      plot3 (squeeze (kw_face3(1,:,:,ii)), squeeze(kw_face3(2,:,:,ii)), squeeze (kw_face3(3,:,:,ii))); 
120      plot3 (squeeze (kw_face4(1,:,:,ii)), squeeze(kw_face4(2,:,:,ii)), squeeze (kw_face4(3,:,:,ii))); 
121    end
122  end
123
124 else % plot a NURBS curve
125   nsub = 1000;
126   nrbplot (nurbs, nsub);
127   hold on
128
129   % And plot the knots
130    p = nrbeval (nurbs, unique (nurbs.knots));
131
132    if (any (nurbs.coefs(3,:))) % plot a 3D curve
133      plot3 (p(1,:), p(2,:), p(3,:), 'x'); 
134    else                     % plot a 2D curve
135      plot (p(1,:), p(2,:), 'x'); 
136    end
137
138 end
139
140 if (~hold_flag)
141   hold off
142 end
143
144 end
145 %!demo
146 %! crv = nrbtestcrv;
147 %! nrbkntplot(crv)
148 %! title('Test curve')
149 %! hold off
150
151 %!demo
152 %! sphere = nrbrevolve(nrbcirc(1,[],0.0,pi),[0.0 0.0 0.0],[1.0 0.0 0.0]);
153 %! nrbkntplot(sphere);
154 %! title('Ball and torus - surface construction by revolution');
155 %! hold on;
156 %! torus = nrbrevolve(nrbcirc(0.2,[0.9 1.0]),[0.0 0.0 0.0],[1.0 0.0 0.0]);
157 %! nrbkntplot(torus);
158 %! hold off
159
160 %!demo
161 %! knots = {[0 0 0 1/2 1 1 1] [0 0 0 1 1 1]...
162 %!          [0 0 0 1/6 2/6 1/2 1/2 4/6 5/6 1 1 1]};
163 %!
164 %! coefs = [-1.0000   -0.9734   -0.7071    1.4290    1.0000    3.4172
165 %!          0    2.4172         0    0.0148   -2.0000   -1.9734
166 %!          0    2.0000    4.9623    9.4508    4.0000    2.0000
167 %!     1.0000    1.0000    0.7071    1.0000    1.0000    1.0000
168 %!    -0.8536         0   -0.6036    1.9571    1.2071    3.5000
169 %!     0.3536    2.5000    0.2500    0.5429   -1.7071   -1.0000
170 %!          0    2.0000    4.4900    8.5444    3.4142    2.0000
171 %!     0.8536    1.0000    0.6036    1.0000    0.8536    1.0000
172 %!    -0.3536   -4.0000   -0.2500   -1.2929    1.7071    1.0000
173 %!     0.8536         0    0.6036   -2.7071   -1.2071   -5.0000
174 %!          0    2.0000    4.4900   10.0711    3.4142    2.0000
175 %!     0.8536    1.0000    0.6036    1.0000    0.8536    1.0000
176 %!          0   -4.0000         0    0.7071    2.0000    5.0000
177 %!     1.0000    4.0000    0.7071   -0.7071   -1.0000   -5.0000
178 %!          0    2.0000    4.9623   14.4142    4.0000    2.0000
179 %!     1.0000    1.0000    0.7071    1.0000    1.0000    1.0000
180 %!    -2.5000   -4.0000   -1.7678    0.7071    1.0000    5.0000
181 %!          0    4.0000         0   -0.7071   -3.5000   -5.0000
182 %!          0    2.0000    6.0418   14.4142    4.0000    2.0000
183 %!     1.0000    1.0000    0.7071    1.0000    1.0000    1.0000
184 %!    -2.4379         0   -1.7238    2.7071    1.9527    5.0000
185 %!     0.9527    4.0000    0.6737    1.2929   -3.4379   -1.0000
186 %!          0    2.0000    6.6827   10.0711    4.0000    2.0000
187 %!     1.0000    1.0000    0.7071    1.0000    1.0000    1.0000
188 %!    -0.9734   -1.0000   -0.6883    0.7071    3.4172    1.0000
189 %!     2.4172         0    1.7092   -1.4142   -1.9734   -2.0000
190 %!          0    4.0000    6.6827    4.9623    4.0000         0
191 %!     1.0000    1.0000    0.7071    0.7071    1.0000    1.0000
192 %!          0   -0.8536         0    0.8536    3.5000    1.2071
193 %!     2.5000    0.3536    1.7678   -1.2071   -1.0000   -1.7071
194 %!          0    3.4142    6.0418    4.4900    4.0000         0
195 %!     1.0000    0.8536    0.7071    0.6036    1.0000    0.8536
196 %!    -4.0000   -0.3536   -2.8284    1.2071    1.0000    1.7071
197 %!          0    0.8536         0   -0.8536   -5.0000   -1.2071
198 %!          0    3.4142    7.1213    4.4900    4.0000         0
199 %!     1.0000    0.8536    0.7071    0.6036    1.0000    0.8536
200 %!    -4.0000         0   -2.8284    1.4142    5.0000    2.0000
201 %!     4.0000    1.0000    2.8284   -0.7071   -5.0000   -1.0000
202 %!          0    4.0000   10.1924    4.9623    4.0000         0
203 %!     1.0000    1.0000    0.7071    0.7071    1.0000    1.0000
204 %!    -4.0000   -2.5000   -2.8284    0.7071    5.0000    1.0000
205 %!     4.0000         0    2.8284   -2.4749   -5.0000   -3.5000
206 %!          0    4.0000   10.1924    6.0418    4.0000         0
207 %!     1.0000    1.0000    0.7071    0.7071    1.0000    1.0000
208 %!          0   -2.4379         0    1.3808    5.0000    1.9527
209 %!     4.0000    0.9527    2.8284   -2.4309   -1.0000   -3.4379
210 %!          0    4.0000    7.1213    6.6827    4.0000         0
211 %!     1.0000    1.0000    0.7071    0.7071    1.0000    1.0000
212 %!    -1.0000   -0.9734    0.2071    2.4163    1.0000    3.4172
213 %!          0    2.4172   -1.2071   -1.3954   -2.0000   -1.9734
214 %!     2.0000    4.0000    7.0178    6.6827    2.0000         0
215 %!     1.0000    1.0000    1.0000    0.7071    1.0000    1.0000
216 %!    -0.8536         0    0.3536    2.4749    1.2071    3.5000
217 %!     0.3536    2.5000   -0.8536   -0.7071   -1.7071   -1.0000
218 %!     1.7071    4.0000    6.3498    6.0418    1.7071         0
219 %!     0.8536    1.0000    0.8536    0.7071    0.8536    1.0000
220 %!    -0.3536   -4.0000    0.8536    0.7071    1.7071    1.0000
221 %!     0.8536         0   -0.3536   -3.5355   -1.2071   -5.0000
222 %!     1.7071    4.0000    6.3498    7.1213    1.7071         0
223 %!     0.8536    1.0000    0.8536    0.7071    0.8536    1.0000
224 %!          0   -4.0000    1.2071    3.5355    2.0000    5.0000
225 %!     1.0000    4.0000   -0.2071   -3.5355   -1.0000   -5.0000
226 %!     2.0000    4.0000    7.0178   10.1924    2.0000         0
227 %!     1.0000    1.0000    1.0000    0.7071    1.0000    1.0000
228 %!    -2.5000   -4.0000   -0.5429    3.5355    1.0000    5.0000
229 %!          0    4.0000   -1.9571   -3.5355   -3.5000   -5.0000
230 %!     2.0000    4.0000    8.5444   10.1924    2.0000         0
231 %!     1.0000    1.0000    1.0000    0.7071    1.0000    1.0000
232 %!    -2.4379         0   -0.0355    3.5355    1.9527    5.0000
233 %!     0.9527    4.0000   -1.4497   -0.7071   -3.4379   -1.0000
234 %!     2.0000    4.0000    9.4508    7.1213    2.0000         0
235 %!     1.0000    1.0000    1.0000    0.7071    1.0000    1.0000];
236 %! coefs = reshape (coefs, 4, 4, 3, 9);
237 %! horseshoe = nrbmak (coefs, knots);
238 %! nrbkntplot (horseshoe);