-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkeletonDrawer.cs
136 lines (117 loc) · 4.85 KB
/
SkeletonDrawer.cs
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
using System.Windows.Media;
using Xtr3D.Net.ExtremeMotion.Data;
using Xtr3D.Net.ExtremeMotion.Interop.Types;
using Xtr3D.Net;
namespace CSharpVisualSkeletonSample
{
class SkeletonDrawer
{
private readonly Brush m_brush = new SolidColorBrush(Color.FromArgb(255, 70, 190, 70));
private Pen m_bonePen = new Pen(Brushes.Green, 8);
DrawingGroup m_drawingGroup;
DrawingImage m_imageSource;
ImageInfo m_imageInfo;
public SkeletonDrawer(ImageInfo imageInfo)
{
m_drawingGroup = new DrawingGroup();
m_imageSource = new DrawingImage(m_drawingGroup);
m_imageInfo = imageInfo;
}
public ImageSource ImageSource
{
get
{
return m_imageSource;
}
}
internal System.Windows.Point toScreenPoint(Joint joint)
{
double calcedX = joint.skeletonPoint.ImgCoordNormHorizontal * m_imageInfo.Width,
calcedY = joint.skeletonPoint.ImgCoordNormVertical * m_imageInfo.Height;
double x = calcedX >= m_imageInfo.Width ? m_imageInfo.Width - 1 : calcedX;
double y = calcedY >= m_imageInfo.Height ? m_imageInfo.Height - 1 : calcedY;
return new System.Windows.Point(x, y);
}
internal void DrawBone(DrawingContext dc, Joint joint1, Joint joint2)
{
dc.DrawLine(m_bonePen, toScreenPoint(joint1), toScreenPoint(joint2));
DrawJoint(dc, joint1);
DrawJoint(dc, joint2);
}
internal void WipeSkeleton()
{
using (DrawingContext dc = m_drawingGroup.Open())
{
dc.DrawEllipse(m_brush, null, new System.Windows.Point(0, 0), 1, 1);
dc.DrawEllipse(m_brush, null, new System.Windows.Point(m_imageInfo.Width, m_imageInfo.Height), 1, 1);
}
}
internal void DrawJoint(DrawingContext dc, Joint joint1)
{
dc.DrawEllipse(m_brush, null, toScreenPoint(joint1), 3, 3);
}
internal void DrawSkeleton(JointCollection joints)
{
using (DrawingContext dc = m_drawingGroup.Open())
{
dc.DrawEllipse(m_brush, null, new System.Windows.Point(0, 0), 1, 1);
dc.DrawEllipse(m_brush, null, new System.Windows.Point(m_imageInfo.Width, m_imageInfo.Height), 1, 1);
DrawJoint(dc, joints.Head);
DrawBone(dc, joints.Spine, joints.HipCenter);
DrawBone(dc, joints.Head, joints.ShoulderCenter);
DrawBone(dc, joints.ShoulderCenter, joints.Spine);
DrawBone(dc, joints.Spine, joints.ShoulderLeft);
DrawBone(dc, joints.Spine, joints.ShoulderRight);
if (joints.ElbowLeft.jointTrackingState == JointTrackingState.NotTracked)
{
DrawJoint(dc, joints.ShoulderLeft);
}
else
{
DrawBone(dc, joints.ShoulderLeft, joints.ElbowLeft);
if (joints.HandLeft.jointTrackingState != JointTrackingState.NotTracked)
{
DrawBone(dc, joints.ElbowLeft, joints.HandLeft);
}
}
if (joints.ElbowRight.jointTrackingState == JointTrackingState.NotTracked)
{
DrawJoint(dc, joints.ShoulderRight);
}
else
{
DrawBone(dc, joints.ShoulderRight, joints.ElbowRight);
if (joints.HandRight.jointTrackingState != JointTrackingState.NotTracked)
{
DrawBone(dc, joints.ElbowRight, joints.HandRight);
}
}
// Lower Body
if (joints.KneeLeft.jointTrackingState == JointTrackingState.NotTracked)
{
DrawJoint(dc, joints.HipLeft);
}
else
{
DrawBone(dc, joints.HipLeft, joints.KneeLeft);
if (joints.FootLeft.jointTrackingState != JointTrackingState.NotTracked)
{
DrawBone(dc, joints.KneeLeft, joints.FootLeft);
}
}
if (joints.KneeRight.jointTrackingState == JointTrackingState.NotTracked)
{
DrawJoint(dc, joints.HipRight);
}
else
{
DrawBone(dc, joints.HipRight, joints.KneeRight);
if (joints.FootRight.jointTrackingState != JointTrackingState.NotTracked)
{
DrawBone(dc, joints.KneeRight, joints.FootRight);
}
}
}
}
}
}