-
Notifications
You must be signed in to change notification settings - Fork 0
/
OryxCameraSettings.cs
480 lines (415 loc) · 17 KB
/
OryxCameraSettings.cs
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SpinnakerNET;
using SpinnakerNET.GenApi;
using Emgu.CV;
using Emgu.CV.UI;
using System.Windows.Forms;
using Emgu.CV.Structure;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Globalization;
using System.IO;
namespace FetchRig3
{
public class OryxCameraSettings
{
private OryxCamera cam;
private Dictionary<Util.OryxSettingName, Util.SettingInfo> settingsToLoad;
private const int MAXCHARS = 35;
public OryxCameraSettings(OryxCamera cam)
{
this.cam = cam;
settingsToLoad = cam.setupInfo.settingsToLoad;
foreach (KeyValuePair<Util.OryxSettingName, Util.SettingInfo> entry in settingsToLoad)
{
SetSetting(entry.Value);
}
EnableChunkData();
}
public void EnableChunkData()
{
cam.managedCamera.ChunkSelector.Value = ChunkSelectorEnums.Timestamp.ToString();
cam.managedCamera.ChunkEnable.Value = true;
cam.managedCamera.ChunkModeActive.Value = true;
cam.managedCamera.ChunkSelector.Value = ChunkSelectorEnums.FrameID.ToString();
cam.managedCamera.ChunkEnable.Value = true;
cam.managedCamera.ChunkModeActive.Value = true;
}
private void SetSetting(Util.SettingInfo item)
{
string settingName = item._SettingName.ToString();
Util.NodeType nodeType = item._NodeType;
Util.NodeMap nodeMap = item._NodeMap;
string value = item._Value;
if (nodeType == Util.NodeType.String)
{
IString iNode = null;
if (nodeMap == Util.NodeMap.GenICam)
{
iNode = cam.nodeMap.GetNode<IString>(settingName);
}
else if (nodeMap == Util.NodeMap.TLDevice)
{
iNode = cam.nodeMapTLDevice.GetNode<IString>(settingName);
}
else if (nodeMap == Util.NodeMap.TLStream)
{
iNode = cam.nodeMapTLStream.GetNode<IString>(settingName);
}
string currentValue = string.Copy(iNode.Value.ToString());
iNode.Value = value;
string newValue = string.Copy(iNode.Value.ToString());
printSettingChangeInfo(currentValue, newValue);
}
else if (nodeType == Util.NodeType.Integer)
{
IInteger iNode = null;
if (nodeMap == Util.NodeMap.GenICam)
{
iNode = cam.nodeMap.GetNode<IInteger>(settingName);
}
else if (nodeMap == Util.NodeMap.TLDevice)
{
iNode = cam.nodeMapTLDevice.GetNode<IInteger>(settingName);
}
else if (nodeMap == Util.NodeMap.TLStream)
{
iNode = cam.nodeMapTLStream.GetNode<IInteger>(settingName);
}
string currentValue = string.Copy(iNode.Value.ToString());
iNode.Value = int.Parse(value);
string newValue = string.Copy(iNode.Value.ToString());
printSettingChangeInfo(currentValue, newValue);
}
else if (nodeType == Util.NodeType.Float)
{
IFloat iNode = null;
if (nodeMap == Util.NodeMap.GenICam)
{
iNode = cam.nodeMap.GetNode<IFloat>(settingName);
}
else if (nodeMap == Util.NodeMap.TLDevice)
{
iNode = cam.nodeMapTLDevice.GetNode<IFloat>(settingName);
}
else if (nodeMap == Util.NodeMap.TLStream)
{
iNode = cam.nodeMapTLStream.GetNode<IFloat>(settingName);
}
string currentValue = string.Copy(iNode.Value.ToString());
iNode.Value = float.Parse(value, CultureInfo.InvariantCulture.NumberFormat);
string newValue = string.Copy(iNode.Value.ToString());
printSettingChangeInfo(currentValue, newValue);
}
else if (nodeType == Util.NodeType.Bool)
{
IBool iNode = null;
if (nodeMap == Util.NodeMap.GenICam)
{
iNode = cam.nodeMap.GetNode<IBool>(settingName);
}
else if (nodeMap == Util.NodeMap.TLDevice)
{
iNode = cam.nodeMapTLDevice.GetNode<IBool>(settingName);
}
else if (nodeMap == Util.NodeMap.TLStream)
{
iNode = cam.nodeMapTLStream.GetNode<IBool>(settingName);
}
string currentValue = string.Copy(iNode.Value.ToString());
iNode.Value = bool.Parse(value);
string newValue = string.Copy(iNode.Value.ToString());
printSettingChangeInfo(currentValue, newValue);
}
else if (nodeType == Util.NodeType.Command)
{
ICommand iNode = null;
if (nodeMap == Util.NodeMap.GenICam)
{
iNode = cam.nodeMap.GetNode<ICommand>(settingName);
}
else if (nodeMap == Util.NodeMap.TLDevice)
{
iNode = cam.nodeMapTLDevice.GetNode<ICommand>(settingName);
}
else if (nodeMap == Util.NodeMap.TLStream)
{
iNode = cam.nodeMapTLStream.GetNode<ICommand>(settingName);
}
Console.WriteLine("Command to be executed: {0}: ", settingName);
iNode.Execute();
}
else if (nodeType == Util.NodeType.Enumeration)
{
IEnum iNode = null;
if (nodeMap == Util.NodeMap.GenICam)
{
iNode = cam.nodeMap.GetNode<IEnum>(settingName);
}
else if (nodeMap == Util.NodeMap.TLDevice)
{
iNode = cam.nodeMapTLDevice.GetNode<IEnum>(settingName);
}
else if (nodeMap == Util.NodeMap.TLStream)
{
iNode = cam.nodeMapTLStream.GetNode<IEnum>(settingName);
}
string currentValue = string.Copy(iNode.Value);
IEnumEntry iEntry = iNode.GetEntryByName(value);
iNode.Value = iEntry.Symbolic;
string newValue = string.Copy(iEntry.Symbolic);
printSettingChangeInfo(currentValue, newValue);
}
void printSettingChangeInfo(string _currentValue, string _newValue, bool suppress=true)
{
if (!suppress)
{
Console.WriteLine("{0} ({1}) changed from {2} to {3}", settingName, nodeType, _currentValue, _newValue);
}
}
}
string Indent(int level)
{
StringBuilder sb = new StringBuilder("");
for (int i = 0; i < level; i++)
{
sb.Append(" ");
}
return sb.ToString();
}
// Retrieve display name and value of string node.
private void PrintStringNode(INode node, int level, StreamWriter sw)
{
try
{
// Cast as string node
IString iStringNode = (IString)node;
// Retrieve display name
string displayName = iStringNode.DisplayName;
// Retrieve string node value
string value = iStringNode.Value;
// Check length is not excessive for printing
if (value.Length > MAXCHARS)
{
value = value.Substring(0, MAXCHARS) + "...";
}
sw.WriteLine(Indent(level) + displayName + ": " + value + " (String Node)");
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
private void PrintIntegerNode(INode node, int level, StreamWriter sw)
{
try
{
// Cast node as integer node
IInteger iIntegerNode = (IInteger)node;
// Retrieve display name
string displayName = iIntegerNode.DisplayName;
// Retrieve integer node value
long value = iIntegerNode.Value;
sw.WriteLine(Indent(level) + displayName + ": " + value.ToString() + " (Integer Node)");
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
private void PrintFloatNode(INode node, int level, StreamWriter sw)
{
try
{
// Cast node as integer node
IFloat iFloatNode = (IFloat)node;
// Retrieve display name
string displayName = iFloatNode.DisplayName;
// Retrieve integer node value
double value = iFloatNode.Value;
sw.WriteLine(Indent(level) + displayName + ": " + value.ToString() + " (Float Node)");
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
private void PrintBooleanNode(INode node, int level, StreamWriter sw)
{
try
{
// Cast as boolean node
IBool iBooleanNode = (IBool)node;
// Retrieve display name
string displayName = iBooleanNode.DisplayName;
// Retrieve value as a string representation
string value = (iBooleanNode.Value ? "true" : "false");
sw.WriteLine(Indent(level) + displayName + ": " + value + " (Bool Node)");
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
private void PrintCommandNode(INode node, int level, StreamWriter sw)
{
try
{
// Cast as command node
ICommand iCommandNode = (ICommand)node;
// Retrieve display name
string displayName = iCommandNode.DisplayName;
// Retrieve tooltip
string tooltip = iCommandNode.ToolTip;
// Ensure that the value length is not excessive for printing
if (tooltip.Length > MAXCHARS)
{
tooltip = tooltip.Substring(0, MAXCHARS) + "...";
}
sw.WriteLine(Indent(level) + displayName + ": " + tooltip + " (Command Node)");
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
private void PrintEnumerationNodeAndCurrentEntry(INode node, int level, StreamWriter sw)
{
try
{
// Cast as enumeration node
IEnum iEnumerationNode = (IEnum)node;
// Retrieve current entry as enumeration node
EnumValue iEnumEntryValue = iEnumerationNode.Value;
// Retrieve display name
string displayName = iEnumerationNode.DisplayName;
// Retrieve current symbolic
string currentEntrySymbolic = iEnumEntryValue.String;
sw.WriteLine(Indent(level) + displayName + ": " + currentEntrySymbolic + " (Enumeration Node)");
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
private void PrintCategoryNodeAndAllFeatures(INode node, int level, StreamWriter sw)
{
try
{
// Cast as category node
ICategory iCategoryNode = (ICategory)node;
// Retrieve display name
string displayName = iCategoryNode.DisplayName;
sw.WriteLine(Indent(level) + displayName + " (Category Node)");
// Retrieve children
//
// *** NOTES ***
// The two nodes that typically have children are category nodes
// and enumeration nodes. Throughout the examples, the children
// of category nodes are referred to as features while the
// children of enumeration nodes are referred to as entries.
// Keep in mind that enumeration nodes can be cast as category
// nodes, but category nodes cannot be cast as enumerations.
//
INode[] features = iCategoryNode.Features;
// Iterate through all children
foreach (INode iFeatureNode in features)
{
// Ensure node is available and readable
if (!iFeatureNode.IsAvailable || !iFeatureNode.IsReadable)
{
continue;
}
// Category nodes must be dealt with separately in order to
// retrieve subnodes recursively.
if (iFeatureNode.GetType() == typeof(Category))
{
PrintCategoryNodeAndAllFeatures(iFeatureNode, level + 1, sw);
}
else if (iFeatureNode.GetType() == typeof(StringReg))
{
PrintStringNode(iFeatureNode, level + 1, sw);
}
else if (iFeatureNode.GetType() == typeof(Integer))
{
PrintIntegerNode(iFeatureNode, level + 1, sw);
}
else if (iFeatureNode.GetType() == typeof(Float))
{
PrintFloatNode(iFeatureNode, level + 1, sw);
}
else if (iFeatureNode.GetType() == typeof(BoolNode))
{
PrintBooleanNode(iFeatureNode, level + 1, sw);
}
else if (iFeatureNode.GetType() == typeof(Command))
{
PrintCommandNode(iFeatureNode, level + 1, sw);
}
else if (iFeatureNode.GetType() == typeof(Enumeration))
{
PrintEnumerationNodeAndCurrentEntry(iFeatureNode, level + 1, sw);
}
}
sw.WriteLine();
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
public void SaveSettings(bool _printSettings = false)
{
try
{
// Check if file already exists. If yes, delete it.
if (File.Exists(cam.settingsFileName))
{
File.Delete(cam.settingsFileName);
}
// Create a new file.
using (StreamWriter sw = File.CreateText(cam.settingsFileName))
{
int level = 0;
try
{
sw.WriteLine("\n*** TRANSPORT LAYER DEVICE NODEMAP ***\n");
PrintCategoryNodeAndAllFeatures(cam.nodeMapTLDevice.GetNode<ICategory>("Root"), level, sw);
sw.WriteLine("\n*** TRANSPORT LAYER STREAM NODEMAP ***\n");
PrintCategoryNodeAndAllFeatures(cam.nodeMapTLStream.GetNode<ICategory>("Root"), level, sw);
sw.WriteLine("\n*** GENICAM NODEMAP ***\n");
PrintCategoryNodeAndAllFeatures(cam.nodeMap.GetNode<ICategory>("Root"), level, sw);
}
catch (SpinnakerException ex)
{
Console.WriteLine("Error: {0}", ex.ToString());
}
}
// Write file contents on console if desired.
if (_printSettings)
{
using (StreamReader sr = File.OpenText(cam.settingsFileName))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}