]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbextract.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbextract.m
1 function crvs = nrbextract(srf)
2
3 %
4 % NRBEXTRACT: construct NURBS curves by extracting the boundaries of a NURBS surface, or NURBS surfaces by extracting the boundary of a NURBS volume.
5
6 % Calling Sequence:
7
8 %   crvs = nrbextract(surf);
9
10 % INPUT:
11
12 %   surf        : NURBS surface or volume, see nrbmak.
13
14 % OUTPUT: 
15
16 %   crvs        : array of NURBS curves or NURBS surfaces extracted.
17
18 % Description:
19
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
23 %
24 %    1: U = 0
25 %    2: U = 1
26 %    3: V = 0
27 %    4: V = 1
28 %    5: W = 0 (only for volumes)
29 %    6: W = 1 (only for volumes)
30 %
31 %    Copyright (C) 2010 Rafael Vazquez
32 %
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.
37
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.
42 %
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/>.
45
46 if (~iscell (srf.knots))
47   error('The boundary information is only extracted for NURBS surfaces or volumes');
48 end
49
50 if (numel (srf.knots) == 2)
51   for ind = 1:2
52     ind2 = mod (ind, 2) + 1;    %ind2 = [2 1];
53     bnd1 = (ind - 1) * 2 + 1;
54     bnd2 = (ind - 1) * 2 + 2;
55     if (ind == 1)
56       coefs1 = squeeze (srf.coefs(:,1,:));
57       coefs2 = squeeze (srf.coefs(:,end,:));
58     elseif (ind == 2)
59       coefs1 = squeeze (srf.coefs(:,:,1));
60       coefs2 = squeeze (srf.coefs(:,:,end));
61     end
62     crvs(bnd1) = nrbmak (coefs1, srf.knots{ind2});
63     crvs(bnd2) = nrbmak (coefs2, srf.knots{ind2});
64   end
65 elseif (numel (srf.knots) == 3)
66   for ind = 1:3
67     inds = setdiff (1:3, ind);
68     bnd1 = (ind - 1) * 2 + 1;
69     bnd2 = (ind - 1) * 2 + 2;
70     if (ind == 1)
71       coefs1 = squeeze (srf.coefs(:,1,:,:));
72       coefs2 = squeeze (srf.coefs(:,end,:,:));
73     elseif (ind == 2)
74       coefs1 = squeeze (srf.coefs(:,:,1,:));
75       coefs2 = squeeze (srf.coefs(:,:,end,:));
76     elseif (ind == 3)
77       coefs1 = squeeze (srf.coefs(:,:,:,1));
78       coefs2 = squeeze (srf.coefs(:,:,:,end));
79     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)}});
82   end
83 else
84   error ('The entity is not a surface nor a volume')
85 end
86
87 end