1 function crvs = nrbextract(srf)
4 % NRBEXTRACT: construct NURBS curves by extracting the boundaries of a NURBS surface, or NURBS surfaces by extracting the boundary of a NURBS volume.
8 % crvs = nrbextract(surf);
12 % surf : NURBS surface or volume, see nrbmak.
16 % crvs : array of NURBS curves or NURBS surfaces extracted.
20 % Constructs either an array of four NURBS curves, by extracting the boundaries
21 % of a NURBS surface, or an array of six surfaces, by extracting the boundaries
22 % of a NURBS volume. The new entities are ordered in the following way
28 % 5: W = 0 (only for volumes)
29 % 6: W = 1 (only for volumes)
31 % Copyright (C) 2010 Rafael Vazquez
33 % This program is free software: you can redistribute it and/or modify
34 % it under the terms of the GNU General Public License as published by
35 % the Free Software Foundation, either version 2 of the License, or
36 % (at your option) any later version.
38 % This program is distributed in the hope that it will be useful,
39 % but WITHOUT ANY WARRANTY; without even the implied warranty of
40 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 % GNU General Public License for more details.
43 % You should have received a copy of the GNU General Public License
44 % along with this program. If not, see <http://www.gnu.org/licenses/>.
46 if (~iscell (srf.knots))
47 error('The boundary information is only extracted for NURBS surfaces or volumes');
50 if (numel (srf.knots) == 2)
52 ind2 = mod (ind, 2) + 1; %ind2 = [2 1];
53 bnd1 = (ind - 1) * 2 + 1;
54 bnd2 = (ind - 1) * 2 + 2;
56 coefs1 = squeeze (srf.coefs(:,1,:));
57 coefs2 = squeeze (srf.coefs(:,end,:));
59 coefs1 = squeeze (srf.coefs(:,:,1));
60 coefs2 = squeeze (srf.coefs(:,:,end));
62 crvs(bnd1) = nrbmak (coefs1, srf.knots{ind2});
63 crvs(bnd2) = nrbmak (coefs2, srf.knots{ind2});
65 elseif (numel (srf.knots) == 3)
67 inds = setdiff (1:3, ind);
68 bnd1 = (ind - 1) * 2 + 1;
69 bnd2 = (ind - 1) * 2 + 2;
71 coefs1 = squeeze (srf.coefs(:,1,:,:));
72 coefs2 = squeeze (srf.coefs(:,end,:,:));
74 coefs1 = squeeze (srf.coefs(:,:,1,:));
75 coefs2 = squeeze (srf.coefs(:,:,end,:));
77 coefs1 = squeeze (srf.coefs(:,:,:,1));
78 coefs2 = squeeze (srf.coefs(:,:,:,end));
80 crvs(bnd1) = nrbmak (coefs1, {srf.knots{inds(1)} srf.knots{inds(2)}});
81 crvs(bnd2) = nrbmak (coefs2, {srf.knots{inds(1)} srf.knots{inds(2)}});
84 error ('The entity is not a surface nor a volume')