]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/bspeval.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / bspeval.m
1 function p = bspeval(d,c,k,u)
2
3 % BSPEVAL:  Evaluate B-Spline at parametric points.
4
5 % Calling Sequence:
6
7 %   p = bspeval(d,c,k,u)
8
9 %    INPUT:
10
11 %       d - Degree of the B-Spline.
12 %       c - Control Points, matrix of size (dim,nc).
13 %       k - Knot sequence, row vector of size nk.
14 %       u - Parametric evaluation points, row vector of size nu.
15
16 %    OUTPUT:
17 %
18 %       p - Evaluated points, matrix of size (dim,nu)
19
20 %    Copyright (C) 2000 Mark Spink, 2007 Daniel Claxton, 2010 C. de Falco
21 %
22 %    This program is free software: you can redistribute it and/or modify
23 %    it under the terms of the GNU General Public License as published by
24 %    the Free Software Foundation, either version 2 of the License, or
25 %    (at your option) any later version.
26
27 %    This program is distributed in the hope that it will be useful,
28 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
29 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30 %    GNU General Public License for more details.
31 %
32 %    You should have received a copy of the GNU General Public License
33 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
34
35 nu = numel(u);
36 [mc,nc] = size(c);
37                                                 %   int bspeval(int d, double *c, int mc, int nc, double *k, int nk, double *u,int nu, double *p){
38                                                 %   int ierr = 0;
39                                                 %   int i, s, tmp1, row, col;
40                                                 %   double tmp2;
41                                                 %
42                                                 %   // Construct the control points
43                                                 %   double **ctrl = vec2mat(c,mc,nc);
44                                                 %
45                                                 %   // Contruct the evaluated points
46 p = zeros(mc,nu);                               %   double **pnt = vec2mat(p,mc,nu);
47                                                 %
48                                                 %   // space for the basis functions
49 %N = zeros(d+1,1);                               %   double *N = (double*) mxMalloc((d+1)*sizeof(double));
50                                                 %
51                                                 %   // for each parametric point i
52 %for col=1:nu                                    %   for (col = 0; col < nu; col++) {
53                                                 %     // find the span of u[col]
54     s = findspan(nc-1, d, u(:), k);           %     s = findspan(nc-1, d, u[col], k);
55     N = basisfun(s,u(:),d,k);                 %     basisfun(s, u[col], d, k, N);
56                                                 %
57     tmp1 = s - d + 1;                           %     tmp1 = s - d;
58     %for row=1:mc                                %     for (row = 0; row < mc; row++)  {
59         p = zeros (mc, nu);                               %       tmp2 = 0.0;
60         for i=0:d                               %       for (i = 0; i <= d; i++)
61            p = p + repmat (N(:,i+1)', mc, 1).*c(:,tmp1+i);  %   tmp2 += N[i] * ctrl[tmp1+i][row];
62         end                                     %
63         %p(row,:) = tmp2;                      %       pnt[col][row] = tmp2;
64     %end                                         %     }
65 %end                                             %   }
66                                                 %
67                                                 %   mxFree(N);
68                                                 %   freevec2mat(pnt);
69                                                 %   freevec2mat(ctrl);
70                                                 %
71                                                 %   return ierr;
72 end                                             %   }