-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
371 lines (310 loc) · 9.32 KB
/
Copy pathmain.cpp
File metadata and controls
371 lines (310 loc) · 9.32 KB
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
#include <windows.h>
#include <iostream>
/*
#include "pxcsensemanager.h"
#include "pxcmetadata.h"
#include "service/pxcsessionservice.h"
#include "pxchanddata.h"
#include "pxchandconfiguration.h"
#include "Definitions.h"
bool g_live = false; // true - Working in live camera mode, false - sequence mode
bool g_gestures = false; // Writing gesture data to console ouput
bool g_alerts = false; // Writing alerts data to console ouput
bool g_skeleton = false; // Writing skeleton data (22 joints) to console ouput
bool g_default = false; // Writing hand type to console ouput
bool g_stop = false; // user closes application
std::wstring g_sequencePath;
PXCSession *g_session;
PXCSenseManager *g_senseManager;
PXCHandModule *g_handModule;
PXCHandData *g_handDataOutput;
PXCHandConfiguration *g_handConfiguration;
void releaseAll();
BOOL CtrlHandler( DWORD fdwCtrlType )
{
switch( fdwCtrlType )
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
// confirm that the user wants to exit.
case CTRL_CLOSE_EVENT:
g_stop = true;
Sleep(1000);
releaseAll();
return( TRUE );
default:
return FALSE;
}
} */
#include "Dictionary.h"
#include "Parser.h"
#include <vector>
using std::string;
using std::vector;
using std::pair;
using std::cout;
using std::cin;
int main(int argc, const char* argv[])
{
Dictionary d;
Parser p("examples/example.json");
// vector of vector used to store all the pairs
vector< vector< pair<string, long> > > res;
// parse the json file
cout << "Parsing Json file..." << endl;
res = p.ReadJsonFile();
cout << "Parsing > OK" << endl;
cout << "" << endl;
// insert all the vectors of pairs in the dictionary
for (vector<vector<pair<string, long>>>::iterator it = res.begin(); it != res.end(); ++it){
d.insertList((*it));
}
//getsymbol
string mot = d.read(1);
mot = d.read(2);
mot = d.read(3);
mot = d.read(1);
cout << "Vector Dictionary creation..." << endl;
vector<vector<pair<string, long>>> v = d.createVectorDictionary(); // Create vector of vectors of pairs from the dict
cout << "Vector Dictionary > OK" << endl;
cout << "" << endl;
cout << "Writting Json file from vect..." << endl;
p.WriteJsonFile(v);
cout << "Json file > OK" << endl;
cout << "" << endl;
while (true);
/*Dictionary d;
//Première série pour faire un mot
pair<string, long> p1("jambon1", 1);
pair<string, long> p2("jambon4", 4);
pair<string, long> p3("jambon3", 3);
pair<string, long> p4("jambon2", 2);
//Deuxième série pour faire un mot
pair<string, int> p5("jambon1", 1); //Je vérifie que ca ne duplique pas le jambon1 du premier vecteur
pair<string, long> p6("saucisson1", 4); //p6 symbole = p2 symbole = 4. Cela va overwrite le "mot" lié au symbole 8 qui va devenir "saucisson1" à la place de jambon4
pair<string, long> p7("saucisson2", 7);
//Troisème mot
pair<string, long> p8("autruche", 8);
//Création des structures à envoyer au dictionnaire (un vecteur par série de mots/signes)
vector<pair<string, long>> v = { p1,p2,p3,p4};
vector<pair<string, long>> v2 = { p5,p6,p7};
vector<pair<string, long>> v3 = { p8 };
//On les insèrent au dico
d.insertList(v);
d.insertList(v2);
d.insertList(v3);
//Lire un symbole.
string temp = d.read(1); //Renvoie "" car 1 n'est pas un symbole final
cout << "la valeur premiere lecture est : " << temp <<"\n";
//Si le timer expire, alors on affiche le mot correspondant au dernier mot lu, soit le mot lié à symbol 1
temp = d.refreshDictionary();
cout << "la valeur deuxième lecture est : " << temp << "\n";
temp = d.read(1); //Renvoie "" car 1 n'est pas un symbole final
cout << "la valeur troisième lecture est : " << temp << "\n";
temp = d.read(1); //Renvoie la valeur du symbol 1 car 1 n'as pas de fils avec le symbol 1, c'est donc un symbol 1
cout << "la valeur quatrième lecture est : " << temp << "\n";
temp = d.read(1);
temp = d.read(4);
temp = d.read(7);
temp = d.refreshDictionary();
cout << "la valeur cinquième lecture est : " << temp << "\n";
temp = d.read(1);
cout << "la valeur sixieme lecture est : " << temp << "\n";
temp = d.read(4);
cout << "la valeur septième lecture est : " << temp << "\n";
temp = d.read(1);
cout << "la valeur huitième lecture est : " << temp << "\n";
temp = d.refreshDictionary();
cout << "la valeur neuvième lecture est : " << temp << "\n";
while (true);
return 0;*/
/*Definitions::appName = argv[0];
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
if(argc < 2)
{
Definitions::WriteHelpMessage();
return;
}
// Setup
g_session = PXCSession::CreateInstance();
if(!g_session)
{
std::printf("Failed Creating PXCSession\n");
return;
}
g_senseManager = g_session->CreateSenseManager();
if(!g_senseManager)
{
releaseAll();
std::printf("Failed Creating PXCSenseManager\n");
return;
}
if(g_senseManager->EnableHand() != PXC_STATUS_NO_ERROR)
{
releaseAll();
std::printf("Failed Enabling Hand Module\n");
return;
}
g_handModule = g_senseManager->QueryHand();
if(!g_handModule)
{
releaseAll();
std::printf("Failed Creating PXCHandModule\n");
return;
}
g_handDataOutput = g_handModule->CreateOutput();
if(!g_handDataOutput)
{
releaseAll();
std::printf("Failed Creating PXCHandData\n");
return;
}
g_handConfiguration = g_handModule->CreateActiveConfiguration();
if(!g_handConfiguration)
{
releaseAll();
std::printf("Failed Creating PXCHandConfiguration\n");
return;
}
// Iterating input parameters
for (int i=1;i<argc;i++)
{
if (strcmp(argv[i],"-live")==0)
{
g_live=true;
}
if (strcmp(argv[i],"-seq")==0)
{
g_live=false;
std::string tmp(argv[i+1]);
i++;
g_sequencePath.clear();
g_sequencePath.assign(tmp.begin(),tmp.end());
continue;
}
if (strcmp(argv[i],"-gestures")==0)
{
std::printf("-Gestures Are Enabled-\n");
g_handConfiguration->EnableAllGestures();
g_gestures = true;
}
if (strcmp(argv[i],"-alerts")==0)
{
std::printf("-Alerts Are Enabled-\n");
g_handConfiguration->EnableAllAlerts();
g_alerts = true;
}
if (strcmp(argv[i],"-skeleton")==0)
{
std::printf("-Skeleton Information Enabled-\n");
g_skeleton = true;
}
}
// Apply configuration setup
g_handConfiguration->ApplyChanges();
// run sequences as fast as possible
if(!g_live)
{
g_senseManager->QueryCaptureManager()->SetFileName(g_sequencePath.c_str(),false);
g_senseManager->QueryCaptureManager()->SetRealtime(false);
}
if(g_handConfiguration)
{
g_handConfiguration->Release();
g_handConfiguration = NULL;
}
g_default = !(g_alerts && g_gestures && g_skeleton);
pxcI32 numOfHands = 0;
// First Initializing the sense manager
if(g_senseManager->Init() == PXC_STATUS_NO_ERROR)
{
std::printf("\nPXCSenseManager Initializing OK\n========================\n");
if(g_default)
{
std::printf("Number of hands: %d\n",numOfHands);
}
// Acquiring frames from input device
while(g_senseManager->AcquireFrame(true) == PXC_STATUS_NO_ERROR && !g_stop)
{
// Get current hand outputs
if(g_handDataOutput->Update() == PXC_STATUS_NO_ERROR)
{
// Display alerts
if(g_alerts)
{
PXCHandData::AlertData alertData;
for(int i = 0 ; i < g_handDataOutput->QueryFiredAlertsNumber() ; ++i)
{
if(g_handDataOutput->QueryFiredAlertData(i,alertData) == PXC_STATUS_NO_ERROR)
{
std::printf("%s was fired at frame %d \n",Definitions::AlertToString(alertData.label).c_str(),alertData.frameNumber);
}
}
}
// Display gestures
if(g_gestures)
{
PXCHandData::GestureData gestureData;
for(int i = 0 ; i < g_handDataOutput->QueryFiredGesturesNumber() ; ++i)
{
if(g_handDataOutput->QueryFiredGestureData(i,gestureData) == PXC_STATUS_NO_ERROR)
{
std::wprintf(L"%s, Gesture: %s was fired at frame %d \n",Definitions::GestureStateToString(gestureData.state),gestureData.name,gestureData.frameNumber);
}
}
}
// Display joints
if(g_skeleton)
{
PXCHandData::IHand *hand;
PXCHandData::JointData jointData;
for(int i = 0 ; i < g_handDataOutput->QueryNumberOfHands() ; ++i)
{
g_handDataOutput->QueryHandData(PXCHandData::ACCESS_ORDER_BY_TIME,i,hand);
std::string handSide = "Unknown Hand";
handSide = hand->QueryBodySide() == PXCHandData::BODY_SIDE_LEFT ? "Left Hand" : "Right Hand";
std::printf("%s\n==============\n",handSide.c_str());
for(int j = 0 ; j < 22 ; ++j)
{
if(hand->QueryTrackedJoint((PXCHandData::JointType)j,jointData) == PXC_STATUS_NO_ERROR)
{
std::printf(" %s)\tX: %f, Y: %f, Z: %f \n",Definitions::JointToString((PXCHandData::JointType)j).c_str(),jointData.positionWorld.x,jointData.positionWorld.y,jointData.positionWorld.z);
}
}
}
}
// Display number of hands
if(g_default)
{
if(numOfHands != g_handDataOutput->QueryNumberOfHands())
{
numOfHands = g_handDataOutput->QueryNumberOfHands();
std::printf("Number of hands: %d\n",numOfHands);
}
}
} // end if update
g_senseManager->ReleaseFrame();
} // end while acquire frame
} // end if Init
else
{
releaseAll();
std::printf("Failed Initializing PXCSenseManager\n");
return;
}
releaseAll();
}
void releaseAll()
{
if(g_senseManager)
{
g_senseManager->Close();
g_senseManager->Release();
g_senseManager = NULL;
}
if(g_session)
{
g_session->Release();
g_session = NULL;
}*/
}