-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_interface.cpp
117 lines (96 loc) · 2.57 KB
/
device_interface.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
/*
* device_interface.cpp
*
* Created on: Oct 10, 2017
* Author: may
*/
#include <stdlib.h>
#if defined(OS_WINDOWS)
#include <windows.h>
#endif
#include <boost/thread/once.hpp>
#include "device_interface.h"
#include "utils.h"
#include "DeviceBase.h"
#include "IPGTrack.h"
#include "smarttrack.h"
DeviceBase *device = nullptr;
#ifdef ST_COMPARE
DeviceBase *st = nullptr;
#endif /* ST_COMPARE */
boost::once_flag once = BOOST_ONCE_INIT;
void hack_ipgmovie_terminate() {
device->Export(false);
device->Terminate();
#ifdef ST_COMPARE
st->Export(false);
st->Terminate();
#endif /* ST_COMPARE */
}
void hack_ipgmovie_init(Tcl_Interp *interp) {
atexit(hack_ipgmovie_terminate);
// Workaround to set undefined variable Pgm($Debug)
Tcl_SetVar2Ex(interp, "Pgm", "Debug", Tcl_NewIntObj(0), 0);
device = new IPGTrack();
device->Init();
device->Export(true);
#ifdef ST_COMPARE
st = new SmartTrack();
st->Init();
st->Export(true);
#endif /* ST_COMPARE */
}
int device_get_mvmatrix(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
// FIXME: Remove once IPGMovie implements this
// Make sure to call init function only once
boost::call_once(boost::bind(&hack_ipgmovie_init, interp), once);
// Allocate new tcl_ret object
Tcl_Obj* tcl_ret = Tcl_NewListObj(0, NULL);
// FIXME: Remove once IPGMovie implements this
// On 'Spacebar': set the new camera origin
#if defined(OS_WINDOWS)
if (GetAsyncKeyState(VK_SPACE)) {
#else
char key = get_keystroke();
if (key == 32) {
#endif
device->ResetCamera();
#ifdef ST_COMPARE
st->ResetCamera();
#endif
}
device->GetMVMatrix(interp, tcl_ret);
// Return the complete tcl list
Tcl_SetObjResult(interp, tcl_ret);
return TCL_OK;
}
int device_postproc(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
device->PostProcc();
return TCL_OK;
}
int device_init(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
// TODO: switch-case to initialise desired device
device = new IPGTrack();
device->Init();
return TCL_OK;
}
int device_cam_reset(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
device->ResetCamera();
return TCL_OK;
}
int device_terminate(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
device->Terminate();
delete device;
return TCL_OK;
}
int device_close(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
device->Terminate();
delete device;
return TCL_OK;
}