private void DrawBoneOnColor(Joint startJoint, Joint endJoint, Color boneColor, double thickness, Point offset, int kinectID)
{
if (startJoint.TrackingState != TrackingState.NotTracked && endJoint.TrackingState != TrackingState.NotTracked)
{
//Map the joint from the skeleton to the color image
Point startPoint = server.kinects[kinectID].MapJointToColor(startJoint, false);
Point endPoint = server.kinects[kinectID].MapJointToColor(endJoint, false);
//Don't draw bones that are off the image
if (startPoint.X < 0 || startPoint.Y < 0 || startPoint.X >= colorSource.PixelWidth || startPoint.Y >= colorSource.PixelHeight ||
endPoint.X < 0 || endPoint.Y < 0 || endPoint.X >= colorSource.PixelWidth || endPoint.Y >= colorSource.PixelHeight)
{
return;
}
//Calculate the coordinates on the image (the offset of the image is added in the next section)
Point imagePointStart = new Point(0.0, 0.0);
imagePointStart.X = ((double)startPoint.X / colorSource.PixelWidth) * ColorImage.ActualWidth;
imagePointStart.Y = ((double)startPoint.Y / colorSource.PixelHeight) * ColorImage.ActualHeight;
Point imagePointEnd = new Point(0.0, 0.0);
imagePointEnd.X = ((double)endPoint.X / colorSource.PixelWidth) * ColorImage.ActualWidth;
imagePointEnd.Y = ((double)endPoint.Y / colorSource.PixelHeight) * ColorImage.ActualHeight;
if (startJoint.TrackingState == TrackingState.Inferred || endJoint.TrackingState == TrackingState.Inferred)
{
thickness = thickness / 2.0; //If either end of the joint is inferred, use a thinner line
}
//Generate the line for the bone
Line line = new Line();
line.Stroke = new SolidColorBrush(boneColor);
line.StrokeThickness = thickness;
line.X1 = imagePointStart.X + offset.X;
line.X2 = imagePointEnd.X + offset.X;
line.Y1 = imagePointStart.Y + offset.Y;
line.Y2 = imagePointEnd.Y + offset.Y;
ColorImageCanvas.Children.Add(line);
}
}