예제 #1
0
        protected void CalculateAngle()
        {
            //Create line from the base of the whisker to the point on the whisker
            IWhiskerPoint baseWhiskerPoint = ControlPoints.Last();

            BasePoint = new Point(baseWhiskerPoint.XRatio * VideoWidth, baseWhiskerPoint.YRatio * VideoHeight);
            Point  anglePoint;
            Vector gradient;

            if (TValue == 1)
            {
                //If TValue == 1 (Point on whisker == base), calculate gradient at TValue = 1
                gradient      = GetBezierGradientVideoSize();
                gradient     *= -1;
                anglePoint    = BasePoint;
                anglePoint.X += gradient.X;
                anglePoint.Y += gradient.Y;
            }
            else
            {
                anglePoint = GetTValuePoint();
                gradient   = new Vector(anglePoint.X - BasePoint.X, anglePoint.Y - BasePoint.Y);
            }

            //Create line which will determine angle
            gradient.Normalize();
            TargetPoint = anglePoint;

            AngleLine = gradient;
            Angle     = AngleType.CalculateAngle(AngleLine);
        }
예제 #2
0
        public PickUnitsPointsViewModel(Bitmap bitmap, IWhiskerPoint point1 = null, IWhiskerPoint point2 = null)
        {
            Image = bitmap;

            IGenericPoint genericPoint1 = ModelResolver.Resolve <IGenericPoint>();
            IGenericPoint genericPoint2 = ModelResolver.Resolve <IGenericPoint>();

            genericPoint1.PointId = 1;
            genericPoint2.PointId = 2;

            GenericPointViewModel viewModel1 = new GenericPointViewModel(genericPoint1);
            GenericPointViewModel viewModel2 = new GenericPointViewModel(genericPoint2);

            //IWhisker whisker = ModelResolver.Resolve<IWhisker>();
            //whisker.WhiskerId = 1;

            //IWhiskerPoint whiskerPoint1 = point1 ?? ModelResolver.Resolve<IWhiskerPoint>();
            //whiskerPoint1.Parent = whisker;
            ////whiskerPoint1.WhiskerId = 0;

            //IWhiskerPoint whiskerPoint2 = point2 ?? ModelResolver.Resolve<IWhiskerPoint>();
            //whiskerPoint2.Parent = whisker;
            ////whiskerPoint2.WhiskerId = 1;
            //whisker.WhiskerPoints = new IWhiskerPoint[] { whiskerPoint1, whiskerPoint2 };

            //WhiskerViewModel whiskerViewModel = new WhiskerViewModel(whisker);
            //WhiskerPointViewModel viewModel1 = new WhiskerPointViewModel(whiskerPoint1, whiskerViewModel);
            //WhiskerPointViewModel viewModel2 = new WhiskerPointViewModel(whiskerPoint2, whiskerViewModel);

            CanvasChildren.Add(viewModel1);
            CanvasChildren.Add(viewModel2);
        }
예제 #3
0
        public PickUnitsPointsViewModel(Bitmap bitmap, IWhiskerPoint point1 = null, IWhiskerPoint point2 = null)
        {
            Image = bitmap;

            IGenericPoint genericPoint1 = ModelResolver.Resolve<IGenericPoint>();
            IGenericPoint genericPoint2 = ModelResolver.Resolve<IGenericPoint>();

            genericPoint1.PointId = 1;
            genericPoint2.PointId = 2;

            GenericPointViewModel viewModel1 = new GenericPointViewModel(genericPoint1);
            GenericPointViewModel viewModel2 = new GenericPointViewModel(genericPoint2);

            //IWhisker whisker = ModelResolver.Resolve<IWhisker>();
            //whisker.WhiskerId = 1;

            //IWhiskerPoint whiskerPoint1 = point1 ?? ModelResolver.Resolve<IWhiskerPoint>();
            //whiskerPoint1.Parent = whisker;
            ////whiskerPoint1.WhiskerId = 0;

            //IWhiskerPoint whiskerPoint2 = point2 ?? ModelResolver.Resolve<IWhiskerPoint>();
            //whiskerPoint2.Parent = whisker;
            ////whiskerPoint2.WhiskerId = 1;
            //whisker.WhiskerPoints = new IWhiskerPoint[] { whiskerPoint1, whiskerPoint2 };

            //WhiskerViewModel whiskerViewModel = new WhiskerViewModel(whisker);
            //WhiskerPointViewModel viewModel1 = new WhiskerPointViewModel(whiskerPoint1, whiskerViewModel);
            //WhiskerPointViewModel viewModel2 = new WhiskerPointViewModel(whiskerPoint2, whiskerViewModel);

            CanvasChildren.Add(viewModel1);
            CanvasChildren.Add(viewModel2);
        }
예제 #4
0
        public override bool Equals(object obj)
        {
            IWhiskerPoint other = obj as IWhiskerPoint;

            if (other == null)
            {
                return(false);
            }

            return(Equals(other));
        }
예제 #5
0
        private void CreateData()
        {
            if (Model == null || ImageWidth == 0 || ImageHeight == 0)
            {
                return;
            }

            IWhiskerPoint velocityPoint = Model.VelocityPoint;

            VelocityPoint     = new Point(velocityPoint.XRatio * ImageWidth, velocityPoint.YRatio * ImageHeight);
            VelocityDirection = ModifyVideoToImageVector(Model.Velocity);
        }
예제 #6
0
        public override void LoadData(IMouseFrame frame)
        {
            IWhisker nose        = frame.Whiskers.FirstOrDefault(x => x.WhiskerId == -1);
            IWhisker orientation = frame.Whiskers.FirstOrDefault(x => x.WhiskerId == 0);

            if (nose == null || orientation == null)
            {
                return;
            }

            NosePoint        = nose.WhiskerPoints[0];
            OrientationPoint = orientation.WhiskerPoints[0];
        }
        private void CreateData()
        {
            IWhisker noseWhisker        = Model.NoseWhisker;
            IWhisker orientationWhisker = Model.OrientationWhisker;

            if (noseWhisker == null || orientationWhisker == null)
            {
                return;
            }

            IWhiskerPoint nose = noseWhisker.WhiskerPoints[0];

            NosePoint = new Point(nose.XRatio * ImageWidth, nose.YRatio * ImageHeight);

            IWhiskerPoint orientation = orientationWhisker.WhiskerPoints[0];

            OrientationPoint = new Point(orientation.XRatio * ImageWidth, orientation.YRatio * ImageHeight);
        }
예제 #8
0
        private void CreateAngleLine()
        {
            Vector gradient = Model.AngleLine;

            gradient.Normalize();
            Point         basePoint   = Model.BasePoint;
            IWhiskerPoint lastPoint   = Model.ControlPoints.First();
            Point         targetPoint = new Point(lastPoint.XRatio * ImageWidth, lastPoint.YRatio * ImageHeight);

            basePoint.X = ConvertHorizontalFromVideoToImage(basePoint.X);
            basePoint.Y = ConvertVerticalFromVideoToImage(basePoint.Y);

            Vector distance   = new Vector(targetPoint.X - basePoint.X, targetPoint.Y - basePoint.Y);
            double lineLength = distance.Length;

            X1 = basePoint.X - (gradient.X * lineLength);
            Y1 = basePoint.Y - (gradient.Y * lineLength);
            X2 = basePoint.X + (gradient.X * lineLength);
            Y2 = basePoint.Y + (gradient.Y * lineLength);
        }
예제 #9
0
        private void CalculateCurvature()
        {
            Curvature = 0;

            if (ControlPoints.Length == 2)
            {
                TargetPoint = GetTValuePointForLinear();
            }
            else if (ControlPoints.Length == 3)
            {
                IWhiskerPoint cWhiskerPoint0 = Whisker.WhiskerPoints[0];
                IWhiskerPoint cWhiskerPoint1 = Whisker.WhiskerPoints[1];
                IWhiskerPoint cWhiskerPoint2 = Whisker.WhiskerPoints[2];

                Point[] points = new Point[3];
                points[0] = new Point(cWhiskerPoint0.XRatio * VideoWidth, cWhiskerPoint0.YRatio * VideoHeight);
                points[1] = new Point(cWhiskerPoint1.XRatio * VideoWidth, cWhiskerPoint1.YRatio * VideoHeight);
                points[2] = new Point(cWhiskerPoint2.XRatio * VideoWidth, cWhiskerPoint2.YRatio * VideoHeight);

                Curvature = DrawingUtility.GetQuadraticBezierCurvature(points, TValue);

                TargetPoint = GetTValuePointForQuadratic();
            }
            else
            {
                IWhiskerPoint cWhiskerPoint0 = Whisker.WhiskerPoints[0];
                IWhiskerPoint cWhiskerPoint1 = Whisker.WhiskerPoints[1];
                IWhiskerPoint cWhiskerPoint2 = Whisker.WhiskerPoints[2];
                IWhiskerPoint cWhiskerPoint3 = Whisker.WhiskerPoints[3];

                Point[] points = new Point[4];
                points[0] = new Point(cWhiskerPoint0.XRatio * VideoWidth, cWhiskerPoint0.YRatio * VideoHeight);
                points[1] = new Point(cWhiskerPoint1.XRatio * VideoWidth, cWhiskerPoint1.YRatio * VideoHeight);
                points[2] = new Point(cWhiskerPoint2.XRatio * VideoWidth, cWhiskerPoint2.YRatio * VideoHeight);
                points[3] = new Point(cWhiskerPoint3.XRatio * VideoWidth, cWhiskerPoint3.YRatio * VideoHeight);

                Curvature   = DrawingUtility.GetCubicBezierCurvature(points, TValue);
                TargetPoint = GetTValuePointForCubic();
            }
        }
예제 #10
0
        private void CalculateVelocity()
        {
            if (VelocityPoint == null || PreviousFrame == null || FrameRateSettings == null || UnitSettings == null)
            {
                return;
            }

            IWhiskerPoint previousWhisker = PreviousFrame.VelocityPoint;
            Point         currentPoint    = new Point(VelocityPoint.XRatio * VideoWidth, VelocityPoint.YRatio * VideoHeight);
            Point         previousPoint   = new Point(previousWhisker.XRatio * VideoWidth, previousWhisker.YRatio * VideoHeight);

            Vector distance = new Vector(currentPoint.X - previousPoint.X, currentPoint.Y - previousPoint.Y) * FrameRateSettings.OriginalFrameRate;

            distance *= UnitSettings.UnitsPerPixel;

            if (CompensateForHeadMovement)
            {
                distance -= NosePoint.Velocity;
            }

            Velocity = distance;
        }
예제 #11
0
        public IWhisker CreateWhisker(IMouseFrame mouseFrame)
        {
            IWhisker whisker = ModelResolver.Resolve <IWhisker>();

            whisker.Parent    = mouseFrame;
            whisker.WhiskerId = WhiskerId;

            IWhiskerPoint[] whiskerPoints = new IWhiskerPoint[NumberOfPoints];
            whisker.WhiskerPoints = new IWhiskerPoint[NumberOfPoints];
            for (int i = 0; i < NumberOfPoints; i++)
            {
                IWhiskerPoint whiskerPoint = ModelResolver.Resolve <IWhiskerPoint>();
                whiskerPoint.Parent  = whisker;
                whiskerPoint.PointId = i + 1;
                whiskerPoints[i]     = whiskerPoint;
            }

            whisker.WhiskerPoints  = whiskerPoints;
            whisker.IsGenericPoint = IsGenericPoint;
            whisker.WhiskerName    = WhiskerName;

            return(whisker);
        }
예제 #12
0
        protected void GenerateCurve()
        {
            //Make sure we have all the info we need
            if (Whisker == null || Whisker.WhiskerPoints == null)
            {
                return;
            }

            if (Whisker.WhiskerPoints.Length == 0)
            {
                return;
            }

            if (Whisker.Parent.OriginalWidth == 0 || Whisker.Parent.OriginalHeight == 0)
            {
                return;
            }

            //Calculate Control Points
            IWhiskerPoint firstPoint = Whisker.WhiskerPoints[0].Clone();

            ControlPoints = new IWhiskerPoint[Whisker.WhiskerPoints.Length];
            ControlPoints[0] = firstPoint;

            double videoWidth = Whisker.Parent.OriginalWidth;
            double videoHeight = Whisker.Parent.OriginalHeight;

            if (ControlPoints.Length == 2)
            {
                IWhiskerPoint lWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                ControlPoints[1] = lWhiskerPoint1;
                TargetPoint = GetTValuePointForLinear();
            }

            if (ControlPoints.Length == 3)
            {
                IWhiskerPoint qWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                IWhiskerPoint qWhiskerPoint2 = Whisker.WhiskerPoints[2].Clone();

                Point[] points = new Point[3];
                points[0] = new Point(firstPoint.XRatio * videoWidth, firstPoint.YRatio * videoHeight);
                points[1] = new Point(qWhiskerPoint1.XRatio * videoWidth, qWhiskerPoint1.YRatio * videoHeight);
                points[2] = new Point(qWhiskerPoint2.XRatio * videoWidth, qWhiskerPoint2.YRatio * videoHeight);

                Point point1;
                DrawingUtility.GetControlPointsForQuadraticBezier(points, out point1);

                qWhiskerPoint1.XRatio = point1.X / videoWidth;
                qWhiskerPoint1.YRatio = point1.Y / videoHeight;

                ControlPoints[1] = qWhiskerPoint1;
                ControlPoints[2] = qWhiskerPoint2;
                TargetPoint = GetTValuePointForQuadratic();
            }

            if (ControlPoints.Length == 4)
            {
                IWhiskerPoint cWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                IWhiskerPoint cWhiskerPoint2 = Whisker.WhiskerPoints[2].Clone();
                IWhiskerPoint cWhiskerPoint3 = Whisker.WhiskerPoints[3].Clone();

                Point[] points = new Point[4];
                points[0] = new Point(firstPoint.XRatio * videoWidth, firstPoint.YRatio * videoHeight);
                points[1] = new Point(cWhiskerPoint1.XRatio * videoWidth, cWhiskerPoint1.YRatio * videoHeight);
                points[2] = new Point(cWhiskerPoint2.XRatio * videoWidth, cWhiskerPoint2.YRatio * videoHeight);
                points[3] = new Point(cWhiskerPoint3.XRatio * videoWidth, cWhiskerPoint3.YRatio * videoHeight);

                Point point1, point2;
                DrawingUtility.GetControlPointsForCubicBezier(points, out point1, out point2);

                cWhiskerPoint1.XRatio = point1.X / videoWidth;
                cWhiskerPoint1.YRatio = point1.Y / videoHeight;
                cWhiskerPoint2.XRatio = point2.X / videoWidth;
                cWhiskerPoint2.YRatio = point2.Y / videoHeight;

                ControlPoints[1] = cWhiskerPoint1;
                ControlPoints[2] = cWhiskerPoint2;
                ControlPoints[3] = cWhiskerPoint3;
                TargetPoint = GetTValuePointForCubic();
            }
        }
예제 #13
0
 public bool Equals(IWhiskerPoint other)
 {
     return Parent.Equals(other.Parent) && PointId == other.PointId;
 }
예제 #14
0
        protected void GenerateCurve()
        {
            //Make sure we have all the info we need
            if (Whisker == null || Whisker.WhiskerPoints == null)
            {
                return;
            }

            if (Whisker.WhiskerPoints.Length == 0)
            {
                return;
            }

            if (Whisker.Parent.OriginalWidth == 0 || Whisker.Parent.OriginalHeight == 0)
            {
                return;
            }

            //Calculate Control Points
            IWhiskerPoint firstPoint = Whisker.WhiskerPoints[0].Clone();

            ControlPoints    = new IWhiskerPoint[Whisker.WhiskerPoints.Length];
            ControlPoints[0] = firstPoint;

            double videoWidth  = Whisker.Parent.OriginalWidth;
            double videoHeight = Whisker.Parent.OriginalHeight;

            if (ControlPoints.Length == 2)
            {
                IWhiskerPoint lWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                ControlPoints[1] = lWhiskerPoint1;
                TargetPoint      = GetTValuePointForLinear();
            }

            if (ControlPoints.Length == 3)
            {
                IWhiskerPoint qWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                IWhiskerPoint qWhiskerPoint2 = Whisker.WhiskerPoints[2].Clone();

                Point[] points = new Point[3];
                points[0] = new Point(firstPoint.XRatio * videoWidth, firstPoint.YRatio * videoHeight);
                points[1] = new Point(qWhiskerPoint1.XRatio * videoWidth, qWhiskerPoint1.YRatio * videoHeight);
                points[2] = new Point(qWhiskerPoint2.XRatio * videoWidth, qWhiskerPoint2.YRatio * videoHeight);

                Point point1;
                DrawingUtility.GetControlPointsForQuadraticBezier(points, out point1);

                qWhiskerPoint1.XRatio = point1.X / videoWidth;
                qWhiskerPoint1.YRatio = point1.Y / videoHeight;

                ControlPoints[1] = qWhiskerPoint1;
                ControlPoints[2] = qWhiskerPoint2;
                TargetPoint      = GetTValuePointForQuadratic();
            }

            if (ControlPoints.Length == 4)
            {
                IWhiskerPoint cWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                IWhiskerPoint cWhiskerPoint2 = Whisker.WhiskerPoints[2].Clone();
                IWhiskerPoint cWhiskerPoint3 = Whisker.WhiskerPoints[3].Clone();

                Point[] points = new Point[4];
                points[0] = new Point(firstPoint.XRatio * videoWidth, firstPoint.YRatio * videoHeight);
                points[1] = new Point(cWhiskerPoint1.XRatio * videoWidth, cWhiskerPoint1.YRatio * videoHeight);
                points[2] = new Point(cWhiskerPoint2.XRatio * videoWidth, cWhiskerPoint2.YRatio * videoHeight);
                points[3] = new Point(cWhiskerPoint3.XRatio * videoWidth, cWhiskerPoint3.YRatio * videoHeight);

                Point point1, point2;
                DrawingUtility.GetControlPointsForCubicBezier(points, out point1, out point2);

                cWhiskerPoint1.XRatio = point1.X / videoWidth;
                cWhiskerPoint1.YRatio = point1.Y / videoHeight;
                cWhiskerPoint2.XRatio = point2.X / videoWidth;
                cWhiskerPoint2.YRatio = point2.Y / videoHeight;

                ControlPoints[1] = cWhiskerPoint1;
                ControlPoints[2] = cWhiskerPoint2;
                ControlPoints[3] = cWhiskerPoint3;
                TargetPoint      = GetTValuePointForCubic();
            }
        }
예제 #15
0
파일: Whisker.cs 프로젝트: pierrekhoury/MWA
 public void Initialise(int numberOfPoints)
 {
     WhiskerPoints = new IWhiskerPoint[numberOfPoints];
 }
예제 #16
0
        public IWhisker CreateWhisker(IMouseFrame mouseFrame)
        {
            IWhisker whisker = ModelResolver.Resolve<IWhisker>();

            whisker.Parent = mouseFrame;
            whisker.WhiskerId = WhiskerId;

            IWhiskerPoint[] whiskerPoints = new IWhiskerPoint[NumberOfPoints];
            whisker.WhiskerPoints = new IWhiskerPoint[NumberOfPoints];
            for (int i = 0; i < NumberOfPoints; i++)
            {
                IWhiskerPoint whiskerPoint = ModelResolver.Resolve<IWhiskerPoint>();
                whiskerPoint.Parent = whisker;
                whiskerPoint.PointId = i + 1;
                whiskerPoints[i] = whiskerPoint;
            }

            whisker.WhiskerPoints = whiskerPoints;
            whisker.IsGenericPoint = IsGenericPoint;
            whisker.WhiskerName = WhiskerName;

            return whisker;
        }
예제 #17
0
 public WhiskerPointViewModel(IWhiskerPoint model, WhiskerViewModel parent)
 {
     Model = model;
     Parent = parent;
     GetColor();
 }
예제 #18
0
 public bool Equals(IWhiskerPoint other)
 {
     return(Parent.Equals(other.Parent) && PointId == other.PointId);
 }
예제 #19
0
 public WhiskerPointXml(IWhiskerPoint whiskerPoint)
 {
     PointId = whiskerPoint.PointId;
     XRatio = whiskerPoint.XRatio;
     YRatio = whiskerPoint.YRatio;
 }
예제 #20
0
 public WhiskerPointXml(IWhiskerPoint whiskerPoint)
 {
     PointId = whiskerPoint.PointId;
     XRatio  = whiskerPoint.XRatio;
     YRatio  = whiskerPoint.YRatio;
 }
예제 #21
0
 public WhiskerPointViewModel(IWhiskerPoint model, WhiskerViewModel parent)
 {
     Model  = model;
     Parent = parent;
     GetColor();
 }