-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSensorDevice.h
More file actions
112 lines (80 loc) · 4.1 KB
/
SensorDevice.h
File metadata and controls
112 lines (80 loc) · 4.1 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
//
// SensorDevice: A wrapper for OpenNI devices
#ifndef _SENSOR_DEVICE_H
#define _SENSOR_DEVICE_H
#include <XnCppWrapper.h>
#include <string>
#include <vector>
#include "SkeletonMath.h"
class SensorDevice
{
public:
SensorDevice();
~SensorDevice();
int initialize();
inline void waitForDeviceUpdateOnUser() { context_.WaitOneUpdateAll(depthG_); }
/*
* Updates list of currently tracked users
* Returns TRUE if there is a user who's skeleton is being tracked
*/
bool isTracking();
// stores the latest hand points in hands(preallocated):
// hands[0] = left, hands[1] = right
void getHandPoints(const unsigned int i, Point* const hands);
// stores the latest elbow points in elbows
// same convention as getHandPoints()
void getElbowPoints(const unsigned int i, Point* const elbows);
// stores the lastest arm points : hand, elbow, shoulder
// 0 = l hand, 1 = r hand, 2 = left elbow....
void getArmPoints(const unsigned int i, Point* const arms);
// stores head points in externally managed array
void getHeadPoint(const unsigned int i, Point* const head);
// gets shoulder points
void getShoulderPoints(const unsigned int i, Point* const shoulders);
// returns unordered_map of points with keys of type <string>
void getAllAvailablePoints(){}
void getDepthMetaData(xn::DepthMetaData& depthMD) { depthG_.GetMetaData(depthMD); }
void getDepthSceneMetaData(xn::SceneMetaData& sceneMD) { userG_.GetUserPixels(0, sceneMD); }
void setPointModeToProjective() { pointModeProjective_ = true; }
void setPointModeToReal() { pointModeProjective_ = false; }
// set the smoothing factor
inline void setSmoothing(const float smoothingF)
{
smoothingFactor_ = smoothingF;
}
int lookForCalibrationPoseOn();
void startGeneratingAll() { context_.StartGeneratingAll(); }
// get/set: calibration pose may be needed by OpenNI device, default FALSE
inline bool getNeedCalibrationPose() const { return needCalibrationPose_; }
inline void setNeedCalibrationPose(const bool b) { needCalibrationPose_ = b; }
xn::UserGenerator* getUserGenerator() { return &userG_; }
xn::DepthGenerator* getDepthGenerator() { return &depthG_; }
unsigned int getNOTrackedUsers() { return trackedUsers_.size(); }
unsigned int getUID(int i) { return trackedUsers_[i]; }
void addTrackedUser(const int uID) { trackedUsers_.push_back(uID); }
void removeTrackedUser(const int uID);
void printAvailablePoses();
void convertXnJointToPoint(XnSkeletonJointPosition* const j, Point* const p, unsigned int numPoints);
inline const char* getPoseString() { return pose_.c_str(); }
void saveCalibrationDataOn() { saveCalibration_ = true; }
void saveCalibrationDataOn(std::string& filename) { saveCalibration_ = true;
calibrationFilename_ = filename; }
bool getSaveCalibration() { return saveCalibration_; }
void loadCalibrationFromFile(std::string& filename) { loadCalibration_ = true;
calibrationFilename_ = filename;
needCalibrationPose_ = false; }
const char* getCalibrationFilename() { return calibrationFilename_.c_str(); }
private:
xn::Context context_;
xn::DepthGenerator depthG_;
xn::UserGenerator userG_;
bool pointModeProjective_;
bool needCalibrationPose_;
std::string pose_;
std::vector<int> trackedUsers_;
bool loadCalibration_;
bool saveCalibration_;
std::string calibrationFilename_;
float smoothingFactor_;
};
#endif