1% @file gsTHBSpline.m
2%
3%    @brief Matlab wrapper for gsTHBSplineBasis class
4%
5%    This file is part of the G+Smo library.
6%
7%    This Source Code Form is subject to the terms of the Mozilla Public
8%    License, v. 2.0. If a copy of the MPL was not distributed with this
9%    file, You can obtain one at http://mozilla.org/MPL/2.0/.
10%
11%    Author(s): O. Chanon, P. Noertoft
12
13classdef gsTHBSplineBasis < handle
14
15    properties (SetAccess = private, Hidden = true)
16        objectHandle; % Handle to the underlying C++ class instance
17    end
18
19    methods(Access = public)
20
21        % Constructor - Create a new C++ class instance
22        function this = gsTHBSplineBasis(varargin)
23            %gsTHBSplineBasis - construct a gsTHBSplineBasis object
24            %
25            %Usage:
26            %  thb = gsTHBSplineBasis( file )
27            %
28            %Input:
29            %  file: char, [1 x numChar].
30            %    Name of input file from which to read/construct the
31            %    gsTHBSplineBasis.
32            %
33            %Output:
34            %  thb: gsTHBSplineBasis, [1 x 1].
35            %    The gsTHBSplineBasis object.
36
37            if (nargin~=1 || nargout>1)
38                error('Invalid number of input and/or output arguments.')
39            end
40
41            if (isa(varargin{1},'uint64'))
42                this.objectHandle = varargin{1};
43            else
44                if (~(isa(varargin{1},'char')))
45                    error('Input argument no. 1 should be of type ''char''.')
46                elseif (~exist(varargin{1},'file'))
47                    error('File does not exist: %s.',varargin{1})
48                end
49                this.objectHandle = mex_gsTHBSplineBasis('constructor', class(varargin{1}), varargin{:});
50            end
51        end
52
53        % Destructor - Destroy the C++ class instance
54        function delete(this)
55            %delete - delete a gsTHBSplineBasis object
56            %
57            %Usage:
58            %  thb.delete()
59            %
60            %Input:
61            %  thb: gsTHBSplineBasis, [1 x 1].
62            %    The gsTHBSplineBasis object.
63            %
64            %Output:
65            %  (none)
66
67            mex_gsTHBSplineBasis('destructor', this.objectHandle);
68        end
69
70        % dim - call class method
71        function varargout = dim(this, varargin)
72            %dim - dimension of the parameter space of a gsTHBSplineBasis object
73            %
74            %Usage:
75            %  val = thb.dim()
76            %
77            %Input:
78            %  thb: gsTHBSplineBasis, [1 x 1].
79            %    The gsTHBSplineBasis object.
80            %
81            %Output:
82            %  val: double, [1 x 1].
83            %    Dimension of the parameter space of the gsTHBSplineBasis.
84
85            if (nargin~=1 || nargout>1)
86                error('Invalid number of input and/or output arguments.')
87            end
88            [varargout{1:nargout}] = mex_gsTHBSplineBasis('accessor', this.objectHandle, 'dim',  varargin{:});
89        end
90
91        % numElements - call class method
92        function varargout = numElements(this, varargin)
93            %numElements - number of elements of a gsTHBSplineBasis object
94            %
95            %Usage:
96            %  num = thb.numElements()
97            %
98            %Input:
99            %  thb: gsTHBSplineBasis, [1 x 1].
100            %    The gsTHBSplineBasis object.
101            %
102            %Output:
103            %  num: double, [1 x 1].
104            %    Number of elements of the gsTHBSplineBasis.
105
106            if (nargin~=1 || nargout>1)
107                error('Invalid number of input and/or output arguments.')
108            end
109            [varargout{1:nargout}] = mex_gsTHBSplineBasis('accessor', this.objectHandle, 'numElements',  varargin{:});
110        end
111
112        % support - call class method
113        function varargout = support(this, varargin)
114            %support - support of a gsTHBSplineBasis object
115            %
116            %Usage:
117            %  supp = thb.support()
118            %
119            %Input:
120            %  thb: gsTHBSplineBasis, [1 x 1].
121            %    The gsTHBSplineBasis object.
122            %
123            %Output:
124            %  supp: double, [1 x 2*d].
125            %    Support of the gsTHBSplineBasis, ordered like
126            %      [u1_min, ..., ud_min, u1_max, ..., ud_max]
127            %    where d is the parametric dimennsion of the
128            %    gsTHBSplineBasis.
129
130            if (nargin~=1 || nargout>1)
131                error('Invalid number of input and/or output arguments.')
132            end
133            [varargout{1:nargout}] = mex_gsTHBSplineBasis('accessor', this.objectHandle, 'support',  varargin{:});
134        end
135
136        % size - call class method
137        function varargout = size(this, varargin)
138            %size - size of a gsTHBSplineBasis object
139            %
140            %Usage:
141            %  num = thb.size()
142            %
143            %Input:
144            %  thb: gsTHBSplineBasis, [1 x 1].
145            %    The gsTHBSplineBasis object.
146            %
147            %Output:
148            %  num: double, [1 x 1].
149            %    Size of the gsTHBSplineBasis.
150
151            if (nargin~=1 || nargout>1)
152                error('Invalid number of input and/or output arguments.')
153            end
154            [varargout{1:nargout}] = mex_gsTHBSplineBasis('accessor', this.objectHandle, 'size',  varargin{:});
155        end
156
157        % treeSize - call class method
158        function varargout = treeSize(this, varargin)
159            %treeSize - size of the tree of a gsTHBSplineBasis object
160            %
161            %Usage:
162            %  num = thb.treeSize()
163            %
164            %Input:
165            %  thb: gsTHBSplineBasis, [1 x 1].
166            %    The gsTHBSplineBasis object.
167            %
168            %Output:
169            %  num: double, [1 x 1].
170            %    Size of the tree of the gsTHBSplineBasis.
171
172            if (nargin~=1 || nargout>1)
173                error('Invalid number of input and/or output arguments.')
174            end
175            [varargout{1:nargout}] = mex_gsTHBSplineBasis('accessor', this.objectHandle, 'treeSize',  varargin{:});
176        end
177
178        % treeLeafSize - call class method
179        function varargout = treeLeafSize(this, varargin)
180            %treeLeafSize - size of the leaf in the tree of a gsTHBSplineBasis object
181            %
182            %Usage:
183            %  num = thb.treeLeafSize()
184            %
185            %Input:
186            %  thb: gsTHBSplineBasis, [1 x 1].
187            %    The gsTHBSplineBasis object.
188            %
189            %Output:
190            %  num: double, [1 x 1].
191            %    Size of the leaf in the tree of the gsTHBSplineBasis.
192
193            if (nargin~=1 || nargout>1)
194                error('Invalid number of input and/or output arguments.')
195            end
196            [varargout{1:nargout}] = mex_gsTHBSplineBasis('accessor', this.objectHandle, 'treeLeafSize',  varargin{:});
197        end
198
199        % maxLevel - call class method
200        function varargout = maxLevel(this, varargin)
201            %maxLevel - maximum level of a gsTHBSplineBasis object
202            %
203            %Usage:
204            %  lev = thb.maxLevel()
205            %
206            %Input:
207            %  thb: gsTHBSplineBasis, [1 x 1].
208            %    The gsTHBSplineBasis object.
209            %
210            %Output:
211            %  lev: double, [1 x 1].
212            %    Maximum level present in the hierarchy of the
213            %    gsTHBSplineBasis object.
214
215            if (nargin~=1 || nargout>1)
216                error('Invalid number of input and/or output arguments.')
217            end
218            [varargout{1:nargout}] = mex_gsTHBSplineBasis('accessor', this.objectHandle, 'maxLevel',  varargin{:});
219        end
220
221        % treePrintLeaves - call class method
222        function varargout = treePrintLeaves(this, varargin)
223            %treePrintLeaves - print the leaves in the tree of a gsTHBSplineBasis object
224            %
225            %Usage:
226            %  thb.treePrintLeaves()
227            %
228            %Input:
229            %  thb: gsTHBSplineBasis, [1 x 1].
230            %    The gsTHBSplineBasis object.
231            %
232            %Output:
233            %  (none - outputs to the screen).
234
235            if (nargin~=1 || nargout>0)
236                error('Invalid number of input and/or output arguments.')
237            end
238            [varargout{1:nargout}] = mex_gsTHBSplineBasis('treePrintLeaves', this.objectHandle, varargin{:});
239        end
240
241        % degree - call class method
242        function [varargout] = degree(this, varargin)
243            %degree - the degree for a specified direction of a
244            %   gsTHBSplineBasis object
245            %
246            %Usage:
247            %  deg = thb.degree( dir )
248            %
249            %Input:
250            %  thb: gsTHBSplineBasis, [1 x 1].
251            %    The gsTHBSplineBasis object.
252            %  dir: int, [1 x 1].
253            %    Direction of space for which we want to know the degree of
254            %    the gsTHBSplineBasis.
255            %
256            %Output:
257            %  deg: double, [1 x 1].
258            %    Degree of the gsTHBSplineBasis object in direction dir.
259
260            if (nargin~=2 || nargout>1)
261                error('Invalid number of input and/or output arguments.')
262            end
263            if (~isa(varargin{1},'numeric') || ~isscalar(varargin{1}) || ...
264                    ~(mod(varargin{1},1)==0) || varargin{1}>this.dim())
265                error('Input argument must be an integer less than %d.', this.dim())
266            end
267            [varargout{1:nargout}] = mex_gsTHBSplineBasis('degree', this.objectHandle, varargin{:});
268        end
269
270        % eval - call class method
271        function [varargout] = eval(this, varargin)
272            %eval - evaluate a gsTHBSplineBasis object
273            %
274            %Usage:
275            %  val = thb.eval( pts )
276            %
277            %Input:
278            %  thb: gsTHBSplineBasis, [1 x 1].
279            %    The gsTHBSplineBasis object.
280            %  pts: double, [d x numPts].
281            %    Points in which to evaluate the gsTHBSplineBasis.
282            %
283            %Output:
284            %  val: double, [numFun x numPts].
285            %    Value of all active functions in each of the specified
286            %    points.
287
288            if (nargin~=2 || nargout>1)
289                error('Invalid number of input and/or output arguments.')
290            end
291            if (~isa(varargin{1},'numeric') || ~ismatrix(varargin{1}) || ~isequal(size(varargin{1},1),this.dim()))
292                error('Input argument no. 1 must be numeric, 2-dimensional, and with d rows.')
293            end
294            [varargout{1:nargout}] = mex_gsTHBSplineBasis('eval', this.objectHandle, varargin{:});
295        end
296
297        % evalSingle - call class method
298        function [varargout] = evalSingle(this, varargin)
299            %evalSingle - evaluate a single function in a gsTHBSplineBasis object
300            %
301            %Usage:
302            %  valSingle = thb.evalSingle( fun, pts )
303            %
304            %Input:
305            %  thb: gsTHBSplineBasis, [1 x 1].
306            %    The gsTHBSplineBasis object.
307            %  fun: double, [1 x 1].
308            %    Index of function to evaluate.
309            %  pts: double, [d x numPts].
310            %    Points in which to evaluate the function.
311            %
312            %Output:
313            %  val: double, [1 x numPts].
314            %    Value of the specified function in each of the specified
315            %    points.
316
317            if (nargin~=3 || nargout>1)
318                error('Invalid number of input and/or output arguments.')
319            end
320            if (~isa(varargin{1},'numeric') || ~isscalar(varargin{1}) || ...
321                    ~(mod(varargin{1},1)==0) || varargin{1}<1)
322                error('Input argument no. 1 must be an strictly positive integer.')
323            elseif (~isa(varargin{2},'numeric') || ~ismatrix(varargin{2}) || ~isequal(size(varargin{2},1),this.dim()))
324                error('Input argument no. 2 must be numeric, 2-dimensional, and with d rows.')
325            end
326            [varargout{1:nargout}] = mex_gsTHBSplineBasis('evalSingle', this.objectHandle, varargin{:});
327        end
328
329        % save - call class method
330        function [varargout] = save(this, varargin)
331            %save - save a gsTHBSplineBasis object as xml object
332            %
333            %Usage:
334            %  thb.save();
335            %
336            %Input:
337            %  thb: gsTHBSplineBasis, [1 x 1].
338            %    The gsTHBSplineBasis object.
339            %
340            %Output:
341            %   (none - saved into an xml file)
342
343            if (nargin~=2)
344                error('Invalid number of input arguments.')
345            end
346            if (~(isa(varargin{1},'char')))
347                error('Input argument no. 1 should be of type ''char''.')
348            end
349            [varargout{1:nargout}] = mex_gsTHBSplineBasis('save', this.objectHandle, varargin{:});
350        end
351
352        % knots - call class method
353        function [varargout] = knots(this, varargin)
354            %knots - returns the knot vector of a gsTHBSplineBasis object
355            %   of the specified level on the specified direction
356            %
357            %Usage:
358            %  knt = thb.knots( lev, dir )
359            %
360            %Input:
361            %  thb: gsTHBSplineBasis, [1 x 1].
362            %    The gsTHBSplineBasis object.
363            %  lev: int, [1 x 1].
364            %    Index of the level of the hierarchy to consider.
365            %  dir: int, [1 x 1].
366            %    index of the direction of space to consider.
367            %
368            %Output:
369            %  knt: double, [1 x numKnots].
370            %    Knot vector corresponding to level lev in the direction
371            %    dir.
372
373            if (nargin~=3 || nargout>1)
374                error('Invalid number of input and/or output arguments.')
375            end
376            if (~isa(varargin{1},'numeric') || ~isscalar(varargin{1}) || ~(mod(varargin{1},1)==0) || varargin{1}<1)
377                error('Input argument no. 1 must be a strictly positive integer.')
378            elseif (~isa(varargin{2},'numeric') || ~isscalar(varargin{2}) || ...
379                    ~(mod(varargin{2},1)==0) || varargin{2}<1 || varargin{2}>this.dim())
380                error('Input argument no. 2 must be a strictly positive integer smaller than %d.', this.dim())
381            end
382            [varargout{1:nargout}] = mex_gsTHBSplineBasis('knots', this.objectHandle, varargin{:});
383        end
384
385        % active - call class method
386        function [varargout] = active(this, varargin)
387            %active - active functions of a gsTHBSplineBasis object
388            %
389            %Usage:
390            %  act = thb.active( pts )
391            %
392            %Input:
393            %  thb: gsTHBSplineBasis, [1 x 1].
394            %    The gsTHBSplineBasis object.
395            %  pts: double, [d x numPts].
396            %    Points in which to evaluate the function.
397            %
398            %Output:
399            %  act: double, [numFun x numPts].
400            %    Index of active functions in each of the specified points.
401
402            if (nargin~=2 || nargout>1)
403                error('Invalid number of input and/or output arguments.')
404            end
405            if (~isa(varargin{1},'numeric') || ~ismatrix(varargin{1}) || ~isequal(size(varargin{1},1),this.dim()))
406                error('Input argument no. 1 must be numeric, 2-dimensional, and with d rows.')
407            end
408            [varargout{1:nargout}] = mex_gsTHBSplineBasis('active', this.objectHandle, varargin{:});
409        end
410
411    end
412end