-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuvis_measurement.m
364 lines (248 loc) · 13.7 KB
/
cuvis_measurement.m
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
classdef cuvis_measurement < handle
properties
name;
path;
comment;
capture_time;
factory_calibration;
product_name;
serial_number;
assembly;
integration_time;
averages;
sequence_no;
session_no;
sesesion_name;
processing_mode;
measurement_flags;
flags;
capabilites;
data;
sdk_handle;
end
properties (Access = private)
cleanup;
end
methods
function cpyObj = copy(srcObj)
mesuPtr = libpointer('int32Ptr',0);
[code,copy_handle]=calllib('cuvis','cuvis_measurement_deep_copy',srcObj.sdk_handle, mesuPtr );
clear mesuPtr ;
cuvis_helper_chklasterr(code);
cpyObj = cuvis_measurement(copy_handle);
end
function mesuObj=refreshData(mesuObj)
mesuMetaDataPtr = calllib('cuvis','cuvis_mesu_metadata_allocate');
[code,mesu_data]=calllib('cuvis','cuvis_measurement_get_metadata',mesuObj.sdk_handle, mesuMetaDataPtr);
calllib('cuvis','cuvis_mesu_metadata_free',mesuMetaDataPtr);
%clear mesu_data;
clear mesuMetaDataPtr;
cuvis_helper_chklasterr(code);
mesuObj.name = deblank(char(mesu_data.name));
mesuObj.path = deblank(char(mesu_data.path));
mesuObj.comment = deblank(char(mesu_data.comment));
mesuObj.product_name = deblank(char(mesu_data.product_name));
mesuObj.serial_number = deblank(char(mesu_data.serial_number));
mesuObj.assembly = deblank(char(mesu_data.assembly));
mesuObj.sesesion_name = deblank(char(mesu_data.session_info_name));
mesuObj.sequence_no = mesu_data.session_info_sequence_no;
mesuObj.session_no = mesu_data.session_info_session_no;
mesuObj.processing_mode = deblank(char(mesu_data.processing_mode));
mesuObj.capture_time = cuvis_helper_mktime( mesu_data.capture_time);
mesuObj.factory_calibration = cuvis_helper_mktime(mesu_data.factory_calibration);
mesuObj.integration_time = mesu_data.integration_time;
mesuObj.averages = mesu_data.averages;
capaPtr = libpointer('int32Ptr',0);
[code,capa]=calllib('cuvis','cuvis_measurement_get_capabilities', mesuObj.sdk_handle, capaPtr);
clear capaPtr;
cuvis_helper_chklasterr(code);
mesuObj.capabilites = cuvis_load_capabilites(capa);
mesuObj.readflags(mesu_data.measurement_flags);
dataCntPtr = libpointer('int32Ptr',0);
[code,dataCnt]=calllib('cuvis','cuvis_measurement_get_data_count',mesuObj.sdk_handle,dataCntPtr);
clear dataCntPtr;
cuvis_helper_chklasterr(code);
mesuObj.data=[];
for k=0:dataCnt-1
typePtr = libpointer('cuvis_data_type_t',0);
keyStr= libpointer('cstring', repmat(' ',1,256));
[code,key,type]=calllib('cuvis','cuvis_measurement_get_data_info',mesuObj.sdk_handle,keyStr,typePtr,k);
clear typePtr;
clear keyStr;
if (isempty(key))
continue;
end
contentdata=[];
switch type
case 'data_type_image' % image
imbufptr = calllib('cuvis','cuvis_imbuffer_allocate');
[code , ~, image] =calllib('cuvis','cuvis_measurement_get_data_image',mesuObj.sdk_handle, key ,imbufptr);
calllib('cuvis','cuvis_imbuffer_free',imbufptr);
len = image.width * image.height * image.channels;
switch image.format
case 'imbuffer_format_uint8'
setdatatype(image.raw,'uint8Ptr',len);
case 'imbuffer_format_uint16'
setdatatype(image.raw,'uint16Ptr',len);
case 'imbuffer_format_uint32'
setdatatype(image.raw,'uint32Ptr',len);
case 'imbuffer_format_float'
setdatatype(image.raw,'singlePtr',len);
end
if isempty(image.wavelength)
contentdata = permute(reshape(image.raw.Value,[image.channels image.width image.height]),[3,2,1]);
else
contentdata.value = permute(reshape(image.raw.Value,[image.channels image.width image.height]),[3,2,1]);
setdatatype(image.wavelength,'uint32Ptr', image.channels);
contentdata.wl = image.wavelength.Value;
end
case 'data_type_gps' % GPS
gpsPtr = calllib('cuvis','cuvis_gps_allocate');
[code,~,gps]=calllib('cuvis','cuvis_measurement_get_data_gps',mesuObj.sdk_handle,key,gpsPtr);
calllib('cuvis','cuvis_gps_free',gpsPtr);
cuvis_helper_chklasterr(code);
contentdata.longitude = gps.longitude;
contentdata.latitude = gps.latitude;
contentdata.altitude = gps.altitude;
contentdata.time = cuvis_helper_mktime(gps.time);
case 'data_type_string' % string
valueStr= libpointer('cstring', repmat(' ',1,265));
[code,~,value]=calllib('cuvis','cuvis_measurement_get_data_string',mesuObj.sdk_handle,key,valueStr);
clear valueStr;
cuvis_helper_chklasterr(code);
contentdata = value;
case 'data_type_sensor_info' % string
gpsPtr = calllib('cuvis','cuvis_sensor_info_allocate');
[code,~,sinfo]=calllib('cuvis','cuvis_measurement_get_data_sensor_info',mesuObj.sdk_handle,key,gpsPtr);
calllib('cuvis','cuvis_sensor_info_free',gpsPtr);
cuvis_helper_chklasterr(code);
contentdata.averages = sinfo.averages;
contentdata.temperature = sinfo.temperature;
contentdata.gain = sinfo.gain;
contentdata.readout_time = cuvis_helper_mktime(sinfo.readout_time);
contentdata.width = sinfo.width;
contentdata.height = sinfo.height;
contentdata.pixel_format = sinfo.pixel_format
contentdata.binning = sinfo.binning
otherwise
contentdata.key=key;
contentdata.type='unkown';
end
mesuObj.data.(key)= contentdata;
cuvis_helper_chklasterr(code);
end
end
function mesuObj = cuvis_measurement(data)
cuvis_helper_chklib
mesuObj.cleanup = onCleanup(@()delete(mesuObj));
switch class(data)
case 'char'
mesuObj.sdk_handle=-1;
pathStr = libpointer('cstring', data);
mesuPtr = libpointer('int32Ptr',0);
[code,~,mesuObj.sdk_handle]=calllib('cuvis','cuvis_measurement_load',pathStr, mesuPtr);
clear pathStr;
clear mesuPtr;
cuvis_helper_chklasterr(code);
case 'int32'
mesuObj.sdk_handle=data;
otherwise
error('unkown argument type');
end
mesuObj.refreshData();
end
function set_name(mesuObj,name)
cuvis_helper_chklib
nameStr = libpointer('cstring', name);
[code]=calllib('cuvis','cuvis_measurement_set_name', mesuObj.sdk_handle,nameStr);
cuvis_helper_chklasterr(code);
refreshData(mesuObj);
end
function save(mesuObj, path, varargin)
cuvis_helper_chklib
p = inputParser;
p.KeepUnmatched=false;
validScalarPosNum = @(x) isnumeric(x) && isscalar(x) && (x > 0);
addParameter(p,'allow_fragmentation',false,@islogical);
addParameter(p,'allow_overwrite',false,@islogical);
addParameter(p,'allow_drop',false,@islogical);
%addParameter(p,'allow_session_file',true,@islogical);
addParameter(p,'allow_info_file',true,@islogical);
addParameter(p,'operation_mode','Software',@ischar);
addParameter(p,'fps',0.0,@isdouble);
addParameter(p,'soft_limit',20,validScalarPosNum);
addParameter(p,'hard_limit',100,validScalarPosNum);
addParameter(p,'max_buftime',10000,validScalarPosNum);
parse(p,varargin{:});
cargs=calllib('cuvis','cuvis_save_args_allocate');
cargs.Value.allow_fragmentation = p.Results.allow_fragmentation;
cargs.Value.allow_overwrite = p.Results.allow_overwrite;
cargs.Value.allow_drop = p.Results.allow_drop;
cargs.Value.allow_session_file = false;%p.Results.allow_session_file;
cargs.Value.allow_info_file = p.Results.allow_info_file;
if strcmp(p.Results.operation_mode, 'Software')
cargs.Value.operation_mode = 1;
elseif strcmp(p.Results.operation_mode, 'Internal')
cargs.Value.operation_mode = 2;
elseif strcmp(p.Results.operation_mode, 'External')
cargs.Value.operation_mode = 3;
else
cargs.Value.operation_mode = 4;
end
cargs.Value.fps = p.Results.fps;
cargs.Value.soft_limit = p.Results.soft_limit;
cargs.Value.hard_limit = p.Results.hard_limit;
cargs.Value.max_buftime = p.Results.max_buftime;
pathStr = libpointer('cstring', path);
[code]=calllib('cuvis','cuvis_measurement_save', mesuObj.sdk_handle,pathStr, cargs );
calllib('cuvis','cuvis_save_args_free',cargs);
clear cargs;
cuvis_helper_chklasterr(code);
end
function delete(mesuObj)
if (mesuObj.sdk_handle >=0)
calllib('cuvis','cuvis_measurement_free',mesuObj.sdk_handle);
end
end
function readflags(mesuObj,flags)
mesuObj.flags = [];
flagidx = 1;
if bitand(flags,1 )
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_OVERILLUMINATED';
flagidx = flagidx+1;
end
if bitand(flags,2)
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_POOR_REFERENCE';
flagidx = flagidx+1;
end
if bitand(flags,4 )
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_POOR_WHITE_BALANCING';
flagidx = flagidx+1;
end
if bitand(flags,8 )
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_DARK_INTTIME';
flagidx = flagidx+1;
end
if bitand(flags,16 )
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_DARK_TEMP';
flagidx = flagidx+1;
end
if bitand(flags,32)
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_WHITE_INTTIME';
flagidx = flagidx+1;
end
if bitand(flags,64)
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_WHITE_TEMP';
flagidx = flagidx+1;
end
if bitand(flags,128)
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_WHITEDARK_INTTIME';
flagidx = flagidx+1;
end
if bitand(flags,256)
mesuObj.flags{flagidx}='CUBERT_MESU_FLAG_WHITEDARK_TEMP';
flagidx = flagidx+1;
end
end
end
end