using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.CV.Structure;
using bbiwarg.Detectors.FingerDetection;
using bbiwarg.Utility;

namespace bbiwarg.Detectors.HandDetection
{
    class Hand
    {
        public enum HandSide
        {
            Left,
            Right
        }

        public Vector2D Centroid { private set; get; }
        public HandSide Side { get; set; }
        public Image<Gray, byte> Mask { get; private set; }
        public List<Finger> Fingers { get; private set; }

        public Hand(Image<Gray, byte> mask, Finger finger) {
            Mask = mask;
            Centroid = getCentroid();
            Fingers = new List<Finger>();
            addFinger(finger);
        }

        public bool isInside(Vector2D point) {
            return (Mask.Data[point.IntY, point.IntX, 0] != 0);
        }

        public void addFinger(Finger finger) {
            Fingers.Add(finger);
        }

        private Vector2D getCentroid()
        {
            MCvPoint2D64f gravityCenter = Mask.GetMoments(true).GravityCenter;
            return new Vector2D((float)gravityCenter.x, (float)gravityCenter.y);
        }
    }
}
