-
Notifications
You must be signed in to change notification settings - Fork 1
/
VikingPlot.m
314 lines (284 loc) · 13.3 KB
/
VikingPlot.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
function VikingPlot( varargin )
disp('');
disp('Version: 1.0.2019.07.26');
disp('');
dbstop if error
%If no arguments passed, print usage
if(nargin == 0)
PrintUsage();
return;
end
%Walk through arguments, setting flags as needed
CellIDs = []; %ID's of cells to render
ShowAll = 0; %Show all structures in database and ignore CellIDs
SaveFrames = 0; %Spin rendering in a circle and save all the frames to disk
HideChildren = 0; %Do not show child structures of structures in CellIDs
HideLabels = 0; %Do not show labels on any structure
HideChildLabels = 0; %Do not show labels on child structures
RenderMode = 1; %How we render the scene:
%0 - Do not render, only write .obj files if requested
%1 - Use default Matlab renderer
%2 - Use OpenGL, faster but lighting isn't as good
IsDebug = false; %Set to true to enable debug mode, single threading
WindowSize = []; %Size of the client window
RenderOrigin = []; %Origin of the rendered volume window
RenderDimensions = []; %Dimensions of the render boundaries
ObjPath = []; %The path to write .obj files to, if not specified .obj files are not written
ColladaPath = []; %The path to write .dae files to, if not specified .dae files are not written
Query = {};
IDFileNames = {};
InvertZ = true;
MinZ = NaN;
MaxZ = NaN;
iNextQuery = 1;
iNextIDFile = 1;
[Server, Port, Database] = IO.Local.ReadConnection('ServerConnection.cfg');
SkipNextArgument = false;
NumThreads = 0;
DefaultAlpha = 1;
ChildScalar = 1.0;
iArg = 1;
while iArg <= nargin
if(SkipNextArgument)
SkipNextArgument = false;
iArg = iArg + 1;
continue;
end
StructureID = str2double(varargin(iArg));
if ~isnan(StructureID)
CellIDs = [CellIDs; StructureID];
iArg = iArg + 1;
continue;
else
if(strcmpi(varargin{iArg},'-SaveFrames') )
SaveFrames = 1;
elseif(strcmpi(varargin{iArg},'-d') || strcmpi(varargin{iArg},'-Database'))
Database = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-v') || strcmpi(varargin{iArg},'-Volume'))
Database = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-s') ||strcmpi(varargin{iArg},'-Server'))
Server = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-e') ||strcmpi(varargin{iArg},'-Endpoint'))
Server = varargin{iArg+1};
if(~IsEndpoint(Server))
disp('-Endpoint parameter must begin with http.');
PrintUsage();
return;
end
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-q') || strcmpi(varargin{iArg},'-Query'))
while iArg+1 <= nargin && ~strncmpi(varargin{iArg+1} ,'-', 1)
Query{iNextQuery} = varargin{iArg+1};
iNextQuery = iNextQuery + 1;
iArg = iArg+1;
end
elseif(strcmpi(varargin{iArg},'-f') || strcmpi(varargin{iArg},'-IDFiles'))
while iArg+1 <= nargin && ~strncmpi(varargin{iArg+1} ,'-', 1)
IDFileNames{iNextIDFile} = varargin{iArg+1};
iNextIDFile = iNextIDFile + 1;
iArg = iArg+1;
end
elseif(strcmpi(varargin{iArg},'-port'))
Port = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-Debug'))
IsDebug = true;
elseif(strcmpi(varargin{iArg},'-Threads'))
NumThreads = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-h') || strcmpi(varargin{iArg},'-HideChildren') )
HideChildren = 1;
elseif(strcmpi(varargin{iArg},'-HideLabels') )
HideLabels = 1;
elseif(strcmpi(varargin{iArg},'-ShowChildLabels') )
HideChildLabels = 1;
elseif(strcmpi(varargin{iArg},'-ScaleChildren') )
ChildScalar = str2num(varargin{iArg+1});
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-RenderMode') )
RenderMode = str2num(varargin{iArg+1});
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-WindowSize') )
WindowSize = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-Origin') )
RenderOrigin = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-Dimension') )
RenderDimensions = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-Dims') )
RenderDimensions = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-DefaultAlpha'))
DefaultAlpha = str2num(varargin{iArg+1});
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-ObjPath') )
ObjPath = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-ColladaPath') )
ColladaPath = varargin{iArg+1};
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-z'))
InvertZ = false;
elseif(strcmpi(varargin{iArg},'-InvertZ'))
InvertZ = false;
elseif(strcmpi(varargin{iArg},'-MinZ') )
MinZ = str2num(varargin{iArg+1});
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg},'-MaxZ') )
MaxZ = str2num(varargin{iArg+1});
SkipNextArgument = true;
elseif(strcmpi(varargin{iArg}, '-All'))
ShowAll = 1;
if(~isempty(CellIDs))
disp('Both -All and specific IDs where specified. Mutally exclusive options');
PrintUsage();
return;
end
else
disp(['Unknown argument: ' varargin(iArg)]);
PrintUsage();
return;
end
iArg = iArg + 1;
end
end
%VIKINGPLOT is passed a string of numbers seperated by spaces, each number
%is the number of a cell in the database. Options are -save and -children
%Read the ID Files
if ~isempty(IDFileNames)
endpoint = [];
if IsEndpoint(Server)
endpoint = [Server '/' Database '/OData'];
end
for iFile = 1:length(IDFileNames)
IDsFromFiles = IO.Local.ReadIDsFromFile(IDFileNames{iFile}, endpoint);
IDsFromFiles = sort(IDsFromFiles);
disp(['Loaded IDs from file ' IDFileNames{iFile}]);
disp(num2str(IDsFromFiles'));
CellIDs = vertcat(CellIDs, IDsFromFiles);
end
end
if(ShowAll)
CellIDs =[];
if IsEndpoint(Server)
Query{iNextQuery} = 'Structures?$filter=TypeID eq 1&$select=ID';
iNextQuery = iNextQuery + 1;
end
end
if(IsEndpoint(Server))
endpoint = [Server '/' Database '/OData'];
disp(['Querying OData server: ' endpoint]);
if(~isempty(Query))
for iQuery = 1:length(Query)
[QueryResults, query_url] = QueryODataIDs(endpoint, Query{iQuery});
QueryResults = sort(QueryResults');
disp(['Query results for ' query_url]);
disp(num2str(QueryResults));
CellIDs = [CellIDs; QueryODataIDs(endpoint, Query{iQuery})];
end
end
scale = IO.OData.FetchODataScale(endpoint);
CellIDs = unique(CellIDs);
[Structs, Locs, LocLinks] = IO.OData.FetchOData(endpoint, CellIDs, ~HideChildren);
else
scale = IO.DB.FetchScale(Server, Port, Database);
CellIDs = unique(CellIDs);
[Structs, Locs, LocLinks] = IO.DB.FetchData(Server, Port, Database, CellIDs);
end
if(isempty(Structs))
disp(['No structure data returned by server']);
return
end
if(isempty(Locs))
disp(['No location data returned by server']);
return
end
if(isempty(WindowSize))
PPlot2(Structs, Locs, LocLinks, scale, Database, ...
'SaveFrames', SaveFrames, ...
'HideChildren', HideChildren, ...
'HideLabels', HideLabels, ...
'ShowChildLabels', HideChildLabels, ...
'RenderMode', RenderMode, ...
'Debug', IsDebug, ...
'ObjPath', ObjPath, ...
'ScaleChildren', ChildScalar,...
'DefaultAlpha', DefaultAlpha,...
'ColladaPath', ColladaPath, ...
'InvertZ', InvertZ, ...
'MinZ', MinZ, ...
'MaxZ', MaxZ);
else
PPlot2(Structs, Locs, LocLinks, scale, Database, ...
'SaveFrames', SaveFrames, ...
'HideChildren', HideChildren, ...
'HideLabels', HideLabels, ...
'ShowChildLabels', HideChildLabels, ...
'RenderMode', RenderMode, ...
'ObjPath', ObjPath, ...
'ScaleChildren', ChildScalar,...
'DefaultAlpha', DefaultAlpha,...
'Debug', IsDebug, ...
'WindowSize', WindowSize, ...
'ColladaPath', ColladaPath, ...
'InvertZ', InvertZ, ...
'MinZ', MinZ, ...
'MaxZ', MaxZ);
end
end
function PrintUsage()
disp('Usage: VikingPlot [-SaveFrames] [-HideChildren] [-RenderMode 0|1|2] [-ObjPath <path>] [-All] [ID_1 ID_2 ... ID_N]');
disp('OData use:');
disp(' -Endpoint, -e OData service to connect to. Must begin with "http".');
disp(' -Volume, -v Volume name on OData service');
disp(' -Query, -q Query for OData service, must return array of IDs or Structures.');
disp(' Multiple queries can be passed, either delimited by spaces or each');
disp(' proceeded by a -Query flag.');
disp('');
disp('Database use:');
disp(' -Server, -s Server to connect to');
disp(' -Port Port to connect to, default 1433');
disp(' -Database, -d Datbase name to connect to');
disp('');
disp('General options');
disp(' ID_N Any numbers, seperated by spaces, indicate structure IDs');
disp(' VikingPlot should render');
disp('');
disp(' -All Render all structures in the database.');
disp(' -ColladaPath Export a .dae file for import into other 3D environments');
disp(' -DefaultAlpha The default value for how transparent objects are.');
disp(' All alphaoperations require the use of "-rendermode 2".');
disp(' 1.0 is opaque, 0 is transparent');
disp(' -Dimensions Dimensions of the rendered volume. If not specified Matlab');
disp(' sets this value.');
disp(' -HideChildren Show child structures of the specified IDs');
disp(' -HideLabels Do not label any structure');
disp(' -IDFiles, -f Load structure IDs from one or more text files, one ID per line.');
disp(' Multiple filenames can be passed, either delimited by spaces or each');
disp(' proceeded by a -IDFiles flag.');
disp(' -InvertZ Flip the Z axis.');
disp(' -MinZ Do not render locations on section numbers below this Z value.');
disp(' -MaxZ Do not render locations on section numbers above this Z value.');
disp(' -ObjPath Export an .obj file for import into other 3D environments.');
disp(' -Origin Origin of the rendered volume. Set this to do multiple');
disp(' renderings with cells in the same relative positions. If');
disp(' not specified Matlab sets this value.');
disp(' -RenderMode How should VikingPlot render the data:');
disp(' 0: Do not render. Used to save .obj files.');
disp(' 1: Use default Matlab renderer. Required if saving frames');
disp(' 2: Use OpenGL hardware rendering for faster manipulation');
disp(' but poorer lighting quality.');
disp(' -SaveFrames Save a set of frames to create a movie spinning around');
disp(' the subject');
disp(' -ShowChildLabels Show labels for child structures');
disp(' -Threads Number of threads to use for preparing model');
disp(' -WindowSize The size of the window in pixels to display, useful to');
disp(' -Z Invert the Z coordinates.');
disp('');
return;
end