5683
|
1 /* Copyright (C) 2009 Carlo de Falco |
|
2 |
6958
|
3 This program is free software: you can redistribute it and/or modify |
5683
|
4 it under the terms of the GNU General Public License as published by |
11634
|
5 the Free Software Foundation, either version 3 of the License, or |
5683
|
6 (at your option) any later version. |
6958
|
7 |
5683
|
8 This program is distributed in the hope that it will be useful, |
|
9 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 GNU General Public License for more details. |
|
12 |
|
13 You should have received a copy of the GNU General Public License |
6958
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. |
5683
|
15 */ |
|
16 |
|
17 #include <octave/oct.h> |
|
18 #include "low_level_functions.h" |
|
19 |
|
20 DEFUN_DLD(basisfun, args, nargout, "\n\ |
|
21 BASISFUN: Compute B-Spline Basis Functions \n\ |
|
22 \n\ |
6958
|
23 Calling Sequence:\n\ |
|
24 \n\ |
|
25 N = basisfun(iv,uv,p,U)\n\ |
|
26 \n\ |
5683
|
27 INPUT:\n\ |
|
28 \n\ |
6958
|
29 iv - knot span ( from FindSpan() )\n\ |
|
30 uv - parametric point\n\ |
5683
|
31 p - spline degree\n\ |
|
32 U - knot sequence\n\ |
|
33 \n\ |
|
34 OUTPUT:\n\ |
|
35 \n\ |
6958
|
36 N - Basis functions vector(numel(uv)*(p+1))\n\ |
5683
|
37 \n\ |
|
38 Algorithm A2.2 from 'The NURBS BOOK' pg70.\n\ |
6958
|
39 \n\ |
5683
|
40 ") |
|
41 { |
|
42 |
|
43 octave_value_list retval; |
|
44 const NDArray i = args(0).array_value(); |
|
45 const NDArray u = args(1).array_value(); |
|
46 int p = args(2).idx_type_value(); |
|
47 const RowVector U = args(3).row_vector_value(); |
|
48 RowVector N(p+1, 0.0); |
12672
|
49 Matrix B(u.numel (), p+1, 0.0); |
5683
|
50 |
|
51 if (!error_state) |
|
52 { |
12672
|
53 for (octave_idx_type ii(0); ii < u.numel (); ii++) |
5683
|
54 { |
|
55 basisfun(int(i(ii)), u(ii), p, U, N); |
|
56 B.insert(N, ii, 0); |
|
57 } |
|
58 |
|
59 retval(0) = octave_value(B); |
|
60 } |
|
61 return retval; |
|
62 } |
|
63 |
|
64 /* |
|
65 %!shared n, U, p, u, s |
|
66 %!test |
|
67 %! n = 3; |
|
68 %! U = [0 0 0 1/2 1 1 1]; |
|
69 %! p = 2; |
|
70 %! u = linspace(0, 1, 10); |
|
71 %! s = findspan(n, p, u, U); |
|
72 %! assert (s, [2*ones(1, 5) 3*ones(1, 5)]); |
|
73 %!test |
|
74 %! Bref = [1.00000 0.00000 0.00000 |
|
75 %! 0.60494 0.37037 0.02469 |
|
76 %! 0.30864 0.59259 0.09877 |
|
77 %! 0.11111 0.66667 0.22222 |
|
78 %! 0.01235 0.59259 0.39506 |
|
79 %! 0.39506 0.59259 0.01235 |
|
80 %! 0.22222 0.66667 0.11111 |
|
81 %! 0.09877 0.59259 0.30864 |
|
82 %! 0.02469 0.37037 0.60494 |
|
83 %! 0.00000 0.00000 1.00000]; |
|
84 %! B = basisfun(s, u, p, U); |
|
85 %! assert (B, Bref, 1e-5); |
|
86 */ |