]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbnumbasisfun.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbnumbasisfun.m
1 function idx = nrbnumbasisfun (points, nrb)
2 %
3 % NRBNUMBASISFUN:  Numbering of basis functions for NURBS
4 %
5 % Calling Sequence:
6
7 %   N      = nrbnumbasisfun (u, crv)
8 %   N      = nrbnumbasisfun ({u, v}, srf)
9 %   N      = nrbnumbasisfun (p, srf)
10 %
11 %    INPUT:
12 %   
13 %      u or p(1,:,:)  - parametric points along u direction
14 %      v or p(2,:,:)  - parametric points along v direction
15 %      crv - NURBS curve
16 %      srf - NURBS surface
17 %   
18 %    OUTPUT:
19 %
20 %      N - Indices of the basis functions that are nonvanishing at each
21 %          point. size(N) == size(B)
22 %
23 %    Copyright (C) 2009 Carlo de Falco
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<2) ...
39       || (nargout>1) ...
40       || (~isstruct(nrb)) ...
41       || (iscell(points) && ~iscell(nrb.knots)) ...
42       || (~iscell(points) && iscell(nrb.knots) && (size(points,1)~=2)) ...
43       )
44     error('Incorrect input arguments in nrbnumbasisfun');
45   end
46
47
48   if (~iscell(nrb.knots))          %% NURBS curve
49     
50     iv  = findspan (nrb.number-1, nrb.order-1, points, nrb.knots);
51     idx = numbasisfun (iv, points, nrb.order-1, nrb.knots);
52     
53   elseif size(nrb.knots,2) == 2  %% NURBS surface
54
55     if (iscell(points))
56       [v, u] = meshgrid(points{2}, points{1});
57       p(1,:,:) = u;
58       p(2,:,:) = v;
59       p = reshape(p, 2, []);
60     else
61       p = points;
62     end
63     
64     idx = nrb_srf_numbasisfun__ (p, nrb); 
65   else
66     error('The function nrbnumbasisfun is not yet ready for volumes')      
67   end
68   
69 end
70
71
72 %!test
73 %! p = 2;   q = 3;   m = 4; n = 5;
74 %! Lx  = 1; Ly  = 1; 
75 %! nrb = nrb4surf   ([0 0], [1 0], [0 1], [1 1]);
76 %! nrb = nrbdegelev (nrb, [p-1, q-1]);
77 %! ikx = linspace(0,1,m); iky = linspace(0,1,n);
78 %! nrb = nrbkntins  (nrb, {ikx(2:end-1), iky(2:end-1)});
79 %! nrb.coefs (4,:,:) = nrb.coefs (4,:,:) + rand (size (nrb.coefs (4,:,:)));
80 %! u = rand (1, 30); v = rand (1, 10);
81 %! u = (u-min (u))/max (u-min (u));
82 %! v = (v-min (v))/max (v-min (v));
83 %! N = nrbnumbasisfun ({u, v}, nrb);
84 %! assert (all (all (N>0)), true)
85 %! assert (all (all (N <= prod (nrb.number))), true)
86 %! assert (max (max (N)), prod (nrb.number))
87 %! assert (min (min (N)), 1)