示例#1
0
        /// <summary>
        /// 教則グラフ生成用のコレクションを返す
        /// </summary>
        /// <returns></returns>
        public List<GraphPoint> generateBindingGraphCollection()
        {
            List<GraphPoint> collection = new List<GraphPoint>();

            int XRange = (int)this.Tempo.getAllFrame();

            for (int x = 0; x < XRange; x++)
            {
                float restTimeInBottom = this.Tempo.RestTimeInBottom;
                float restTimeInTop = this.Tempo.RestTimeInTop;
                float y = 0;

                if (x < restTimeInBottom * kinectFPS)
                {
                    // 下降時の休憩 180
                    y = PermissibleRangeInBottom.calcAverage() ;
                } else if(x >= restTimeInBottom * kinectFPS && x <= (restTimeInBottom + Tempo.RiseMovementTime) * kinectFPS)
                {
                    // 上昇中 180 -> 30
                    float downRange = (PermissibleRangeInBottom.calcAverage() - PermissibleRangeInTop.calcAverage()) / Tempo.RiseMovementTime / kinectFPS;
                    Console.WriteLine("downRange" + downRange);
                    y = PermissibleRangeInBottom.calcAverage() - downRange * (x - restTimeInBottom * kinectFPS);
                } else if(x >= (restTimeInBottom + Tempo.RiseMovementTime) * kinectFPS && x <= (restTimeInBottom + Tempo.RiseMovementTime + restTimeInTop) * kinectFPS)
                {
                    // 上昇時の休憩 30
                    y = PermissibleRangeInTop.calcAverage();
                } else
                {
                    // 上昇からの下降 30 -> 180
                    float upRange = (PermissibleRangeInBottom.calcAverage() - PermissibleRangeInTop.calcAverage()) / Tempo.DownwardMovementTime / kinectFPS;
                    Console.WriteLine("upRange" + upRange);
                    y = PermissibleRangeInTop.calcAverage() + upRange * (x - (restTimeInTop + restTimeInBottom + Tempo.RiseMovementTime) * kinectFPS);
                }

                Console.WriteLine("Add Point = " + x + "," + y);
                GraphPoint point = new GraphPoint(x,(int)y);
                collection.Add(point);
            }

            return collection;
        }
示例#2
0
        /// <summary>
        /// Kinectセンサーからの骨格情報のハンドリング
        /// 単位はメートル
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            if (this.TrainingInfo == null || this.isTraining == false) return;

            frameCount++;

            if (frameCount == this.TrainingInfo.RangeTrackingTargets.First().Tempo.getAllFrame())
            {
                this.UserAngleCollection.Clear();
                frameCount = 0;
            }

            using (var bodyFrame = e.FrameReference.AcquireFrame())
            {
                if (bodyFrame == null)
                {
                    return;
                }

                // ボディデータを取得する
                bodyFrame.GetAndRefreshBodyData(bodies);

                //ボディがトラッキングできている
                foreach (
                    var body in bodies.Where(b => b.IsTracked))
                {
                    // TrainingInfoを利用して原点と2つのベクトルから角度を求める
                    foreach (var trackingTarget in this.TrainingInfo.RangeTrackingTargets)
                    {
                        // 角度アノテーションの表示・座標の調整
                        AngleAnnotation annotation = this.AngleAnnotations.Where(ant => ant.trackingTarget.Origin == trackingTarget.Origin).First();
                        ColorSpacePoint colorPoint = this.kinect.CoordinateMapper.MapCameraPointToColorSpace(body.Joints[trackingTarget.Origin].Position);
                        Canvas.SetLeft(annotation, colorPoint.X / 2 - annotation.ActualWidth);
                        Canvas.SetTop(annotation, colorPoint.Y / 2 - annotation.ActualHeight);

                        //ベクトル計算してグラフに反映する。ただし、isManegeTempoプロパティがTrueのオブジェクトのみ。
                        CameraSpacePoint origin = new CameraSpacePoint();
                        CameraSpacePoint position1 = new CameraSpacePoint();
                        CameraSpacePoint position2 = new CameraSpacePoint();

                        // ベクトルが一つであれば、単位ベクトルを利用して計算する
                        if (trackingTarget.isUseUnitVector)
                        {
                            origin = body.Joints[trackingTarget.Origin].Position;
                            position1 = body.Joints[trackingTarget.Vector[0]].Position;
                        }
                        else
                        {
                            origin = body.Joints[trackingTarget.Origin].Position;
                            position1 = body.Joints[trackingTarget.Vector[0]].Position;
                            position2 = body.Joints[trackingTarget.Vector[1]].Position;
                        }

                        Model.Vector vector1 = new Model.Vector();
                        Model.Vector vector2 = new Model.Vector();
                        double cos;
                        double angle;
                        GraphPoint graphPoint;

                        switch (trackingTarget.PlaneType)
                        {
                            case PlaneType.CoronalPlane:
                                // X,Y
                                vector1.X = position1.X - origin.X;
                                vector1.Y = position1.Y - origin.Y;

                                if (trackingTarget.isUseUnitVector)
                                {
                                    vector2.X = trackingTarget.UnitVector.X - origin.X;
                                    vector2.Y = trackingTarget.UnitVector.Y - origin.Y;
                                } else
                                {
                                    vector2.X = position2.X - origin.X;
                                    vector2.Y = position2.Y - origin.Y;
                                }

                                cos = (vector1.X * vector2.X + vector1.Y * vector2.Y) /
                                    ((Math.Sqrt(Math.Pow(vector1.X, 2) + Math.Pow(vector1.Y, 2)) * Math.Sqrt(Math.Pow(vector2.X, 2) + Math.Pow(vector2.Y, 2))));
                                angle = Math.Acos(cos);
                                graphPoint = new GraphPoint(frameCount, (int)Utility.radToDegree(angle));

                                if (trackingTarget.isManageTempo)
                                {
                                    this.UserAngleCollection.Add(graphPoint);
                                }

                                annotation.Angle = (int)Utility.radToDegree(angle);

                                break;
                            case PlaneType.SagittalPlane:
                                // Y,Z
                                vector1.X = position1.Z - origin.Z;
                                vector1.Y = position1.Y - origin.Y;

                                if (trackingTarget.isUseUnitVector)
                                {
                                    vector2.X = trackingTarget.UnitVector.X - origin.Y;
                                    vector2.Y = trackingTarget.UnitVector.Y - origin.Z;
                                }
                                else
                                {
                                    vector2.X = position2.Z - origin.Z;
                                    vector2.Y = position2.Y - origin.Y;
                                }

                                cos = (vector1.X * vector2.X + vector1.Y * vector2.Y) /
                                    ((Math.Sqrt(Math.Pow(vector1.X, 2) + Math.Pow(vector1.Y, 2)) * Math.Sqrt(Math.Pow(vector2.X, 2) + Math.Pow(vector2.Y, 2))));
                                angle = Math.Acos(cos);
                                graphPoint = new GraphPoint(frameCount, (int)Utility.radToDegree(angle));

                                if (trackingTarget.isManageTempo == true)
                                {
                                    this.UserAngleCollection.Add(graphPoint);
                                }

                                annotation.Angle = (int)Utility.radToDegree(angle);

                                break;
                            case PlaneType.TransversePlane:
                                // X,Z
                                vector1.X = position1.Y - origin.Y;
                                vector1.Y = position1.Z - origin.Z;

                                if (trackingTarget.isUseUnitVector)
                                {
                                    vector2.X = trackingTarget.UnitVector.X - origin.Z;
                                    vector2.Y = trackingTarget.UnitVector.Y - origin.Y;
                                }
                                else
                                {
                                    vector2.X = position2.Y - origin.Y;
                                    vector2.Y = position2.Z - origin.Z;
                                }

                                cos = (vector1.X * vector2.X + vector1.Y * vector2.Y) /
                                                                    ((Math.Sqrt(Math.Pow(vector1.X, 2) + Math.Pow(vector1.Y, 2)) * Math.Sqrt(Math.Pow(vector2.X, 2) + Math.Pow(vector2.Y, 2))));
                                angle = Math.Acos(cos);
                                graphPoint = new GraphPoint(frameCount, (int)Utility.radToDegree(angle));

                                if (trackingTarget.isManageTempo)
                                {
                                    this.UserAngleCollection.Add(graphPoint);
                                }

                                annotation.Angle = (int)Utility.radToDegree(angle);

                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        }