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

using bbiwarg.Utility;

namespace bbiwarg
{
    class Constants
    {
        // Logger
        public static readonly LogSubject LogLevel = LogSubject.TouchEvents;
        public static readonly int ConsoleWidth = 90;
        public static readonly int ConsoleHeight = 30;
        
        // Output
        public static readonly bool OutputEnabled = true;
        public static readonly int OutputFrameRate = 30;
        public static readonly int OutputNumImages = 5;
        public static readonly int OutputNumImagesPerRow = 3;
        public static readonly float OutputScaleFactor = 1f; // output window size is scaled by this factor (from necessary size for images)
        public static readonly String OutputTitle = "BBIWARG - Output";

        // TUIO
        public static readonly bool TuioEnabled = true;
        public static readonly String TuioIP = "127.0.0.1";
        public static readonly int TuioPort = 3333;

        // image
        public static readonly float ImageDiagonalLength = new Vector2D(319,239).Length;

        // confidence image
        public static readonly int ConfidenceImageMinThreshold = 500;

        // depth image
        public static readonly int DepthImageMedianSize = 3;
        public static readonly int DepthImageDepthRange = 200; // <255

        // edge image
        public static readonly int EdgeImageCannyStartThreshold = 80;
        public static readonly int EdgeImageCannyLinkingThreshold = 60;
        public static readonly int EdgeImageCannySize = 3;
        public static readonly int EdgeImageRoughNumDilationIterations = 1;

        // finger detection
        public static readonly int FingerStepSize = 2;
        public static readonly int FingerMaxGapCounter = 5;
        public static readonly int FingerMaxSliceDifferencePerStep = 5;
        public static readonly int FingerMinNumSlices = 30 / FingerStepSize;
        public static readonly int FingerNumSlicesForDirectionDetection = FingerMinNumSlices / 4;
        public static readonly int FingerMaxWidth = 30;
        public static readonly int FingerMinWidth = 5;
        public static readonly int FingerRemoveNumSlicesForCorrection = 5;
        public static readonly int FingerNumSlicesForRelativeDirection = FingerRemoveNumSlicesForCorrection;
        public static readonly int FingerContourMargin = 2;
        public static readonly int FingerSliceOverlapFactor = 2;
        public static readonly int FingerCrippleOutFactor = 8;
        public static readonly int FingerCrippleOutMinDifference = 20;

        // finger tracking
        public static readonly int FingerNumFramesDetectedUntilTracked = 5;
        public static readonly int FingerNumFramesLostUntilDeleted = 10;
        public static readonly float FingerMinSimilarityForTracking = 0.7f;
        //public static readonly float FingerSimilarityMaxAngle = (float)(45 * Math.PI / 180); // 45°
        //public static readonly float FingerSimilarityMaxParallelDistance = 100;
        //public static readonly float FingerSimilarityMaxVerticalDistance = 20;

        // hand detection
        public static readonly float HandMaxSize = 0.7f;

        // palm detection
        public static readonly float PalmMinDefectMidFingerLineDistance = 20; // defects with mid point ((start + end) / 2) closer than this to a finger line are removed 
        public static readonly float PalmMaxThumbDefectAngle = 110; // degree
        public static readonly float PalmMaxThumbDefectStartEndLengthQuotient = 2.3f;
        public static readonly float PalmMinThumbDefectStartEndLengthQuotient = 1.2f;
        public static readonly float PalmMinTumbDefectDepthThumbLengthQuotient = 0.8f;
        public static readonly float PalmMaxTumbDefectDepthThumbLengthQuotient = 1.2f;
        public static readonly float PalmThumbDefectmXX = 50.0f;
        public static readonly float PalmThumbDefectmXY = -25.0f;
        public static readonly float PalmThumbDefectmYY = 50.0f;
        public static readonly float PalmThumbDefectProcessNoise = 5.0e+1f;
        public static readonly int PalmNumFramesNoHandReset = 5;
        public static readonly float PalmMinAreaQuotient = 0.6f;
        public static readonly float PalmMaxAreaQuotient = 1.4f;
        public static readonly float PalmMinPrecentageQuadForeground = 0.8f;
        public static readonly float PalmMaxPrecentageQuadForegroundReset = 0.5f;

        //palm Grid
        public static readonly int PalmGridNumRows = 3;
        public static readonly int PalmGridNumColumns = 3;

        // touch detection
        public static readonly float TouchEventMinTouchValue = 0.3f;
        public static readonly int TouchEventAreaSize = 30;
        public static readonly int TouchEventFloodfillLowDiff = 1;
        public static readonly int TouchEventFloodfillHighDiff = 3;
        public static readonly int TouchEventTipInsideFactor = 2;
        public static readonly int TouchEventTipOutsideFactor = 7;
        public static readonly float TouchmXX = 0.0008f;
        public static readonly float TouchmXY = 0.0f;
        public static readonly float TouchmYY = 0.0008f;
        public static readonly float TouchProcessNoise = 3.0e-4f;

        // touch tracking
        public static readonly int TouchEventNumFramesDetectedUntilTracked = 1;
        public static readonly int TouchEventNumFramesLostUntilDeleted = 3;
        public static readonly float TouchEventMinSimilarityForTracking = 0.7f;

        // colors
        public static readonly Color ColorDetected = Color.Turquoise;
        public static readonly Color ColorTracked = Color.Yellow;

        public static readonly Color DepthImageColor = Color.White;
        public static readonly Color EdgeImageColor = Color.Blue;
        public static readonly Color OutputImageBorderColor = Color.White;

        public static readonly Color FingerSliceColor = Color.Magenta;
        public static readonly Color FingerDetectedColor = ColorDetected;
        public static readonly Color FingerTrackedColor = ColorTracked;
        public static readonly Color FingerTipColor = Color.Blue;
        public static readonly Color FingerContourColor = Color.Red;
        public static readonly Color FingerIDColor = Color.White;

        public static readonly Color TouchEventDetectedColor = ColorDetected;
        public static readonly Color TouchEventTrackedColor = ColorTracked;
        public static readonly Color TouchEventAreaMatchedSubtractColor = Color.DarkOrange;
        public static readonly Color TouchEventAreaNonMatchedSubtractColor = Color.DarkSlateGray;
        public static readonly Color TouchEventStatusBarColor = Color.Green;

        public static readonly Color TouchEventVisualizerLineColor = Color.Yellow;
        public static readonly Color TouchEventVisualizerPointColor = Color.Red;
        public static readonly Color TouchEventVisualizerGridColor = Color.White;

        public static readonly Color PalmQuadColor = Color.Blue;
        public static readonly Color PalmGridColor = Color.CornflowerBlue;
        public static readonly Color PalmConturColor = Color.Red;
        public static readonly Color PalmConvexHullColor = Color.Green;
        public static readonly Color PalmThumbDefectColor = Color.Lime;

        public static readonly Color HandRightColor = Color.Red;
        public static readonly Color HandLeftColor = Color.Blue;
    }
}
