Mercurial > repos > public > sbplib
comparison +grid/Cartesian.m @ 168:ba1ae5b2c45e feature/grids
grid.Cartesian: Added methods and test to fulfilll abstract class.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 24 Feb 2016 15:01:54 +0100 |
parents | ce10ebde3123 |
children | f7bb2a94d291 |
comparison
equal
deleted
inserted
replaced
167:15baeb35f74e | 168:ba1ae5b2c45e |
---|---|
27 end | 27 end |
28 | 28 |
29 % d returns the spatial dimension of the grid | 29 % d returns the spatial dimension of the grid |
30 function o = D(obj) | 30 function o = D(obj) |
31 o = obj.d; | 31 o = obj.d; |
32 end | |
33 | |
34 function m = size(obj) | |
35 m = obj.m; | |
32 end | 36 end |
33 | 37 |
34 % points returns a n x d matrix containing the coordianets for all points. | 38 % points returns a n x d matrix containing the coordianets for all points. |
35 % points are ordered according to the kronecker product with X*Y*Z | 39 % points are ordered according to the kronecker product with X*Y*Z |
36 function X = points(obj) | 40 function X = points(obj) |
69 s = obj.m; | 73 s = obj.m; |
70 s(i) = 1; | 74 s(i) = 1; |
71 X{i} = repmat(t,s); | 75 X{i} = repmat(t,s); |
72 end | 76 end |
73 end | 77 end |
78 | |
79 % Restricts the grid function gf on obj to the subgrid g. | |
80 % Only works for even multiples | |
81 function gf = restrictFunc(obj, gf, g) | |
82 m1 = obj.m; | |
83 m2 = g.m; | |
84 | |
85 % Check the input | |
86 if prod(m1) ~= numel(gf) | |
87 error('grid:Cartesian:restrictFunc:NonMatchingFunctionSize', 'The grid function has to few or too many points.'); | |
88 end | |
89 | |
90 if ~all(mod(m1-1,m2-1) == 0) | |
91 error('grid:Cartesian:restrictFunc:NonMatchingGrids', 'Only integer downsamplings are allowed'); | |
92 end | |
93 | |
94 % Calculate stride for each dimension | |
95 stride = (m1-1)./(m2-1); | |
96 | |
97 % Create downsampling indecies | |
98 I = {}; | |
99 for i = 1:length(m1) | |
100 I{i} = 1:stride(i):m1(i); | |
101 end | |
102 | |
103 gf = reshapeRowMaj(gf, m1); | |
104 gf = gf(I{:}); | |
105 gf = reshapeRowMaj(gf, prod(m2)); | |
106 end | |
107 | |
108 % Projects the grid function gf on obj to the grid g. | |
109 function gf = projectFunc(obj, gf, g) | |
110 error('grid:Cartesian:NotImplemented') | |
111 end | |
74 end | 112 end |
75 end | 113 end |