Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/rotate.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % ROTATE applies rotation factor to AOs | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: ROTATE applies rotation factor to AOs | |
5 % | |
6 % CALL: m = rotate(x, y, pl) | |
7 % m = rotate(x, y, ang) | |
8 % | |
9 % INPUTS: x - analysis object | |
10 % y - analysis object | |
11 % pl - parameter list | |
12 % ang - rotation angle as cdata AO or double | |
13 % | |
14 % Please notice that a positive rotation angle means rotating counterclockwise | |
15 % if we use the standard right-handed coordinate system, where x axis goes to | |
16 % the right and where y axis goes up. | |
17 % | |
18 % OUTPUTS: m - 2x1 aos vector with rotated data [xr;yr] | |
19 % | |
20 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'rotate')">Parameters Description</a> | |
21 % | |
22 % VERSION: $Id: rotate.m,v 1.10 2011/04/08 08:56:16 hewitson Exp $ | |
23 % | |
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
25 | |
26 function varargout = rotate(varargin) | |
27 | |
28 % check if this is a call for parameters | |
29 if utils.helper.isinfocall(varargin{:}) | |
30 varargout{1} = getInfo(varargin{3}); | |
31 return | |
32 end | |
33 | |
34 import utils.const.* | |
35 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
36 | |
37 % collect input variable names | |
38 in_names = cell(size(varargin)); | |
39 for ii = 1:nargin,in_names{ii} = inputname(ii); end | |
40 | |
41 % collect all AOs and plists | |
42 [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
43 [pli, invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names); | |
44 | |
45 if nargout == 0 | |
46 error('### ao/rotate can not be used as a modifier method. Please give at least one output'); | |
47 end | |
48 | |
49 % combine plists | |
50 pl = combine(pli, getDefaultPlist()); | |
51 | |
52 % make copies of inputs | |
53 bs = copy(as, true); | |
54 | |
55 % collect input histories | |
56 inhists = copy([as.hist], true); | |
57 | |
58 % check number of input AO | |
59 switch numel(as) | |
60 case 2 | |
61 % exctracts info about the rotation angle from the plist | |
62 ang = mfind(pl, 'angle', 'ang'); | |
63 | |
64 if isa(ang, 'ao') | |
65 % extract value | |
66 ang = ang.y; | |
67 else | |
68 % look in rest | |
69 if ang == 0 && ~isempty(rest) | |
70 ang = rest{1}; | |
71 % store angle into the plist to add it to history | |
72 pl.pset('ang', ang); | |
73 end | |
74 end | |
75 | |
76 case 3 | |
77 % exctracts rotation angle from input AO | |
78 ang = as(3).y; | |
79 % remove angle parameter from the plist | |
80 pl.remove('ang'); | |
81 | |
82 otherwise | |
83 error('### wrong number of input AOs. rotate works on two AOs or on three AOs where the third is the rotation angle') | |
84 end | |
85 | |
86 % check that ang is a number | |
87 if isempty(ang) || ~isnumeric(ang) || numel(ang) ~= 1 | |
88 error('### rotation angle must be scalar value'); | |
89 end | |
90 | |
91 % construct rotation matrix | |
92 m = [ cos(ang) -sin(ang) | |
93 sin(ang) cos(ang) ]; | |
94 | |
95 % arrange input values into a column vector | |
96 xy = [ transpose(as(1).y); transpose(as(2).y) ]; | |
97 | |
98 % apply the rotation matrix | |
99 xyr = m * xy; | |
100 | |
101 % set output values | |
102 bs(1).data.y = xyr(1,:); | |
103 bs(2).data.y = xyr(2,:); | |
104 | |
105 for jj = 1:2 | |
106 % set name | |
107 bs(jj).setName(sprintf('rotate(%s, %s)', ao_invars{1}, ao_invars{2})); | |
108 | |
109 % update history | |
110 bs(jj).addHistory(getInfo('None'), pl, ao_invars, inhists); | |
111 | |
112 end | |
113 | |
114 % assign output | |
115 varargout{1} = bs; | |
116 | |
117 end | |
118 | |
119 %-------------------------------------------------------------------------- | |
120 % Get Info Object | |
121 %-------------------------------------------------------------------------- | |
122 function ii = getInfo(varargin) | |
123 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
124 sets = {}; | |
125 pls = []; | |
126 else | |
127 sets = {'Default'}; | |
128 pls = getDefaultPlist; | |
129 end | |
130 % build info object | |
131 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.op, '$Id: rotate.m,v 1.10 2011/04/08 08:56:16 hewitson Exp $', sets, pls); | |
132 ii.setArgsmin(2); | |
133 ii.setOutmin(2); | |
134 end | |
135 | |
136 %-------------------------------------------------------------------------- | |
137 % Get Default Plist | |
138 %-------------------------------------------------------------------------- | |
139 function plout = getDefaultPlist() | |
140 persistent pl; | |
141 if exist('pl', 'var')==0 || isempty(pl) | |
142 pl = buildplist(); | |
143 end | |
144 plout = pl; | |
145 end | |
146 | |
147 function pl = buildplist() | |
148 pl = plist(); | |
149 p = param({'ang', 'The angle to rotate by. It can be a double or an AO.'}, paramValue.DOUBLE_VALUE(0)); | |
150 pl.append(p); | |
151 end |