-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkeletonManager.cpp
213 lines (166 loc) · 5.61 KB
/
SkeletonManager.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
#include "SkeletonManager.h"
#include <cvrKernel/ComController.h>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <sys/syscall.h>
#include <sys/stat.h>
//#include "Skeleton.h"
using namespace cvr;
using namespace std;
using namespace osg;
SkeletonManager::SkeletonManager()
{
should_quit = false;
sf2 = new RemoteKinect::SkeletonFrame();
kNavSpheres = false;
kMoveWithCam = false;
_root = new osg::MatrixTransform();
SceneManager::instance()->getObjectsRoot()->addChild(_root);
// _root->addChild(kinectgrp);
}
SkeletonManager::~SkeletonManager()
{
}
bool SkeletonManager::isCacheDone()
{
return _cacheDone;
}
void SkeletonManager::update()
{
static bool frameLoading = false;
bool cDone;
if(true)
{
if(cvr::ComController::instance()->isMaster())
{
cDone = _cacheDone;
int numSlaves = cvr::ComController::instance()->getNumSlaves();
bool sDone[numSlaves];
cvr::ComController::instance()->readSlaves(sDone,sizeof(bool));
for(int i = 0; i < numSlaves; i++)
{
cDone = cDone && sDone[i];
}
cvr::ComController::instance()->sendSlaves(&cDone,sizeof(bool));
}
else
{
cDone = _cacheDone;
cvr::ComController::instance()->sendMaster(&cDone,sizeof(bool));
cvr::ComController::instance()->readMaster(&cDone,sizeof(bool));
}
if(!cDone)
{
//std::cerr << "Waiting for load to finish." << std::endl;
return;
}
cvr::ComController::instance()->sync();
//Add not here?
return;
}
if(cDone)
{
std::cerr << "Load Finished." << std::endl;
//Add loaded node to root
}
else
{
// std::cerr << "Waiting for GPU load finish." << std::endl;
}
}
void SkeletonManager::run()
{
//Do functions
//cerr << ".";
if(!should_quit)
{
zmq::context_t context3(1);
skelT_socket = NULL;
skelT_socket = new SubSocket<RemoteKinect::SkeletonFrame> (context3, ConfigManager::getEntry("Plugin.KinectDemo.KinectServer.Skeleton"));
while(!should_quit)
{
if (Skeleton::moveWithCam)
{
Matrix camMat = PluginHelper::getWorldToObjectTransform(); //This will get us actual real world coordinates that the camera is at (not sure about how it does rotation)
float cscale = 1; //Want to keep scale to actual Kinect which is is meters
Vec3 camTrans = camMat.getTrans();
Quat camQuad = camMat.getRotate(); //Rotation of cam will cause skeleton to be off center--need Fix!!
double xOffset = (camTrans.x() / cscale);
double yOffset = (camTrans.y() / cscale) + 3; //Added Offset of Skeleton so see a little ways from camera (i.e. 5 meters, works at this scale,only)
double zOffset = (camTrans.z() / cscale);
Skeleton::camPos = Vec3d(xOffset, yOffset, zOffset);
Skeleton::camRot = camQuad;
}
while (skelT_socket->recv(*sf2))
{
// cerr << ".";
//return;
// remove all the skeletons that are no longer reported by the server
for (std::map<int, Skeleton>::iterator it2 = mapIdSkel.begin(); it2 != mapIdSkel.end(); ++it2)
{
bool found = false;
for (int i = 0; i < sf2->skeletons_size(); i++)
{
if (sf2->skeletons(i).skeleton_id() == it2->first)
{
found = true;
break;
}
}
if (!found)
{
mapIdSkel[it2->first].detach(_root);
}
}
//cerr << sf->skeletons_size();
// update all skeletons' joints' positions
for (int i = 0; i < sf2->skeletons_size(); i++)
{
// Skeleton reported but not in the map -> create a new one
if (mapIdSkel.count(sf2->skeletons(i).skeleton_id()) == 0)
{
mapIdSkel[sf2->skeletons(i).skeleton_id()] = Skeleton(); ///XXX remove Skeleton(); part
mapIdSkel[sf2->skeletons(i).skeleton_id()].attach(_root);
}
// Skeleton previously detached (stopped being reported), but is again reported -> reattach
if (mapIdSkel[sf2->skeletons(i).skeleton_id()].attached == false)
mapIdSkel[sf2->skeletons(i).skeleton_id()].attach(_root);
for (int j = 0; j < sf2->skeletons(i).joints_size(); j++)
{
float test;
test = sf2->skeletons(i).joints(j).type();
test = sf2->skeletons(i).joints(j).x() / 1000;
test = sf2->skeletons(i).joints(j).z() / -1000;
test = sf2->skeletons(i).joints(j).y() / 1000;
test = sf2->skeletons(i).joints(j).qx();
test = sf2->skeletons(i).joints(j).qz();
test = sf2->skeletons(i).joints(j).qy();
test = sf2->skeletons(i).joints(j).qw();
/*
mapIdSkel[sf2->skeletons(i).skeleton_id()].update(
sf2->skeletons(i).joints(j).type(),
sf2->skeletons(i).joints(j).x() / 1000,
sf2->skeletons(i).joints(j).z() / -1000,
sf2->skeletons(i).joints(j).y() / 1000,
sf2->skeletons(i).joints(j).qx(),
sf2->skeletons(i).joints(j).qz(),
sf2->skeletons(i).joints(j).qy(),
sf2->skeletons(i).joints(j).qw());
*/
}
}
}
}
if(should_quit)
{
}
}
//When Finished
_cacheDone = true;
std::cerr << "All frames loaded." << std::endl;
}
void SkeletonManager::quit()
{
should_quit = true;
}