-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuvis_viewer.m
167 lines (110 loc) · 5.58 KB
/
cuvis_viewer.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
classdef cuvis_viewer < handle
properties
sdk_handle;
end
properties (Access = private)
cleanup;
end
methods (Access = private)
end
methods
function viewerObj = cuvis_viewer(varargin)
cuvis_helper_chklib
viewerObj.sdk_handle=-1;
cargs=[];
viewerObj.cleanup = onCleanup(@()delete(viewerObj));
p = inputParser;
p.KeepUnmatched=false;
%validScalarPosNum = @(x) isnumeric(x) && isscalar(x) && (x > 0);
addParameter(p,'pan_scale',0,@isnumeric);
addParameter(p,'pan_sharpening_interpolation_type','NearestNeighbor',@ischar);
addParameter(p,'pan_sharpening_algorithm','Noop',@ischar);
addParameter(p,'pre_pan_sharpen_cube',false,@islogical);
addParameter(p,'complete',false,@islogical);
addParameter(p,'userplugin',@ischar);
parse(p,varargin{:});
cargs=calllib('cuvis','cuvis_viewer_settings_allocate');
cargs.Value.pan_scale=p.Results.pan_scale;
cargs.Value.pre_pan_sharpen_cube = p.Results.pre_pan_sharpen_cube;
cargs.Value.complete = p.Results.complete;
switch p.Results.pan_sharpening_interpolation_type
case 'NearestNeighbor'
cargs.Value.pan_interpolation_type = 0;
case 'Linear'
cargs.Value.pan_interpolation_type = 1;
case 'Cubic'
cargs.Value.pan_interpolation_type = 2;
case 'Lanczos'
cargs.Value.pan_interpolation_type = 2;
otherwise
error('pan_sharpening_interpolation_type not supported');
end
switch p.Results.pan_sharpening_algorithm
case 'Noop'
cargs.Value.pan_algorithm = 0;
case 'CubertMacroPixel'
cargs.Value.pan_algorithm = 1;
otherwise
error('pan_sharpening_algorithm not supported');
end
ptr = libpointer('cstring', p.Results.userplugin);
viewerPtr = libpointer('int32Ptr',0);
cargs.Value.userplugin = ptr;
[code,viewerObj.sdk_handle]=calllib('cuvis','cuvis_viewer_create', viewerPtr, cargs);
clear viewerPtr;
calllib('cuvis','cuvis_viewer_settings_free',cargs);
clear cargs;
clear ptr;
cuvis_helper_chklasterr(code);
end
function view = apply(viewerObj, mesu)
viewPtr = libpointer('int32Ptr',0);
[code, viewHandle] = calllib('cuvis','cuvis_viewer_apply',viewerObj.sdk_handle, mesu.sdk_handle, viewPtr);
clear viewPtr;
cuvis_helper_chklasterr(code);
dataCntPtr = libpointer('int32Ptr',0);
[code,dataCnt]=calllib('cuvis','cuvis_view_get_data_count',viewHandle,dataCntPtr);
clear dataCntPtr;
cuvis_helper_chklasterr(code);
view = [];
for k=0:dataCnt-1
dataptr = calllib('cuvis','cuvis_view_data_allocate');
[code, view_data] =calllib('cuvis','cuvis_view_get_data',viewHandle, k , dataptr);
calllib('cuvis','cuvis_view_data_free',dataptr);
cuvis_helper_chklasterr(code);
id = deblank(char(view_data.id));
if (strcmp(id,''))
id = ['unnamed_',num2str(k)];
end
switch view_data.category
case 'view_category_image' % data
vtup.category = 'image';
case 'view_category_data' % image
vtup.category = 'data';
end
vtup.show = view_data.show ~= 0;
image = view_data.data;
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
vtup.value = permute(reshape(image.raw.Value,[image.channels image.width image.height]),[3,2,1]);
view.(id) = vtup;
%view.elemetns{k+1} = vtup;
end
calllib('cuvis','cuvis_view_free',viewHandle);
end
function delete(viewerObj)
if viewerObj.sdk_handle>0
calllib('cuvis','cuvis_viewer_free',viewerObj.sdk_handle);
end
end
end
end