Debian Codegraph @

matlab/+ismrmrd/Acquisition.m

raw
1 classdef Acquisition < handle
2
3 properties
4 head = [];
5 traj = {};
6 data = {};
7 end
8
9 methods
10
11 function obj = Acquisition(arg1, traj, data)
12 switch nargin
13 case 0
14 % No argument constructor
15 % initialize to a single acquisition
16 extend(obj,1);
17
18 case 1
19 % One argument constructor
20 if ismrmrd.util.isInt(arg1)
21 % First argument is a number
22 M = arg1;
23 extend(obj,M);
24 elseif isa(arg1,'ismrmrd.AcquisitionHeader')
25 obj.head = arg1;
26 obj.initializeData();
27 else
28 % First argument is a header (hopefully)
29 M = length(arg1.version);
30 obj.head = ismrmrd.AcquisitionHeader(arg1);
31 obj.initializeData();
32 end
33
34 case 3
35 % Three argument constructor
36 obj.head = ismrmrd.AcquisitionHeader(arg1);
37 M = length(arg1.version);
38 if isempty(traj)
39 obj.traj{M} = [];
40 else
41 trajFromFloat(obj,traj);
42 end
43 if isempty(data)
44 obj.data{M} = [];
45 else
46 if isreal(data{1})
47 dataFromFloat(obj,data);
48 else
49 obj.data = data;
50 end
51 end
52
53 otherwise
54 error('ismrmrd.Acquistion constructor, wrong number of arguments.');
55 end
56 end
57
58 function nacq = getNumber(obj)
59 nacq = obj.head.getNumber();
60 end
61
62 function acq = select(obj, range)
63 % Return a copy of a range of acquisitions
64
65 % create an empty acquisition
66 acq = ismrmrd.Acquisition();
67 % Fill the header
68 acq.head = obj.head.select(range);
69 % Fill the trajectory and the data
70 for p = 1:length(range)
71 acq.traj{p} = obj.traj{range(p)};
72 acq.data{p} = obj.data{range(p)};
73 end
74 end
75
76 function append(obj, head, traj, data)
77 Nstart = obj.getNumber + 1;
78 Nend = obj.getNumber + length(head.version);
79 Nrange = Nstart:Nend;
80 obj.head.append(head);
81 if isempty(traj) > 0
82 obj.traj{Nrange} = traj;
83 end
84 if isempty(data) > 0
85 obj.data{Nrange} = data;
86 end
87
88 end
89
90 function extend(obj,N)
91 % Extend with blank head and empty traj and data.
92 if isempty(obj.head)
93 M = N;
94 obj.head = ismrmrd.AcquisitionHeader(N);
95 else
96 M = N+obj.getNumber();
97 obj.head.extend(N);
98 end
99 obj.traj{M} = [];
100 obj.data{M} = [];
101 end
102
103 function dataFromFloat(obj,v)
104 if (isempty(obj.head) || (length(v) ~= length(obj.head.version)))
105 error('Mismatch between size of head and data. Please set head first.');
106 end
107 obj.data = cell(1,length(v));
108 for p = 1:length(v)
109 dims = [obj.head.number_of_samples(p), ...
110 obj.head.active_channels(p)];
111 buff = v{p};
112 obj.data{p} = reshape(buff(1:2:end) + 1j*buff(2:2:end), dims);
113 end
114 end
115
116 function v = dataToFloat(obj)
117 v = cell(1,length(obj.data));
118 for p = 1:length(obj.data)
119 dim = size(obj.data{p});
120 buff = zeros([2*prod(dim),1],'single');
121 buff(1:2:end) = real(reshape(obj.data{p},prod(dim),1));
122 buff(2:2:end) = imag(reshape(obj.data{p},prod(dim),1));
123 v{p} = buff;
124 end
125 end
126
127 function trajFromFloat(obj,v)
128 if (isempty(obj.head) || (length(v) ~= length(obj.head.version)))
129 error('Mismatch between size of head and trajectory. Please set head first.');
130 end
131 obj.traj = cell(1,length(v));
132 for p = 1:length(v)
133 dims = [obj.head.trajectory_dimensions(p), ...
134 obj.head.number_of_samples(p)];
135 obj.traj{p} = reshape(v{p}, dims);
136 end
137 end
138
139 function v = trajToFloat(obj)
140 v = cell(1,length(obj.traj));
141 for p = 1:length(obj.traj)
142 v{p} = single(obj.traj{p});
143 end
144 end
145 end
146
147 methods(Access = private)
148 function initializeData(obj)
149 for k = 1:length(obj.head.version)
150 obj.data{k} = complex(zeros(obj.head.number_of_samples(k),obj.head.active_channels(k),'single'));
151 obj.traj{k} = zeros(obj.head.trajectory_dimensions(k),obj.head.number_of_samples(k),'single');
152 end
153
154 end
155 end
156
157 end