-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuff.m
More file actions
209 lines (187 loc) · 7.46 KB
/
uff.m
File metadata and controls
209 lines (187 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
classdef uff < handle
%UFF Ultrasound File Format (UFF) superclass
%
% See also CHANNEL_DATA, BEAMFORMED_DATA
% authors: Alfonso Rodriguez-Molares <alfonso.r.molares@ntnu.no>
%
% $Last updated: 2017/08/07$
%% Logistics parameters
properties (Access = public)
name={} % name of the dataset
reference={} % reference to the publication where it was used/acquired
author={} % contact of the authors
version={} % version of the dataset
info={} % other information
end
%% Protected
properties (Access = protected)
last_hash
end
%% constructor
methods (Access = public)
function h=uff(varargin)
%UFF Constructor of UFF class
%
% Syntax:
% h = uff(varaguin)
%
% See also UFF.CHANNEL_DATA, UFF.BEAMFORMED_DATA
if nargin==1 && ~isempty(varargin)
% copy
h.copy(varargin{1});
elseif nargin>1
eval(['mco = ?' class(h) ';']);
plist = mco.PropertyList;
% varagin
for n=1:2:(2*floor(nargin/2))
found=false;
for m=1:length(plist)
if strcmp(plist(m).Name,varargin{n})
h.(plist(m).Name)=varargin{n+1};
found=true;
continue;
end
end
if ~found warning(sprintf('Parameter %s not in %s',varargin{n},class(h))); end
end
end
end
end
%% copy
methods (Access = public)
function copy(h,object)
%COPY Copy the values from another channel_data
%
% Syntax:
% COPY(object)
% object Instance of a channel_data class
%
% See also SCAN, WAVE, SOURCE
assert(isa(object,class(h)),'Class of the input object is not identical');
% we copy all non-dependent & public properties
list_properties=properties(object);
for n=1:numel(list_properties)
property_name=list_properties{n};
mp = findprop(h,property_name);
if strcmp(mp.GetAccess,'public')&&~mp.Dependent
eval(sprintf('h.%s = object.%s;',property_name,property_name));
end
end
end
end
%% HASH tools
methods
function out = hash(h)
% HASH Gives hash for all the non-dependent & public properties
% loop over all non-dependent & public properties
str=[];
list_properties=properties(h);
for n=1:numel(list_properties)
property_name=list_properties{n};
mp = findprop(h,property_name);
if strcmp(mp.GetAccess,'public')&&~mp.Dependent
%fprintf(1,'%s -> %s\n',property_name,tools.hash(h.(property_name)));
if isa(h.(property_name),'uff')
for ne=1:numel(h.(property_name))
str = [ str; h.(property_name)(ne).hash()];
end
elseif isa(h.(property_name),'uff.window')||isa(h.(property_name),'dimension')||isa(h.(property_name),'code')||isa(h.(property_name),'uff.wavefront')
str=[str;tools.hash(char(h.(property_name)))];
else
str=[str;tools.hash(h.(property_name))];
end
end
end
out=tools.hash(str);
end
function h=save_hash(h)
h.last_hash=h.hash();
end
function equal=check_hash(h)
if isempty(h.last_hash) equal=false;
else
equal=strcmp(h.hash(),h.last_hash);
if equal
fprintf('%s: Inputs and outputs are unchanged. Skipping process.\n',class(h));
end
end
end
end
%% Public UFF file write/read
methods (Access = public)
function write(h, filename, name, location, verbose)
%% WRITE Writes object into location
%
% This UFF method writes the object into the specified location
% with the provided name.
%
% UFF_OBJECT.WRITE(filename,name,location,verbose)
%
% Parameters:
% filename Name and path to the UFF file
% name Name of the object within the file
% location Location within the UFF file
% verbose Flag to get text messages
%
% Example:
% channel_data = uff.channel_data();
% channel_data.write('test.uff');
%
% See also UFF.READ, UFF.INDEX
if nargin<3||isempty(name) name=evalin('caller','inputname(1)'); end
if nargin<4 location=[]; end
if nargin<5||isempty(verbose) verbose=true; end
% we are good to write the object
uff.write_object(filename, h, name, location, verbose);
end
function read(h, filename, location, verbose)
%% READ Reads object from location
%
% This UFF method read the UFF object from the specified location
% with the provided name.
%
% UFF_OBJECT.READ(filename, location, verbose)
%
% Parameters:
% filename Name and path to the UFF file
% location Location within the UFF file
% verbose Flag to get text messages
%
% Example:
% channel_data = uff.channel_data();
% channel_data.read('test.uff','/channel_data');
%
% See also UFF.WRITE, UFF.INDEX
if nargin<4 verbose=true; end
object=uff.read_object(filename, location, verbose);
if numel(object)==1 h.copy(object);
else
error('UFF: Trying to copy an array of objects into an UFF class. Use intead: a = uff().read(filename,location)');
end
end
end
%% display methods
methods
function print_authorship(h)
out_name = textwrap([],h.name,50);
fprintf('Name: \t\t %s \n',out_name{1});
for i = 2:numel(out_name)
fprintf('\t\t %s \n',out_name{i});
end
out_reference = textwrap([],h.reference,50);
fprintf('Reference: \t %s \n',out_reference{1});
for i = 2:numel(out_reference)
fprintf('\t\t %s \n',out_reference{i});
end
fprintf('Author(s): ');
for i = 1:numel(h.author)
if i == 1
fprintf('\t %s \n',h.author{i});
else
fprintf('\t\t %s \n',h.author{i});
end
end
fprintf('Version: \t %s \n',h.version{:});
end
end
end