1 function inurbs = nrbdegelev(nurbs, ntimes)
3 % NRBDEGELEV: Elevate the degree of the NURBS curve, surface or volume.
7 % ecrv = nrbdegelev(crv,utimes);
8 % esrf = nrbdegelev(srf,[utimes,vtimes]);
9 % evol = nrbdegelev(vol,[utimes,vtimes,wtimes]);
13 % crv : NURBS curve, see nrbmak.
15 % srf : NURBS surface, see nrbmak.
17 % vol : NURBS volume, see nrbmak.
19 % utimes : Increase the degree along U direction utimes.
21 % vtimes : Increase the degree along V direction vtimes.
23 % wtimes : Increase the degree along W direction vtimes.
27 % ecrv : new NURBS structure for a curve with degree elevated.
29 % esrf : new NURBS structure for a surface with degree elevated.
31 % evol : new NURBS structure for a volume with degree elevated.
36 % Degree elevates the NURBS curve or surface. This function uses the
37 % B-Spline function bspdegelev, which interface to an internal 'C'
42 % Increase the NURBS surface twice along the V direction.
43 % esrf = nrbdegelev(srf, [0, 2]);
49 % Copyright (C) 2000 Mark Spink, 2010 Rafel Vazquez
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.
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.
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/>.
65 error('Input argument must include the NURBS and degree increment.');
69 error('NURBS representation is not structure!');
72 if ~strcmp(nurbs.form,'B-NURBS')
73 error('Not a recognised NURBS representation');
76 degree = nurbs.order-1;
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);
83 % Degree elevate along the w direction
86 knots{3} = nurbs.knots{3};
88 coefs = reshape(nurbs.coefs,4*num1*num2,num3);
89 [coefs,knots{3}] = bspdegelev(degree(3),coefs,nurbs.knots{3},ntimes(3));
91 coefs = reshape(coefs,[4 num1 num2 num3]);
94 % Degree elevate along the v direction
96 knots{2} = nurbs.knots{2};
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]);
106 % Degree elevate along the u direction
108 knots{1} = nurbs.knots{1};
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]);
117 elseif size(nurbs.knots,2) == 2
118 % NURBS represents a surface
119 [dim,num1,num2] = size(nurbs.coefs);
121 % Degree elevate along the v direction
124 knots{2} = nurbs.knots{2};
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]);
132 % Degree elevate along the u direction
134 knots{1} = nurbs.knots{1};
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]);
145 % NURBS represents a curve
150 [coefs,knots] = bspdegelev(degree,nurbs.coefs,nurbs.knots,ntimes);
155 % construct new NURBS
156 inurbs = nrbmak(coefs,knots);
162 %! plot(crv.coefs(1,:),crv.coefs(2,:),'bo')
163 %! title('Degree elevation along test curve: curve and control polygons.');
165 %! plot(crv.coefs(1,:),crv.coefs(2,:),'b--');
168 %! icrv = nrbdegelev(crv, 1);
170 %! plot(icrv.coefs(1,:),icrv.coefs(2,:),'ro')
171 %! plot(icrv.coefs(1,:),icrv.coefs(2,:),'r--');