]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbdegelev.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbdegelev.m
1 function inurbs = nrbdegelev(nurbs, ntimes)
2
3 % NRBDEGELEV: Elevate the degree of the NURBS curve, surface or volume.
4
5 % Calling Sequence:
6
7 %   ecrv = nrbdegelev(crv,utimes);
8 %   esrf = nrbdegelev(srf,[utimes,vtimes]);
9 %   evol = nrbdegelev(vol,[utimes,vtimes,wtimes]);
10
11 % INPUT:
12
13 %   crv         : NURBS curve, see nrbmak.
14
15 %   srf         : NURBS surface, see nrbmak.
16
17 %   vol         : NURBS volume, see nrbmak.
18
19 %   utimes      : Increase the degree along U direction utimes.
20
21 %   vtimes      : Increase the degree along V direction vtimes.
22
23 %   wtimes      : Increase the degree along W direction vtimes.
24 %
25 % OUTPUT:
26 %
27 %   ecrv        : new NURBS structure for a curve with degree elevated.
28
29 %   esrf        : new NURBS structure for a surface with degree elevated.
30
31 %   evol        : new NURBS structure for a volume with degree elevated.
32
33
34 % Description:
35
36 %   Degree elevates the NURBS curve or surface. This function uses the
37 %   B-Spline function bspdegelev, which interface to an internal 'C'
38 %   routine.
39
40 % Examples:
41
42 %   Increase the NURBS surface twice along the V direction.
43 %   esrf = nrbdegelev(srf, [0, 2]); 
44
45 % See also:
46
47 %   bspdegelev
48 %
49 %    Copyright (C) 2000 Mark Spink, 2010 Rafel Vazquez
50 %
51 %    This program is free software: you can redistribute it and/or modify
52 %    it under the terms of the GNU General Public License as published by
53 %    the Free Software Foundation, either version 2 of the License, or
54 %    (at your option) any later version.
55
56 %    This program is distributed in the hope that it will be useful,
57 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
58 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
59 %    GNU General Public License for more details.
60 %
61 %    You should have received a copy of the GNU General Public License
62 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
63
64 if nargin < 2
65   error('Input argument must include the NURBS and degree increment.');
66 end
67
68 if ~isstruct(nurbs)
69   error('NURBS representation is not structure!');
70 end
71
72 if ~strcmp(nurbs.form,'B-NURBS')
73   error('Not a recognised NURBS representation');
74 end
75
76 degree = nurbs.order-1;
77
78 if iscell(nurbs.knots)
79  if size(nurbs.knots,2) == 3
80   % NURBS represents a volume
81   [dim,num1,num2,num3] = size(nurbs.coefs);
82
83   % Degree elevate along the w direction
84   if ntimes(3) == 0
85     coefs = nurbs.coefs;
86     knots{3} = nurbs.knots{3};
87   else
88     coefs = reshape(nurbs.coefs,4*num1*num2,num3);
89     [coefs,knots{3}] = bspdegelev(degree(3),coefs,nurbs.knots{3},ntimes(3));
90     num3 = size(coefs,2);
91     coefs = reshape(coefs,[4 num1 num2 num3]);
92   end
93
94   % Degree elevate along the v direction
95   if ntimes(2) == 0
96     knots{2} = nurbs.knots{2};
97   else
98     coefs = permute(coefs,[1 2 4 3]);
99     coefs = reshape(coefs,4*num1*num3,num2);
100     [coefs,knots{2}] = bspdegelev(degree(2),coefs,nurbs.knots{2},ntimes(2));
101     num2 = size(coefs,2);
102     coefs = reshape(coefs,[4 num1 num3 num2]);
103     coefs = permute(coefs,[1 2 4 3]);
104   end
105
106   % Degree elevate along the u direction
107   if ntimes(1) == 0
108     knots{1} = nurbs.knots{1};
109   else
110     coefs = permute(coefs,[1 3 4 2]);
111     coefs = reshape(coefs,4*num2*num3,num1);
112     [coefs,knots{1}] = bspdegelev(degree(1),coefs,nurbs.knots{1},ntimes(1));
113     coefs = reshape(coefs,[4 num2 num3 size(coefs,2)]);
114     coefs = permute(coefs,[1 4 2 3]);
115   end 
116
117  elseif size(nurbs.knots,2) == 2
118   % NURBS represents a surface
119   [dim,num1,num2] = size(nurbs.coefs);
120
121   % Degree elevate along the v direction
122   if ntimes(2) == 0
123     coefs = nurbs.coefs;
124     knots{2} = nurbs.knots{2};
125   else
126     coefs = reshape(nurbs.coefs,4*num1,num2);
127     [coefs,knots{2}] = bspdegelev(degree(2),coefs,nurbs.knots{2},ntimes(2));
128     num2 = size(coefs,2);
129     coefs = reshape(coefs,[4 num1 num2]);
130   end
131
132   % Degree elevate along the u direction
133   if ntimes(1) == 0
134     knots{1} = nurbs.knots{1};
135   else
136     coefs = permute(coefs,[1 3 2]);
137     coefs = reshape(coefs,4*num2,num1);
138     [coefs,knots{1}] = bspdegelev(degree(1),coefs,nurbs.knots{1},ntimes(1));
139     coefs = reshape(coefs,[4 num2 size(coefs,2)]);
140     coefs = permute(coefs,[1 3 2]);
141   end 
142  end
143 else
144
145   % NURBS represents a curve
146   if isempty(ntimes)
147     coefs = nurbs.coefs;
148     knots = nurbs.knots;
149   else
150     [coefs,knots] = bspdegelev(degree,nurbs.coefs,nurbs.knots,ntimes);
151   end
152   
153 end
154
155 % construct new NURBS
156 inurbs = nrbmak(coefs,knots);
157
158 end
159
160 %!demo
161 %! crv = nrbtestcrv;
162 %! plot(crv.coefs(1,:),crv.coefs(2,:),'bo')
163 %! title('Degree elevation along test curve: curve and control polygons.');
164 %! hold on;
165 %! plot(crv.coefs(1,:),crv.coefs(2,:),'b--');
166 %! nrbplot(crv,48);
167 %!
168 %! icrv = nrbdegelev(crv, 1);
169 %!
170 %! plot(icrv.coefs(1,:),icrv.coefs(2,:),'ro')
171 %! plot(icrv.coefs(1,:),icrv.coefs(2,:),'r--');
172 %! 
173 %! hold off;