forked from VIML/NIController
-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserMap.h
183 lines (147 loc) · 3.53 KB
/
UserMap.h
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
#pragma once
#pragma region Header Files
// STL Header
#include <array>
// Qt Header
#include <QtGui/QtGui>
// OpenNI and NiTE Header
#include <OpenNI.h>
#include <NiTE.h>
#pragma endregion
/**
* The QGraphicsItem to draw user face direction
*/
class QUserDirection : public QGraphicsItem
{
public:
QPen m_qPen1;
QPen m_qPen2;
public:
QUserDirection( float fSize = 40 ) : QGraphicsItem()
{
m_qPen1.setColor( qRgb( 255, 255, 0 ) );
m_qPen1.setWidth( 3 );
m_qPen2.setColor( qRgb( 255, 0, 0 ) );
m_qPen2.setWidth( 5 );
m_vDir = QVector2D( 0, -1 );
SetSize( fSize );
}
void SetSize( float fSize )
{
float fS = fSize / 2;
m_qRect = QRectF( -fS, -fS, fSize, fSize );
}
QRectF boundingRect() const
{
return m_qRect;
}
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
// p1
painter->setPen( m_qPen1 );
painter->drawEllipse( m_qRect );
// p2
painter->setPen( m_qPen2 );
float r = m_qRect.width() / 2;
painter->drawLine( 0, 0, r * m_vDir.x(), r * m_vDir.y() );
}
void SetDirection( const QVector2D& rVec )
{
m_vDir = rVec;
}
private:
QRectF m_qRect;
QVector2D m_vDir;
};
/**
* The user skeleton
*/
class QONI_Skeleton : public QGraphicsItem
{
public:
float m_fScale;
QVector2D m_vPositionShift;
QPen m_qSkeletonPen;
public:
QONI_Skeleton()
{
m_fScale = 1.0f / 2.5f;
m_vPositionShift = QVector2D( 320, 320 );
m_qSkeletonPen.setWidth( 3 );
m_qSkeletonPen.setColor( qRgba( 64, 64, 255, 192 ) );
m_bUpdateransform = true;
}
QRectF boundingRect() const
{
QRectF qRect( m_aJoint2D[0], QSizeF( 1, 1 ) );
for( auto itP = m_aJoint2D.begin(); itP != m_aJoint2D.end(); ++ itP )
qRect |= QRectF( *itP, QSizeF( 1, 1 ) );
return qRect;
}
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
void SetSkeleton( const nite::Skeleton& rSkeleton );
void KeepTransform( bool bKeep = true )
{
m_bUpdateransform = !bKeep;
}
public:
std::array<QPointF,15> m_aJoint2D;
std::array<QVector3D,15> m_aJointRotated;
std::array<nite::SkeletonJoint,15> m_aJointOri;
QVector3D m_vDirection;
private:
bool m_bUpdateransform;
QMatrix4x4 m_qTransform;
};
/**
* User Map
*/
class QONI_UserMap : public QGraphicsItemGroup
{
public:
QONI_UserMap( nite::UserTracker& rUserTracker ) : m_rUserTracker(rUserTracker)
{
addToGroup(&m_UserImage);
addToGroup(&m_UserSkeleton);
addToGroup(&m_UserDirection);
SetSize( 640, 480 );
m_UserSkeleton.hide();
}
bool Update();
void SetSize( int w, int h )
{
float fDirSize = w / 16;
m_UserDirection.SetSize( fDirSize );
m_UserDirection.resetTransform();
m_UserDirection.translate( w - fDirSize, h - fDirSize );
m_UserSkeleton.m_vPositionShift = QVector2D( w / 2, h * 2.0f / 3 );
m_UserSkeleton.m_fScale = 1.0f * w / 1600;
m_qRect = QRectF( 0, 0, w, h );
}
const nite::SkeletonJoint& GetActiveUserJoint( const nite::JointType& eJoint ) const
{
return m_UserSkeleton.m_aJointOri[eJoint];
}
const QVector3D& GetActiveUserJointTR( const nite::JointType& eJoint ) const
{
return m_UserSkeleton.m_aJointRotated[eJoint];
}
const QPointF& GetActiveUserJoint2D( const nite::JointType& eJoint ) const
{
return m_UserSkeleton.m_aJoint2D[eJoint];
}
void KeepSkeletonTransform( bool bKeep )
{
m_UserSkeleton.KeepTransform( bKeep );
}
QRectF boundingRect() const
{
return m_qRect;
}
private:
nite::UserTracker& m_rUserTracker;
QGraphicsPixmapItem m_UserImage;
QONI_Skeleton m_UserSkeleton;
QUserDirection m_UserDirection;
QRectF m_qRect;
};