using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Drawing;


namespace SimpleSurfSift
{
    public class LoCATe
    {
        public List<double[]> extract(Bitmap image, string detector)
        {
            CEDD cedd = new CEDD();
            Bitmap bmpImage = new Bitmap(image);

            createPoints pointsCreator = new createPoints();
            List<keypoint> keypointsList = null;
            if (detector == "SURF")
                keypointsList = pointsCreator.usingSurf(image);
            else if (detector == "SIFT")
                keypointsList = pointsCreator.usingSift(image);
            else
                throw new Exception("Cannot recognize Detector");

            #region LoCATe
            Rectangle cloneRect;
            Bitmap bmpCrop;
            double[] ceddDescriptor;
            List<double[]> tilesDescriptors = new List<double[]>();
            foreach (keypoint myKeypoint in keypointsList)
            {
                cloneRect = new Rectangle((int)(myKeypoint.X - (int)myKeypoint.Size / 2), (int)(myKeypoint.Y - (int)myKeypoint.Size / 2), (int)myKeypoint.Size, (int)myKeypoint.Size);
                bmpCrop = new Bitmap(bmpImage.Clone(cloneRect, bmpImage.PixelFormat));

                ceddDescriptor = cedd.Apply(new Bitmap(bmpCrop));
                tilesDescriptors.Add(ceddDescriptor);
            }
            #endregion

            return tilesDescriptors;
        }

    }
}