Exemple #1
0
    /// <summary>
    /// Gets the slice width.
    /// </summary>
    /// <returns>The slice width.</returns>
    /// <param name="slice">Slice.</param>
    public float getSliceWidth(BodySlice slice)
    {
        int iSlice = (int)slice;

        if (bodySlices[iSlice].isSliceValid)
        {
            return(bodySlices[iSlice].diameter);
        }

        return(0f);
    }
Exemple #2
0
 /// <summary>
 /// Gets the body slice data.
 /// </summary>
 /// <returns>The body slice data.</returns>
 /// <param name="slice">Slice.</param>
 public BodySliceData getBodySliceData(BodySlice slice)
 {
     return(bodySlices[(int)slice]);
 }
        // creates body slice data for the given body slice
        private BodySliceData GetBodySliceParams(BodySlice sliceType, Vector2 middlePoint, bool bSliceOnX, bool bSliceOnY, int maxDepthLength)
        {
            BodySliceData sliceData = new BodySliceData();

            sliceData.sliceType = sliceType;

            sliceData.isSliceValid      = false;
            sliceData.depthPointsLength = 0;

            if (!kinectManager || middlePoint == Vector2.zero)
            {
                return(sliceData);
            }
            if (!bSliceOnX && !bSliceOnY)
            {
                return(sliceData);
            }

            middlePoint.x = Mathf.FloorToInt(middlePoint.x + 0.5f);
            middlePoint.y = Mathf.FloorToInt(middlePoint.y + 0.5f);

            int depthWidth  = sensorData.depthImageWidth;
            int depthHeight = sensorData.depthImageHeight;

            int  indexMid  = (int)middlePoint.y * depthWidth + (int)middlePoint.x;
            byte userIndex = sensorData.bodyIndexImage[indexMid];

            if (userIndex != userBodyIndex)
            {
                return(sliceData);
            }

            sliceData.startDepthPoint = middlePoint;
            sliceData.endDepthPoint   = middlePoint;

            int indexDiff1 = 0;
            int indexDiff2 = 0;

            if (bSliceOnX)
            {
                // min-max
                int minIndex = (int)middlePoint.y * depthWidth;
                int maxIndex = (int)(middlePoint.y + 1) * depthWidth;

                // horizontal left
                int stepIndex = -1;
                indexDiff1 = TrackSliceInDirection(indexMid, stepIndex, minIndex, maxIndex, userIndex);

                // horizontal right
                stepIndex  = 1;
                indexDiff2 = TrackSliceInDirection(indexMid, stepIndex, minIndex, maxIndex, userIndex);
            }
            else if (bSliceOnY)
            {
                // min-max
                int minIndex = 0;
                int maxIndex = depthHeight * depthWidth;

                // vertical up
                int stepIndex = -depthWidth;
                indexDiff1 = TrackSliceInDirection(indexMid, stepIndex, minIndex, maxIndex, userIndex);

                // vertical down
                stepIndex  = depthWidth;
                indexDiff2 = TrackSliceInDirection(indexMid, stepIndex, minIndex, maxIndex, userIndex);
            }

            // calculate depth length
            sliceData.depthPointsLength = indexDiff1 + indexDiff2 + 1;

            // check for max length (used by upper legs)
            if (maxDepthLength > 0 && sliceData.depthPointsLength > maxDepthLength)
            {
                if (indexDiff1 > indexDiff2)
                {
                    indexDiff1 = indexDiff2;
                }
                else
                {
                    indexDiff2 = indexDiff1;
                }

                sliceData.depthPointsLength = indexDiff1 + indexDiff2 + 1;
            }

            // set start and end depth points
            if (bSliceOnX)
            {
                sliceData.startDepthPoint.x -= indexDiff1;
                sliceData.endDepthPoint.x   += indexDiff2;
            }
            else if (bSliceOnY)
            {
                sliceData.startDepthPoint.y -= indexDiff1;
                sliceData.endDepthPoint.y   += indexDiff2;
            }

            // start point
            int    index1 = (int)sliceData.startDepthPoint.y * depthWidth + (int)sliceData.startDepthPoint.x;
            ushort depth1 = sensorData.depthImage[index1];

            sliceData.startKinectPoint = kinectManager.MapDepthPointToSpaceCoords(sensorIndex, sliceData.startDepthPoint, depth1, true);

            // end point
            int    index2 = (int)sliceData.endDepthPoint.y * depthWidth + (int)sliceData.endDepthPoint.x;
            ushort depth2 = sensorData.depthImage[index2];

            sliceData.endKinectPoint = kinectManager.MapDepthPointToSpaceCoords(sensorIndex, sliceData.endDepthPoint, depth2, true);

            sliceData.startColorPoint = kinectManager.MapDepthPointToColorCoords(sensorIndex, sliceData.startDepthPoint, depth1);
            sliceData.endColorPoint   = kinectManager.MapDepthPointToColorCoords(sensorIndex, sliceData.endDepthPoint, depth2);

            if (sliceData.startColorPoint.x < 0)
            {
                sliceData.startColorPoint.x = 0;
            }
            if (sliceData.endColorPoint.x >= sensorData.colorImageWidth)
            {
                sliceData.endColorPoint.x = sensorData.colorImageWidth - 1;
            }
            sliceData.colorPointsLength = (int)sliceData.endColorPoint.x - (int)sliceData.startColorPoint.x + 1;

            // diameter
            sliceData.diameter     = (sliceData.endKinectPoint - sliceData.startKinectPoint).magnitude;
            sliceData.isSliceValid = true;

            return(sliceData);
        }