forked from edennz/artoolkit6-calibration
-
Notifications
You must be signed in to change notification settings - Fork 3
/
prefsLibConfig.cpp
586 lines (537 loc) · 27.2 KB
/
prefsLibConfig.cpp
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
/*
* prefsLibConfig.cpp
* artoolkitX
*
* This file is part of artoolkitX.
*
* artoolkitX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* artoolkitX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with artoolkitX. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent modules, and to
* copy and distribute the resulting executable under terms of your choice,
* provided that you also meet, for each linked independent module, the terms and
* conditions of the license of that module. An independent module is a module
* which is neither derived from nor based on this library. If you modify this
* library, you may extend this exception to your version of the library, but you
* are not obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Copyright 2018 Realmax, Inc.
* Copyright 2017-2017 Daqri LLC. All Rights Reserved.
*
* Author(s): Philip Lamb
*
*/
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <ARX/AR/ar.h>
#if ARX_TARGET_PLATFORM_LINUX
#include <stdio.h>
#include "prefs.hpp"
#include <libconfig.h>
#include <Eden/EdenMessage.h>
#include <pthread.h>
#include <ARX/ARVideo/video.h>
#include "flow.hpp"
#include <ARX/ARUtil/file_utils.h>
#include "calib_camera.h"
#define PREFS_FILENAME "prefs"
typedef struct {
char *prefsPath;
config_t config;
config_setting_t *settingCOT;
config_setting_t *settingCalibrationSave;
config_setting_t *settingCalibSaveDir;
config_setting_t *settingCalibrationUpload;
config_setting_t *settingCSUU;
config_setting_t *settingCSAT;
config_setting_t *settingCalibrationPatternType;
config_setting_t *settingCalibrationPatternSizeWidth;
config_setting_t *settingCalibrationPatternSizeHeight;
config_setting_t *settingCalibrationPatternSpacing;
} prefsLibConfig_t;
static const char *kSettingCameraOpenToken = "cameraOpenToken";
static const char *kSettingCalibrationSave = "calibrationSave";
static const char *kSettingCalibSaveDir = "calibSaveDir";
static const char *kSettingCalibrationUpload = "calibrationUpload";
static const char *kSettingCalibrationServerUploadURL = "calibrationServerUploadURL";
static const char *kSettingCalibrationServerAuthenticationToken = "calibrationServerAuthenticationToken";
static const char *kSettingCalibrationPatternType = "calibrationPatternType";
static const char *kSettingCalibrationPatternSizeWidth = "calibrationPatternSizeWidth";
static const char *kSettingCalibrationPatternSizeHeight = "calibrationPatternSizeHeight";
static const char *kSettingCalibrationPatternSpacing = "calibrationPatternSpacing";
static const char *kCalibrationPatternTypeChessboardStr = "Chessboard";
static const char *kCalibrationPatternTypeCirclesStr = "Circles";
static const char *kCalibrationPatternTypeAsymmetricCirclesStr = "Asymmetric circles";
void *showPreferencesThread(void *);
void *initPreferences(void)
{
prefsLibConfig_t *prefs;
int err;
arMallocClear(prefs, prefsLibConfig_t, 1);
config_init(&prefs->config);
config_setting_t *root = config_root_setting(&prefs->config);
if (asprintf(&prefs->prefsPath, "%s/%s", arUtilGetAndCreateResourcesDirectoryPath(AR_UTIL_RESOURCES_DIRECTORY_BEHAVIOR_USE_APP_DATA_DIR), PREFS_FILENAME) < 0) {
ARLOGperror(NULL);
goto bail;
}
ARLOGd("Preferences config path is '%s'.\n", prefs->prefsPath);
// Attempt to read config, initialising any unconfigured values to defaults.
err = test_f(prefs->prefsPath, NULL);
if (err < 0) {
ARLOGperror(NULL);
goto bail;
} else if (err == 0) {
// Ensure that the directory is available.
} else if (err == 1) {
if (config_read_file(&prefs->config, prefs->prefsPath) == CONFIG_FALSE) {
ARLOGe("Error reading configuration file '%s': %s.\n", prefs->prefsPath, config_error_text(&prefs->config));
goto bail;
}
prefs->settingCOT = config_setting_get_member(root, kSettingCameraOpenToken);
prefs->settingCalibrationSave = config_setting_get_member(root, kSettingCalibrationSave);
prefs->settingCalibSaveDir = config_setting_get_member(root, kSettingCalibSaveDir);
prefs->settingCalibrationUpload = config_setting_get_member(root, kSettingCalibrationUpload);
prefs->settingCSUU = config_setting_get_member(root, kSettingCalibrationServerUploadURL);
prefs->settingCSAT = config_setting_get_member(root, kSettingCalibrationServerAuthenticationToken);
prefs->settingCalibrationPatternType = config_setting_get_member(root, kSettingCalibrationPatternType);
prefs->settingCalibrationPatternSizeWidth = config_setting_get_member(root, kSettingCalibrationPatternSizeWidth);
prefs->settingCalibrationPatternSizeHeight = config_setting_get_member(root, kSettingCalibrationPatternSizeHeight);
prefs->settingCalibrationPatternSpacing = config_setting_get_member(root, kSettingCalibrationPatternSpacing);
}
if (!prefs->settingCOT) prefs->settingCOT = config_setting_add(root, kSettingCameraOpenToken, CONFIG_TYPE_STRING);
if (!prefs->settingCalibrationSave) prefs->settingCalibrationSave = config_setting_add(root, kSettingCalibrationSave, CONFIG_TYPE_BOOL);
if (!prefs->settingCalibSaveDir) prefs->settingCalibSaveDir = config_setting_add(root, kSettingCalibSaveDir, CONFIG_TYPE_STRING);
if (!prefs->settingCalibrationUpload) {
prefs->settingCalibrationUpload = config_setting_add(root, kSettingCalibrationUpload, CONFIG_TYPE_BOOL);
#if defined(ARTOOLKITX_CSUU) && defined(ARTOOLKITX_CSAT)
config_setting_set_bool(prefs->settingCalibrationUpload, true);
#endif
}
if (!prefs->settingCSUU) prefs->settingCSUU = config_setting_add(root, kSettingCalibrationServerUploadURL, CONFIG_TYPE_STRING);
if (!prefs->settingCSAT) prefs->settingCSAT = config_setting_add(root, kSettingCalibrationServerAuthenticationToken, CONFIG_TYPE_STRING);
if (!prefs->settingCalibrationPatternType) prefs->settingCalibrationPatternType = config_setting_add(root, kSettingCalibrationPatternType, CONFIG_TYPE_STRING);
if (!prefs->settingCalibrationPatternSizeWidth) prefs->settingCalibrationPatternSizeWidth = config_setting_add(root, kSettingCalibrationPatternSizeWidth, CONFIG_TYPE_INT);
if (!prefs->settingCalibrationPatternSizeHeight) prefs->settingCalibrationPatternSizeHeight = config_setting_add(root, kSettingCalibrationPatternSizeHeight, CONFIG_TYPE_INT);
if (!prefs->settingCalibrationPatternSpacing) prefs->settingCalibrationPatternSpacing = config_setting_add(root, kSettingCalibrationPatternSpacing, CONFIG_TYPE_FLOAT);
return ((void *)prefs);
bail:
free(prefs);
return (NULL);
}
void showPreferences(void *preferences)
{
pthread_t pt;
pthread_attr_t pta;
pthread_attr_init(&pta);
pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_DETACHED);
if (pthread_create(&pt, &pta, showPreferencesThread, preferences) < 0) {
ARLOGperror(NULL);
return;
}
pthread_attr_destroy(&pta);
}
void *showPreferencesThread(void *arg)
{
enum state {
PREFS_BEGIN,
PREFS_OPTION_HELP,
PREFS_OPTION_CAMERA,
PREFS_OPTION_CALIB_SAVE,
PREFS_OPTION_CALIB_SAVE_DIR,
PREFS_OPTION_CALIB_UPLOAD,
#if !(defined(ARTOOLKITX_CSUU) && defined(ARTOOLKITX_CSAT))
PREFS_OPTION_CSUU,
PREFS_OPTION_CSAT,
#endif
PREFS_OPTION_CALIB_PATT_TYPE,
PREFS_OPTION_CALIB_PATT_SIZE,
PREFS_OPTION_CALIB_PATT_SPACING,
PREFS_END
};
enum state state = PREFS_BEGIN;
int inputi;
unsigned char *inputa;
prefsLibConfig_t *prefs = (prefsLibConfig_t *)arg;
if (!prefs) {
ARLOGe("NULL preferences.\n");
return (NULL);
}
flowHandleEvent(EVENT_MODAL);
while (state != PREFS_END) {
if (state == PREFS_BEGIN) {
const char prompt[] =
"Preferences\n"
"\n"
"1. Help.\n"
"2. Camera.\n"
"3. Save calibration on/off.\n"
"4. Save calibration destination directory.\n"
#if defined(ARTOOLKITX_CSUU) && defined(ARTOOLKITX_CSAT)
"5. Upload calibration to artoolkitx.org on/off.\n"
"6. Calibration pattern type.\n"
"7. Calibration pattern size.\n"
"8. Calibration pattern spacing.\n"
#else
"5. Upload calibration to my server on/off.\n"
"6. My calibration server URL.\n"
"7. My calibration server authentication token.\n"
"8. Calibration pattern type.\n"
"9. Calibration pattern size.\n"
"10. Calibration pattern spacing.\n"
#endif
"\n"
"Press [esc] to finish or type number and press [return] ";
EdenMessageInput((const unsigned char *)prompt, 1, 2, true, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_END;
else if (!inputa[0] || sscanf((const char *)inputa, "%d", &inputi) < 1) {
free(inputa);
state = PREFS_END;
} else {
free(inputa);
if (inputi == 1) state = PREFS_OPTION_HELP;
else if (inputi == 2) state = PREFS_OPTION_CAMERA;
else if (inputi == 3) state = PREFS_OPTION_CALIB_SAVE;
else if (inputi == 4) state = PREFS_OPTION_CALIB_SAVE_DIR;
else if (inputi == 5) state = PREFS_OPTION_CALIB_UPLOAD;
#if defined(ARTOOLKITX_CSUU) && defined(ARTOOLKITX_CSAT)
else if (inputi == 6) state = PREFS_OPTION_CALIB_PATT_TYPE;
else if (inputi == 7) state = PREFS_OPTION_CALIB_PATT_SIZE;
else if (inputi == 8) state = PREFS_OPTION_CALIB_PATT_SPACING;
#else
else if (inputi == 6) state = PREFS_OPTION_CSUU;
else if (inputi == 7) state = PREFS_OPTION_CSAT;
else if (inputi == 8) state = PREFS_OPTION_CALIB_PATT_TYPE;
else if (inputi == 9) state = PREFS_OPTION_CALIB_PATT_SIZE;
else if (inputi == 10) state = PREFS_OPTION_CALIB_PATT_SPACING;
#endif
}
} else if (state == PREFS_OPTION_HELP) {
int ret = system("which xdg-open");
if (ret != 0) {
EdenMessageInput((const unsigned char *)"Unable to open help (missing xdg-open command). Press [return] to continue. ", 0, 0, false, false, false);
inputa = EdenMessageInputGetInput();
free(inputa);
} else {
system("xdg-open https://github.com/artoolkitx/artoolkitx-calibration/wiki");
}
state = PREFS_BEGIN;
} else if (state == PREFS_OPTION_CAMERA) {
ARVideoSourceInfoListT *sil = ar2VideoCreateSourceInfoList("");
if (!sil) {
ARLOGe("Unable to get ARVideoSourceInfoListT.\n");
state = PREFS_END;
} else if (sil->count == 0) {
EdenMessageInput((const unsigned char *)"No video sources connected.\n\nPress [return] to continue.", 0, 1, false, false, false);
state = PREFS_BEGIN;
} else {
char prompt[4096] = "Preferences: Camera.\n\n";
size_t len;
int selectedItemIndex = -1;
const char *cot = config_setting_get_string(prefs->settingCOT);
for (int i = 0; i < sil->count; i++) {
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "%d. %s\n", i + 1, sil->info[i].name);
if (cot && sil->info[i].open_token && strcmp(cot, sil->info[i].open_token) == 0) {
selectedItemIndex = i;
}
}
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "\nCurrent value is %s.\n\nPress [esc] to leave unchanged, or type a number and press [return] ", (selectedItemIndex >= 0 ? sil->info[selectedItemIndex].name : "a camera not currently connected"));
EdenMessageInput((const unsigned char *)prompt, 1, 2, true, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else if (!inputa[0] || sscanf((const char *)inputa, "%d", &inputi) < 1 || inputi < 1 || inputi > sil->count) {
free(inputa);
} else {
config_setting_set_string(prefs->settingCOT, sil->info[inputi - 1].open_token);
ARLOGd("User chose camera %d (%s).\n", inputi - 1, sil->info[inputi - 1].open_token);
}
state = PREFS_BEGIN;
}
} else if (state == PREFS_OPTION_CALIB_SAVE) {
bool b = config_setting_get_bool(prefs->settingCalibrationSave);
char prompt[4096] = "Preferences: Save calibration.\n\n";
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Saving is %s.\n\nPress [esc] to leave unchanged, or press [return] to toggle ", (b ? "on" : "off"));
EdenMessageInput((const unsigned char *)prompt, 0, 0, false, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else {
free(inputa);
config_setting_set_bool(prefs->settingCalibrationSave, !b);
ARLOGd("User chose calibration save %s.\n", (!b ? "on" : "off"));
}
} else if (state == PREFS_OPTION_CALIB_SAVE_DIR) {
const char *s = config_setting_get_string(prefs->settingCalibSaveDir);
char prompt[4096] = "Preferences: save calibration destination directory.\n\n";
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Current value is '%s'.\n\nPress [esc] to leave unchanged, [return] to use default, or type new setting and press [return] ", s ? s : "");
EdenMessageInput((const unsigned char *)prompt, 0, 2048, false, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else {
if (inputa[0]) {
config_setting_set_string(prefs->settingCalibSaveDir, (const char *)inputa);
ARLOGd("User chose save calibration destination directory '%s'.\n", (const char *)inputa);
}
free(inputa);
state = PREFS_BEGIN;
}
} else if (state == PREFS_OPTION_CALIB_UPLOAD) {
bool b = config_setting_get_bool(prefs->settingCalibrationUpload);
#if defined(ARTOOLKITX_CSUU) && defined(ARTOOLKITX_CSAT)
char prompt[4096] = "Preferences: Upload calibration to artoolkitx.org.\n\n";
#else
char prompt[4096] = "Preferences: Upload calibration to my server.\n\n";
#endif
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Upload is %s.\n\nPress [esc] to leave unchanged, or press [return] to toggle ", (b ? "on" : "off"));
EdenMessageInput((const unsigned char *)prompt, 0, 0, false, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else {
free(inputa);
config_setting_set_bool(prefs->settingCalibrationUpload, !b);
ARLOGd("User chose calibration upload %s.\n", (!b ? "on" : "off"));
}
#if !defined(ARTOOLKITX_CSUU) && !defined(ARTOOLKITX_CSAT)
} else if (state == PREFS_OPTION_CSUU) {
const char *s = config_setting_get_string(prefs->settingCSUU);
char prompt[4096] = "Preferences: My calibration server URL.\n\n";
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Current value is '%s'.\n\nPress [esc] to leave unchanged, [return] to use default, or type new setting and press [return] ", s ? s : "");
EdenMessageInput((const unsigned char *)prompt, 0, 2048, false, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else {
if (inputa[0]) {
config_setting_set_string(prefs->settingCSUU, (const char *)inputa);
ARLOGd("User chose calibration server upload URL '%s'.\n", (const char *)inputa);
}
free(inputa);
state = PREFS_BEGIN;
}
} else if (state == PREFS_OPTION_CSAT) {
const char *s = config_setting_get_string(prefs->settingCSAT);
char prompt[4096] = "Preferences: My calibration server authentication token.\n\n";
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Current value is '%s'.\n\nPress [esc] to leave unchanged, [return] to use default, or type new setting and press [return] ", s ? s : "");
EdenMessageInput((const unsigned char *)prompt, 0, 2048, false, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else {
if (inputa[0]) {
config_setting_set_string(prefs->settingCSAT, (const char *)inputa);
ARLOGd("User chose calibration server authentication token '%s'.\n", (const char *)inputa);
}
free(inputa);
state = PREFS_BEGIN;
}
#endif
} else if (state == PREFS_OPTION_CALIB_PATT_TYPE) {
const char *s = config_setting_get_string(prefs->settingCalibrationPatternType);
char prompt[4096] = "Preferences: Calibration pattern type.\n\n1. Chessboard\n2. Circles\n3. Asymmetric circles.\n";
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Current value is '%s'.\n\nPress [esc] to leave unchanged, or type a number and press [return] ", s ? s : "");
EdenMessageInput((const unsigned char *)prompt, 1, 1, true, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else if (!inputa[0] || sscanf((const char *)inputa, "%d", &inputi) < 1) {
free(inputa);
state = PREFS_BEGIN;
} else {
free(inputa);
const char *typeA = NULL;
Calibration::CalibrationPatternType type;
if (inputi == 1) {
typeA = kCalibrationPatternTypeChessboardStr;
type = Calibration::CalibrationPatternType::CHESSBOARD;
} else if (inputi == 2) {
typeA = kCalibrationPatternTypeCirclesStr;
type = Calibration::CalibrationPatternType::CIRCLES_GRID;
} else if (inputi == 3) {
typeA = kCalibrationPatternTypeAsymmetricCirclesStr;
type = Calibration::CalibrationPatternType::ASYMMETRIC_CIRCLES_GRID;
}
if (typeA) {
config_setting_set_string(prefs->settingCalibrationPatternType, typeA);
config_setting_set_int(prefs->settingCalibrationPatternSizeWidth, Calibration::CalibrationPatternSizes[type].width);
config_setting_set_int(prefs->settingCalibrationPatternSizeHeight, Calibration::CalibrationPatternSizes[type].height);
config_setting_set_float(prefs->settingCalibrationPatternSpacing, Calibration::CalibrationPatternSpacings[type]);
ARLOGd("User chose calibration pattern type '%s'.\n", type);
}
state = PREFS_BEGIN;
}
} else if (state == PREFS_OPTION_CALIB_PATT_SIZE) {
int w = config_setting_get_int(prefs->settingCalibrationPatternSizeWidth);
int h = config_setting_get_int(prefs->settingCalibrationPatternSizeHeight);
char prompt[4096] = "Preferences: Calibration pattern size.\n\n";
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Current size is %dx%d.\n\nPress [esc] to leave unchanged, or type new values and press [return] ", w, h);
EdenMessageInput((const unsigned char *)prompt, 1, 7, false, false, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else if (!inputa[0] || sscanf((const char *)inputa, "%dx%d", &w, &h) < 2) {
free(inputa);
state = PREFS_BEGIN;
} else {
free(inputa);
config_setting_set_int(prefs->settingCalibrationPatternSizeWidth, w);
config_setting_set_int(prefs->settingCalibrationPatternSizeHeight, h);
ARLOGd("User chose calibration pattern size %dx%d.\n", w, h);
state = PREFS_BEGIN;
}
} else if (state == PREFS_OPTION_CALIB_PATT_SPACING) {
float f = config_setting_get_float(prefs->settingCalibrationPatternSpacing);
char prompt[4096] = "Preferences: Calibration pattern spacing.\n\n";
size_t len;
len = strlen(prompt);
snprintf(prompt + len, sizeof(prompt) - len, "Current spacing is %.2f.\n\nPress [esc] to leave unchanged, or type new value and press [return] ", f);
EdenMessageInput((const unsigned char *)prompt, 1, 20, false, true, false);
inputa = EdenMessageInputGetInput();
if (!inputa) state = PREFS_BEGIN;
else if (!inputa[0] || sscanf((const char *)inputa, "%f", &f) < 1) {
free(inputa);
state = PREFS_BEGIN;
} else {
free(inputa);
config_setting_set_float(prefs->settingCalibrationPatternSpacing, f);
ARLOGd("User chose calibration pattern spacing %.2f.\n", f);
state = PREFS_BEGIN;
}
}
}
if (config_write_file(&prefs->config, prefs->prefsPath) == CONFIG_FALSE) {
ARLOGe("Error writing configuration file '%s': %s.\n", prefs->prefsPath, config_error_text(&prefs->config));
}
flowHandleEvent(EVENT_MODAL);
SDL_Event event;
SDL_zero(event);
event.type = gSDLEventPreferencesChanged;
event.user.code = (Sint32)0;
event.user.data1 = NULL;
event.user.data2 = NULL;
SDL_PushEvent(&event);
return NULL;
}
char *getPreferenceCameraOpenToken(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return NULL;
const char *s = config_setting_get_string(prefs->settingCOT);
if (s && s[0]) return strdup(s);
return NULL;
}
char *getPreferenceCameraResolutionToken(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return NULL;
return NULL;
}
bool getPreferenceCalibrationSave(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return false;
bool uploadOn = config_setting_get_bool(prefs->settingCalibrationUpload);
return (uploadOn ? config_setting_get_bool(prefs->settingCalibrationSave) : true);
}
char *getPreferenceCalibSaveDir(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (prefs) {
const char *s = config_setting_get_string(prefs->settingCalibSaveDir);
if (s && s[0]) return strdup(s);
}
return (arUtilGetResourcesDirectoryPath(AR_UTIL_RESOURCES_DIRECTORY_BEHAVIOR_USE_USER_ROOT));
}
char *getPreferenceCalibrationServerUploadURL(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return NULL;
bool uploadOn = config_setting_get_bool(prefs->settingCalibrationUpload);
if (!uploadOn) return (NULL);
#if defined(ARTOOLKITX_CSUU) && defined(ARTOOLKITX_CSAT)
return (strdup(ARTOOLKITX_CSUU));
#else
const char *s = config_setting_get_string(prefs->settingCSUU);
if (s && s[0]) return strdup(s);
return (NULL);
#endif
}
char *getPreferenceCalibrationServerAuthenticationToken(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return NULL;
bool uploadOn = config_setting_get_bool(prefs->settingCalibrationUpload);
if (!uploadOn) return (NULL);
#if defined(ARTOOLKITX_CSUU) && defined(ARTOOLKITX_CSAT)
return (strdup(ARTOOLKITX_CSAT));
#else
const char *s = config_setting_get_string(prefs->settingCSAT);
if (s && s[0]) return strdup(s);
return (NULL);
#endif
}
Calibration::CalibrationPatternType getPreferencesCalibrationPatternType(void *preferences)
{
Calibration::CalibrationPatternType patternType = CALIBRATION_PATTERN_TYPE_DEFAULT;
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return patternType;
const char *s = config_setting_get_string(prefs->settingCalibrationPatternType);
if (s && s[0]) {
if (strcmp(s, kCalibrationPatternTypeChessboardStr) == 0) patternType = Calibration::CalibrationPatternType::CHESSBOARD;
else if (strcmp(s, kCalibrationPatternTypeCirclesStr) == 0) patternType = Calibration::CalibrationPatternType::CIRCLES_GRID;
else if (strcmp(s, kCalibrationPatternTypeAsymmetricCirclesStr) == 0) patternType = Calibration::CalibrationPatternType::ASYMMETRIC_CIRCLES_GRID;
}
return patternType;
}
cv::Size getPreferencesCalibrationPatternSize(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return Calibration::CalibrationPatternSizes[CALIBRATION_PATTERN_TYPE_DEFAULT];
int w = config_setting_get_int(prefs->settingCalibrationPatternSizeWidth);
int h = config_setting_get_int(prefs->settingCalibrationPatternSizeHeight);
if (w > 0 && h > 0) return cv::Size(w, h);
return Calibration::CalibrationPatternSizes[CALIBRATION_PATTERN_TYPE_DEFAULT];
}
float getPreferencesCalibrationPatternSpacing(void *preferences)
{
prefsLibConfig_t *prefs = (prefsLibConfig_t *)preferences;
if (!prefs) return Calibration::CalibrationPatternSpacings[CALIBRATION_PATTERN_TYPE_DEFAULT];
float f = config_setting_get_int(prefs->settingCalibrationPatternSpacing);
if (f > 0.0f) return f;
return Calibration::CalibrationPatternSpacings[CALIBRATION_PATTERN_TYPE_DEFAULT];
}
void preferencesFinal(void **preferences_p)
{
if (!preferences_p) return;
prefsLibConfig_t *prefs = (prefsLibConfig_t *)*preferences_p;
if (!prefs) return;
config_destroy(&prefs->config);
free(prefs->prefsPath);
free(*preferences_p);
*preferences_p = NULL;
}
#endif // ARX_TARGET_PLATFORM_LINUX