Пример #1
0
        void UpdateSlidersInfo(PatternPoint pp)
        {
            switch (SelectedSlider.SliderType)
            {
            case SliderTypeEnum.RGB:
                hueValue.Content   = Math.Round(hueSlider.Value).ToString();
                rValue.Content     = pp.PointColor.R.ToString();
                satValue.Content   = Math.Round(satSlider.Value * 100).ToString();
                gValue.Content     = pp.PointColor.G.ToString();
                lightValue.Content = Math.Round(lightSlider.Value * 100).ToString();
                bValue.Content     = pp.PointColor.B.ToString();
                break;

            case SliderTypeEnum.W:
                whiteValue.Content = Convert.ToInt32(pp.WhiteD * 255.0).ToString();
                break;

            case SliderTypeEnum.WT:
                whiteValue.Content = Convert.ToInt32(pp.WhiteD * 255.0).ToString();
                tempValue.Content  = Convert.ToInt32(pp.Temp * 9000.0 + 1000.0).ToString();
                break;

            case SliderTypeEnum.Warm:
                warmValue.Content = Convert.ToInt32(pp.WarmD * 255.0).ToString();
                break;

            case SliderTypeEnum.Cold:
                coldValue.Content = Convert.ToInt32(pp.ColdD * 255.0).ToString();
                break;
            }
        }
Пример #2
0
        public PatternPoint FindPattern()
        {
            PatternPoint ret = new PatternPoint();

            for (int i = 0; i < PointCount; i++)
            {
                IntPoint cPoint   = PointList[i];
                int      hindex   = 1;
                int      k1       = 0;
                Double   Distance = 0;

                while (k1 < cPoint.Dists.Length && cPoint.Dists[k1] == 0)
                {
                    k1++;
                }

                IntPoint sPoint = PointList[cPoint.Neighbors[k1]];

                for (int j = 0; j < 6; j++)
                {
                    for (int k2 = 0; k2 < cPoint.Dists.Length; k2++)
                    {
                        if (cPoint.Dists[k2] > 0)
                        {
                            for (int k3 = 0; k3 < sPoint.Dists.Length; k3++)
                            {
                                if (sPoint.Dists[k3] > 0 && (sPoint.Neighbors[k3] == cPoint.Neighbors[k2]))
                                {
                                    IntPoint s2Point = PointList[cPoint.Neighbors[k2]];

                                    int kp = (sPoint.X - cPoint.X) * (s2Point.Y - cPoint.Y) - (s2Point.X - cPoint.X) * (sPoint.Y - cPoint.Y);

                                    if (kp > 0)
                                    {
                                        //System.Diagnostics.Debug.WriteLine(i + ": " + IntPointDist(cPoint, s2Point) + " -- " + IntPointDist(sPoint, s2Point) + " -- " + kp);
                                        Distance          += PointDist(cPoint, s2Point);
                                        ret.Points[hindex] = sPoint;
                                        hindex++;
                                        sPoint = s2Point;
                                    }

                                    if (hindex > 6)
                                    {
                                        ret.AverageDistance = Distance / 6;
                                        ret.Points[0]       = cPoint;
                                        return(ret);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Пример #3
0
        SliderItem CreateSlider(int value, int max, PatternPoint point)
        {
            SliderItem si = new SliderItem();

            si.PatternPoint   = point;
            si.Minimum        = 1;
            si.Maximum        = max;
            si.SelectionStart = 1;
            si.SelectionEnd   = max;
            si.Value          = value;
            return(si);
        }
Пример #4
0
    void nextPatternPoint()
    {
        if (currPatternPointIndex >= PatternPointList.Count - 1)
        {
            currPatternPointIndex = 0;
        }
        else
        {
            currPatternPointIndex++;
        }

        currPatternPoint = PatternPointList[currPatternPointIndex].GetComponent <PatternPoint>();
    }
Пример #5
0
        void ParsePatternParams(PointTypeEnum pointType, string profile)
        {
            XElement basePoints1 = null;
            XElement basePoints2 = null;


            XElement root       = XElement.Parse(profile);
            int      pointCount = int.Parse(root.Attribute("PointCount").Value);

            PointCount = pointCount;
            Pattern    = new PatternPoint[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                Pattern[i] = new PatternPoint();
            }

            switch (pointType)
            {
            case PointTypeEnum.RGB:
                basePoints1 = root.Elements("RGB").First();
                break;

            case PointTypeEnum.RGBW:
                basePoints1 = root.Elements().First(p => p.Name == "RGB");
                basePoints2 = root.Elements().First(p => p.Name == "White");
                break;

            case PointTypeEnum.RGBWT:
                basePoints1 = root.Elements().First(p => p.Name == "RGB");
                basePoints2 = root.Elements().First(p => p.Name == "WhiteTemp");
                break;

            case PointTypeEnum.CW:
                basePoints1 = root.Elements().First(p => p.Name == "Warm");
                basePoints2 = root.Elements().First(p => p.Name == "Cold");
                break;

            case PointTypeEnum.WT:
                basePoints1 = root.Elements().First(p => p.Name == "WhiteTemp");
                break;

            case PointTypeEnum.W:
                basePoints1 = root.Elements().First(p => p.Name == "White");
                break;
            }

            CreateSliderList(basePoints1, UpSliderList);
            CreateSliderList(basePoints2, DownSliderList);
        }
Пример #6
0
        public void CircleDiameterStat(ImageRec DestImageData, PatternPoint Item)
        {
            int dist;
            int dy     = 0;
            int dx     = 0;
            int iy     = 0;
            int ix     = 0;
            int slope2 = 0;

            int[] LineBuffer = new int[48];

            int SquareRadius = (int)Item.AverageDistance / 2;

            for (int i = 0; i < Item.Points.Length; i++)
            {
                int CountSum = 0;

                for (int x = -SquareRadius; x < SquareRadius; x++)
                {
                    ix = Item.Points[i].X + x;

                    for (int y = -SquareRadius; y < SquareRadius; y++)
                    {
                        iy = Item.Points[i].Y + y;

                        if (iy > 0 && ix > 0 && iy < Height - 1 && ix < Width - 1)
                        {
                            dx = PrimarryBuffer[GetIndex(ix, iy)];
                            dy = SecondaryBuffer[GetIndex(ix, iy)];

                            slope2 = (dx * dx) + (dy * dy);

                            if (slope2 > (256 * 256 * 16))
                            {
                                dist = Isqrt(x * x + y * y);

                                if (dist < SquareRadius)
                                {
                                    DestImageData.PrimarryBuffer[DestImageData.GetIndex(dist * 16 / SquareRadius, i * 2)] += (128 / (dist + 1));
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #7
0
        private void build(int octaves, float scale)
        {
            lookupTable = new PatternPoint[Scales * Orientations * Points];

            double scaleStep = Math.Pow(2.0, (double)(octaves) / Scales);

            step = (float)(Scales / (Constants.Log2 * octaves));

            // pattern definition, radius normalized to 1.0 (outer point position + sigma = 1.0)

            // number of points on each concentric circle (from outer to inner)
            int[] n = { 6, 6, 6, 6, 6, 6, 6, 1 };

            double bigR   = 2.0 / 3.0;                   // bigger radius
            double smallR = 2.0 / 24.0;                  // smaller radius

            double unitSpace = ((bigR - smallR) / 21.0); // define spaces between concentric circles (from center to outer: 1,2,3,4,5,6)

            double[] radius =
            {
                bigR,                  bigR - 6 * unitSpace, // radii of the concentric circles (from outer to inner)
                bigR - 11 * unitSpace, bigR - 15 * unitSpace,
                bigR - 18 * unitSpace, bigR - 20 * unitSpace,
                smallR, 0.0
            };

            double[] sigma =
            {
                radius[0] / 2.0, radius[1] / 2.0,
                radius[2] / 2.0, radius[3] / 2.0,  // sigma of the pattern points (each group of 6
                radius[4] / 2.0, radius[5] / 2.0,  //  points on a concentric circle has same sigma)
                radius[6] / 2.0, radius[6] / 2.0
            };


            // fill the lookup table
            for (int scaleIdx = 0; scaleIdx < Scales; scaleIdx++)
            {
                patternSizes[scaleIdx] = 0;
                double scalingFactor = Math.Pow(scaleStep, scaleIdx);

                for (int orientationIdx = 0; orientationIdx < Orientations; orientationIdx++)
                {
                    // orientation of the pattern
                    double theta    = orientationIdx * 2 * Math.PI / Orientations;
                    int    pointIdx = 0;

                    for (int i = 0; i < 8; i++)
                    {
                        for (int k = 0; k < n[i]; k++)
                        {
                            // Compute orientation offset so that groups
                            // of points on each circles become staggered
                            //
                            double beta  = Math.PI / n[i] * (i % 2);
                            double alpha = k * 2 * Math.PI / n[i] + beta + theta;

                            // Add the point to the pattern look-up table
                            var point = new PatternPoint(
                                (float)(radius[i] * Math.Cos(alpha) * scalingFactor * scale),
                                (float)(radius[i] * Math.Sin(alpha) * scalingFactor * scale),
                                (float)(sigma[i] * scalingFactor * scale));

                            lookupTable[scaleIdx * Orientations * Points
                                        + orientationIdx * Points + pointIdx] = point;

                            // adapt the sizeList if necessary
                            int sizeMax = (int)Math.Ceiling((radius[i] + sigma[i]) * scalingFactor * scale) + 1;
                            if (patternSizes[scaleIdx] < sizeMax)
                            {
                                patternSizes[scaleIdx] = sizeMax;
                            }

                            pointIdx++;
                        }
                    }
                }
            }

            // build the list of orientation pairs
            orientationPairs[0].i = 0; orientationPairs[0].j = 3; orientationPairs[1].i = 1; orientationPairs[1].j = 4; orientationPairs[2].i = 2; orientationPairs[2].j = 5;
            orientationPairs[3].i = 0; orientationPairs[3].j = 2; orientationPairs[4].i = 1; orientationPairs[4].j = 3; orientationPairs[5].i = 2; orientationPairs[5].j = 4;
            orientationPairs[6].i = 3; orientationPairs[6].j = 5; orientationPairs[7].i = 4; orientationPairs[7].j = 0; orientationPairs[8].i = 5; orientationPairs[8].j = 1;

            orientationPairs[9].i  = 6; orientationPairs[9].j = 9; orientationPairs[10].i = 7; orientationPairs[10].j = 10; orientationPairs[11].i = 8; orientationPairs[11].j = 11;
            orientationPairs[12].i = 6; orientationPairs[12].j = 8; orientationPairs[13].i = 7; orientationPairs[13].j = 9; orientationPairs[14].i = 8; orientationPairs[14].j = 10;
            orientationPairs[15].i = 9; orientationPairs[15].j = 11; orientationPairs[16].i = 10; orientationPairs[16].j = 6; orientationPairs[17].i = 11; orientationPairs[17].j = 7;

            orientationPairs[18].i = 12; orientationPairs[18].j = 15; orientationPairs[19].i = 13; orientationPairs[19].j = 16; orientationPairs[20].i = 14; orientationPairs[20].j = 17;
            orientationPairs[21].i = 12; orientationPairs[21].j = 14; orientationPairs[22].i = 13; orientationPairs[22].j = 15; orientationPairs[23].i = 14; orientationPairs[23].j = 16;
            orientationPairs[24].i = 15; orientationPairs[24].j = 17; orientationPairs[25].i = 16; orientationPairs[25].j = 12; orientationPairs[26].i = 17; orientationPairs[26].j = 13;

            orientationPairs[27].i = 18; orientationPairs[27].j = 21; orientationPairs[28].i = 19; orientationPairs[28].j = 22; orientationPairs[29].i = 20; orientationPairs[29].j = 23;
            orientationPairs[30].i = 18; orientationPairs[30].j = 20; orientationPairs[31].i = 19; orientationPairs[31].j = 21; orientationPairs[32].i = 20; orientationPairs[32].j = 22;
            orientationPairs[33].i = 21; orientationPairs[33].j = 23; orientationPairs[34].i = 22; orientationPairs[34].j = 18; orientationPairs[35].i = 23; orientationPairs[35].j = 19;

            orientationPairs[36].i = 24; orientationPairs[36].j = 27; orientationPairs[37].i = 25; orientationPairs[37].j = 28; orientationPairs[38].i = 26; orientationPairs[38].j = 29;
            orientationPairs[39].i = 30; orientationPairs[39].j = 33; orientationPairs[40].i = 31; orientationPairs[40].j = 34; orientationPairs[41].i = 32; orientationPairs[41].j = 35;
            orientationPairs[42].i = 36; orientationPairs[42].j = 39; orientationPairs[43].i = 37; orientationPairs[43].j = 40; orientationPairs[44].i = 38; orientationPairs[44].j = 41;

            for (int m = 0; m < orientationPairs.Length; m++)
            {
                float dx      = lookupTable[orientationPairs[m].i].x - lookupTable[orientationPairs[m].j].x;
                float dy      = lookupTable[orientationPairs[m].i].y - lookupTable[orientationPairs[m].j].y;
                float norm_sq = (dx * dx + dy * dy);
                orientationPairs[m].weight_dx = (int)((dx / (norm_sq)) * 4096.0 + 0.5);
                orientationPairs[m].weight_dy = (int)((dy / (norm_sq)) * 4096.0 + 0.5);
            }

            // build the list of description pairs
            var allPairs = new List <DescriptionPair>();

            for (int i = 1; i < Points; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    allPairs.Add(new DescriptionPair(i, j));
                }
            }

            // default selected pairs
            for (int i = 0; i < descriptionPairs.Length; i++)
            {
                descriptionPairs[i] = allPairs[CV_FREAK_DEF_PAIRS[i]];
            }
        }
Пример #8
0
        private void OnTrackClick(object sender, MouseButtonEventArgs e)
        {
            SliderItem newSlider = null;

            if (e.ClickCount == 2)      // DoubleClick
            {
                if (e.Source is Border && (e.Source as Border).Name == "PART_Track")
                {
                    System.Windows.Point pt = e.GetPosition((UIElement)sender);
                    double halfStep         = (slidersArea.ActualWidth + 2 * Margin.Left) / this.Maxlimit;
                    int    sliderPos        = Convert.ToInt32(pt.X / halfStep) + 1;
                    //Console.WriteLine($"ActualWidth + Margin {slidersArea.ActualWidth + 2 * this.Margin.Left}");
                    //Console.WriteLine($"ptX {pt.X}");
                    //Console.WriteLine($"LedPos: {sliderPos}");
                    //Console.WriteLine($"CurrentMode: {AddMode}");

                    // AddMode = 0 Gradient
                    // AddMode = 1 Range
                    // AddMode = 2 Lightness

                    PatternPoint pp = Pattern[sliderPos - 1];

                    // нельзя добавить слайдер в существующую позицию
                    if (SliderList.FirstOrDefault(p => p.Value == (double)sliderPos) != null)
                    {
                        return;
                    }

                    // если первая точка в Pattern
                    if (sliderPos < SliderList[0].Value)
                    {
                        SliderItem tmpSi = SliderList[0];
                        switch (AddMode)
                        {
                        case 1:       //Range
                            SliderList[0].PatternPoint.CopyTo(pp, SliderList[0].SliderType);
                            SliderItem rangeLeft = CreateSlider(sliderPos, Maxlimit, pp);
                            rangeLeft.Variant = PointVariant.RangeLeft;
                            newSlider         = rangeLeft;
                            SliderItem rangeRight = CreateSlider(sliderPos, Maxlimit, pp);
                            rangeRight.Variant = PointVariant.RangeRight;
                            SliderList.Insert(0, rangeRight);
                            SliderList.Insert(0, rangeLeft);
                            ReArrangeSliderItems();
                            UpdatePatternCommand.Execute(rangeRight);
                            break;

                        case 2:         //Lightness
                            break;

                        default:        //Gradient
                            SliderList[0].PatternPoint.CopyTo(pp, SliderList[0].SliderType);
                            SliderItem gradient = CreateSlider(sliderPos, Maxlimit, pp);
                            newSlider = gradient;
                            SliderList.Insert(0, gradient);
                            ReArrangeSliderItems();
                            UpdatePatternCommand.Execute(gradient);
                            break;
                        }
                        if (newSlider != null)
                        {
                            if (SelectedSlider != null)
                            {
                                SelectedSlider.IsSelected = false;
                            }
                            newSlider.IsSelected = true;
                            SelectedSlider       = newSlider;
                        }
                        return;
                    }

                    // если последняя точка в Pattern
                    if (sliderPos > SliderList[SliderList.Count - 1].Value)
                    {
                        SliderItem lastSi = SliderList[SliderList.Count - 1];
                        switch (AddMode)
                        {
                        case 1:         // Range
                            SliderList[SliderList.Count - 1].PatternPoint.CopyTo(pp, SliderList[0].SliderType);
                            SliderItem rangeLeft = CreateSlider(sliderPos, Maxlimit, pp);
                            rangeLeft.Variant = PointVariant.RangeLeft;
                            SliderItem rangeRight = CreateSlider(sliderPos, Maxlimit, pp);
                            rangeRight.Variant = PointVariant.RangeRight;
                            SliderList.Add(rangeLeft);
                            SliderList.Add(rangeRight);
                            ReArrangeSliderItems();
                            UpdatePatternCommand.Execute(rangeLeft);
                            break;

                        case 2:         //Lightness
                            break;

                        default:        //Gradient
                            SliderList[SliderList.Count - 1].PatternPoint.CopyTo(pp, SliderList[0].SliderType);
                            SliderItem gradient = CreateSlider(sliderPos, Maxlimit, pp);
                            SliderList.Add(gradient);
                            ReArrangeSliderItems();

                            UpdatePatternCommand.Execute(gradient);

                            break;
                        }
                        return;
                    }

                    // точка между PatternPoint
                    SliderItem prevSi   = null;
                    SliderItem nextSi   = null;
                    int        minLeft  = Maxlimit;
                    int        minRight = Maxlimit;
                    foreach (SliderItem si in SliderList)
                    {
                        if (si.Value > sliderPos)
                        {
                            if ((si.Value - sliderPos) < minRight)
                            {
                                minRight = (int)si.Value - sliderPos;
                                nextSi   = si;
                            }
                        }

                        if (si.Value < sliderPos)
                        {
                            if ((sliderPos - si.Value) < minLeft)
                            {
                                minLeft = sliderPos - (int)si.Value;
                                prevSi  = si;
                            }
                        }
                    }
                    // нельзя добавить точку внутри Range
                    if (nextSi.Variant == PointVariant.RangeRight)
                    {
                        return;
                    }

                    newSlider = CreateSlider(sliderPos, Maxlimit, Pattern[sliderPos - 1]);
                    int ix = SliderList.IndexOf(nextSi);
                    if (AddMode == 1)
                    {
                        newSlider.Variant = PointVariant.RangeLeft;
                        SliderItem rangeRight = CreateSlider(sliderPos, Maxlimit, Pattern[sliderPos - 1]);
                        rangeRight.Variant = PointVariant.RangeRight;
                        SliderList.Insert(ix, rangeRight);
                        SliderList.Insert(ix, newSlider);
                        ReArrangeSliderItems();
                        if (newSlider != null)
                        {
                            if (SelectedSlider != null)
                            {
                                SelectedSlider.IsSelected = false;
                            }
                            newSlider.IsSelected = true;
                            SelectedSlider       = newSlider;
                        }
                        return;
                    }
                    if (AddMode == 2)
                    {
                        newSlider.Variant = PointVariant.Lightness;
                        newSlider.PatternPoint.SaveLightness();
                    }
                    SliderList.Insert(ix, newSlider);
                    ReArrangeSliderItems();
                    if (newSlider != null)
                    {
                        if (SelectedSlider != null)
                        {
                            SelectedSlider.IsSelected = false;
                        }
                        newSlider.IsSelected = true;
                        SelectedSlider       = newSlider;
                    }
                }
            }
        }
Пример #9
0
        //int currentIx;
        private void OnSliderPositionChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            SliderItem si = (SliderItem)sender;

            Position = si.Pos;
            int newValue = Convert.ToInt32(e.NewValue);

            PatternPoint pp = Pattern[newValue - 1];

            if (si.Variant == PointVariant.Lightness)
            {
                switch (si.SliderType)
                {
                case SliderTypeEnum.RGB:
                    pp.L = si.PatternPoint.L;
                    pp.SaveLightness();
                    pp.UpdatePoint_RGB();
                    break;

                case SliderTypeEnum.W:
                case SliderTypeEnum.WT:
                    pp.WhiteD        = si.PatternPoint.WhiteD;
                    pp.InitialWhiteD = pp.WhiteD;
                    break;

                case SliderTypeEnum.Warm:
                    pp.WarmD        = si.PatternPoint.WarmD;
                    pp.InitialWarmD = pp.WarmD;
                    break;

                case SliderTypeEnum.Cold:
                    pp.ColdD        = si.PatternPoint.ColdD;
                    pp.InitialColdD = pp.ColdD;
                    break;
                }

                //Console.WriteLine($"DeltaT: {pp.Temp - si.PatternPoint.Temp}");

                si.PatternPoint = pp;
                UpdatePatternCommand.Execute(si);

                // для обновления ColorPanel
                SelectedSlider = null;
                SelectedSlider = si;

                return;
            }
            else
            {
                switch (si.SliderType)
                {
                case SliderTypeEnum.RGB:
                    si.PatternPoint.CopyTo(pp, si.SliderType);
                    break;

                case SliderTypeEnum.W:
                    si.PatternPoint.CopyTo(pp, si.SliderType);
                    break;

                case SliderTypeEnum.WT:
                    si.PatternPoint.CopyTo(pp, si.SliderType);
                    break;

                case SliderTypeEnum.Warm:
                    si.PatternPoint.CopyTo(pp, si.SliderType);
                    break;

                case SliderTypeEnum.Cold:
                    si.PatternPoint.CopyTo(pp, si.SliderType);
                    break;
                }
            }

            si.PatternPoint = pp;
            UpdatePatternCommand.Execute(si);
        }
Пример #10
0
        public FastRetinaKeypointPattern(int octaves = 4, float scale = 22.0f)
        {
            this.Octaves = octaves;
            this.Scale = scale;

            lookupTable = new PatternPoint[Scales * Orientations * Points];

            double scaleStep = Math.Pow(2.0, (double)(octaves) / Scales);
            step = (float)(Scales / (Constants.Log2 * octaves));

            // pattern definition, radius normalized to 1.0 (outer point position + sigma = 1.0)

            // number of points on each concentric circle (from outer to inner)
            int[] n = { 6, 6, 6, 6, 6, 6, 6, 1 };

            double bigR = 2.0 / 3.0;    // bigger radius
            double smallR = 2.0 / 24.0; // smaller radius

            double unitSpace = ((bigR - smallR) / 21.0); // define spaces between concentric circles (from center to outer: 1,2,3,4,5,6)

            double[] radius = 
            {
                bigR, bigR - 6 * unitSpace, // radii of the concentric cirles (from outer to inner)
                bigR - 11 * unitSpace, bigR - 15 * unitSpace,
                bigR - 18 * unitSpace, bigR - 20 * unitSpace,
                smallR, 0.0
            };

            double[] sigma = 
            {         
                radius[0]/2.0, radius[1]/2.0, 
                radius[2]/2.0, radius[3]/2.0,  // sigma of the pattern points (each group of 6 
                radius[4]/2.0, radius[5]/2.0,  //  points on a concentric cirle has same sigma)
                radius[6]/2.0, radius[6]/2.0
            };


            // fill the lookup table
            for (int scaleIdx = 0; scaleIdx < Scales; scaleIdx++)
            {
                patternSizes[scaleIdx] = 0;
                double scalingFactor = Math.Pow(scaleStep, scaleIdx);

                for (int orientationIdx = 0; orientationIdx < Orientations; orientationIdx++)
                {
                    // orientation of the pattern
                    double theta = orientationIdx * 2 * Math.PI / Orientations;
                    int pointIdx = 0;

                    for (int i = 0; i < 8; i++)
                    {
                        for (int k = 0; k < n[i]; k++)
                        {
                            // Compute orientation offset so that groups
                            // of points on each circles become staggered
                            //
                            double beta = Math.PI / n[i] * (i % 2);
                            double alpha = k * 2 * Math.PI / n[i] + beta + theta;

                            // Add the point to the pattern look-up table
                            var point = new PatternPoint(
                                (float)(radius[i] * Math.Cos(alpha) * scalingFactor * scale),
                                (float)(radius[i] * Math.Sin(alpha) * scalingFactor * scale),
                                (float)(sigma[i] * scalingFactor * scale));

                            lookupTable[scaleIdx * Orientations * Points
                                + orientationIdx * Points + pointIdx] = point;

                            // adapt the sizeList if necessary
                            int sizeMax = (int)Math.Ceiling((radius[i] + sigma[i]) * scalingFactor * scale) + 1;
                            if (patternSizes[scaleIdx] < sizeMax)
                                patternSizes[scaleIdx] = sizeMax;

                            pointIdx++;
                        }
                    }
                }
            }

            // build the list of orientation pairs
            orientationPairs[0].i = 0; orientationPairs[0].j = 3; orientationPairs[1].i = 1; orientationPairs[1].j = 4; orientationPairs[2].i = 2; orientationPairs[2].j = 5;
            orientationPairs[3].i = 0; orientationPairs[3].j = 2; orientationPairs[4].i = 1; orientationPairs[4].j = 3; orientationPairs[5].i = 2; orientationPairs[5].j = 4;
            orientationPairs[6].i = 3; orientationPairs[6].j = 5; orientationPairs[7].i = 4; orientationPairs[7].j = 0; orientationPairs[8].i = 5; orientationPairs[8].j = 1;

            orientationPairs[9].i = 6; orientationPairs[9].j = 9; orientationPairs[10].i = 7; orientationPairs[10].j = 10; orientationPairs[11].i = 8; orientationPairs[11].j = 11;
            orientationPairs[12].i = 6; orientationPairs[12].j = 8; orientationPairs[13].i = 7; orientationPairs[13].j = 9; orientationPairs[14].i = 8; orientationPairs[14].j = 10;
            orientationPairs[15].i = 9; orientationPairs[15].j = 11; orientationPairs[16].i = 10; orientationPairs[16].j = 6; orientationPairs[17].i = 11; orientationPairs[17].j = 7;

            orientationPairs[18].i = 12; orientationPairs[18].j = 15; orientationPairs[19].i = 13; orientationPairs[19].j = 16; orientationPairs[20].i = 14; orientationPairs[20].j = 17;
            orientationPairs[21].i = 12; orientationPairs[21].j = 14; orientationPairs[22].i = 13; orientationPairs[22].j = 15; orientationPairs[23].i = 14; orientationPairs[23].j = 16;
            orientationPairs[24].i = 15; orientationPairs[24].j = 17; orientationPairs[25].i = 16; orientationPairs[25].j = 12; orientationPairs[26].i = 17; orientationPairs[26].j = 13;

            orientationPairs[27].i = 18; orientationPairs[27].j = 21; orientationPairs[28].i = 19; orientationPairs[28].j = 22; orientationPairs[29].i = 20; orientationPairs[29].j = 23;
            orientationPairs[30].i = 18; orientationPairs[30].j = 20; orientationPairs[31].i = 19; orientationPairs[31].j = 21; orientationPairs[32].i = 20; orientationPairs[32].j = 22;
            orientationPairs[33].i = 21; orientationPairs[33].j = 23; orientationPairs[34].i = 22; orientationPairs[34].j = 18; orientationPairs[35].i = 23; orientationPairs[35].j = 19;

            orientationPairs[36].i = 24; orientationPairs[36].j = 27; orientationPairs[37].i = 25; orientationPairs[37].j = 28; orientationPairs[38].i = 26; orientationPairs[38].j = 29;
            orientationPairs[39].i = 30; orientationPairs[39].j = 33; orientationPairs[40].i = 31; orientationPairs[40].j = 34; orientationPairs[41].i = 32; orientationPairs[41].j = 35;
            orientationPairs[42].i = 36; orientationPairs[42].j = 39; orientationPairs[43].i = 37; orientationPairs[43].j = 40; orientationPairs[44].i = 38; orientationPairs[44].j = 41;

            for (int m = 0; m < orientationPairs.Length; m++)
            {
                float dx = lookupTable[orientationPairs[m].i].x - lookupTable[orientationPairs[m].j].x;
                float dy = lookupTable[orientationPairs[m].i].y - lookupTable[orientationPairs[m].j].y;
                float norm_sq = (dx * dx + dy * dy);
                orientationPairs[m].weight_dx = (int)((dx / (norm_sq)) * 4096.0 + 0.5);
                orientationPairs[m].weight_dy = (int)((dy / (norm_sq)) * 4096.0 + 0.5);
            }

            // build the list of description pairs
            var allPairs = new List<DescriptionPair>();
            for (int i = 1; i < Points; i++)
                for (int j = 0; j < i; j++)
                    allPairs.Add(new DescriptionPair(i, j));

            // default selected pairs
            for (int i = 0; i < descriptionPairs.Length; i++)
                descriptionPairs[i] = allPairs[CV_FREAK_DEF_PAIRS[i]];
        }
Пример #11
0
        public int GetPatternData(PatternPoint Item)
        {
            int dist;
            int dy     = 0;
            int dx     = 0;
            int iy     = 0;
            int ix     = 0;
            int slope2 = 0;
            int ret    = 0;

            const int bitCount = 4;

            int SquareRadius = (int)Item.AverageDistance / 2;

            for (int i = 0; i < Item.Points.Length; i++)
            {
                int   CountSum   = 0;
                int[] LineBuffer = new int[bitCount];
                bool  lastBit    = false;

                for (int x = -SquareRadius; x < SquareRadius; x++)
                {
                    ix = Item.Points[i].X + x;

                    for (int y = -SquareRadius; y < SquareRadius; y++)
                    {
                        iy = Item.Points[i].Y + y;

                        if (iy > 0 && ix > 0 && iy < Height - 1 && ix < Width - 1)
                        {
                            dx = PrimarryBuffer[GetIndex(ix, iy)];
                            dy = SecondaryBuffer[GetIndex(ix, iy)];

                            slope2 = (dx * dx) + (dy * dy);

                            if (slope2 > (256 * 256 * 16))
                            {
                                dist = Isqrt(x * x + y * y);

                                if (dist < SquareRadius)
                                {
                                    int SumVal = (128 / (dist + 1));
                                    LineBuffer[dist * bitCount / SquareRadius] += SumVal;
                                    CountSum += SumVal;
                                }
                            }
                        }
                    }
                }

                CountSum /= bitCount * 2;

                for (int j = 3; j >= 0; j--)
                {
                    if (LineBuffer[j] > CountSum != lastBit)
                    {
                        ret    |= (1 << (24 - i * 4 + j));
                        lastBit = true;
                    }
                    else
                    {
                        lastBit = false;
                    }
                }
            }

            return(ret);
        }
Пример #12
0
        void CreateSliderList(XElement root, List <SliderItem> sliderList)
        {
            SliderTypeEnum sliderType = SliderTypeEnum.RGB;
            int            ix         = 0;

            if (root != null)
            {
                foreach (XElement basePoint in root.Elements("BasePoint"))
                {
                    int          Pos = int.Parse(basePoint.Attribute("Pos").Value);
                    PatternPoint pp  = Pattern[Pos - 1];
                    switch (root.Name.ToString())
                    {
                    case "RGB":
                        System.Drawing.Color color = System.Drawing.Color.FromArgb
                                                         (0,
                                                         int.Parse(basePoint.Attribute("R").Value),
                                                         int.Parse(basePoint.Attribute("G").Value),
                                                         int.Parse(basePoint.Attribute("B").Value)
                                                         );

                        pp   = Pattern[Pos - 1];
                        pp.H = color.GetHue();
                        pp.S = color.GetSaturation();
                        pp.L = color.GetBrightness();
                        pp.SaveLightness();
                        pp.PointColor = Color.FromRgb(color.R, color.G, color.B);
                        pp.Lightness  = Convert.ToInt32(pp.L * 255.0);
                        sliderType    = SliderTypeEnum.RGB;
                        break;

                    case "White":
                        pp.WhiteD        = double.Parse(basePoint.Attribute("W").Value);
                        pp.InitialWhiteD = pp.WhiteD;
                        sliderType       = SliderTypeEnum.W;
                        break;

                    case "WhiteTemp":
                        pp.WhiteD        = double.Parse(basePoint.Attribute("W").Value);
                        pp.InitialWhiteD = pp.WhiteD;
                        pp.Temp          = double.Parse(basePoint.Attribute("T").Value);
                        sliderType       = SliderTypeEnum.WT;
                        break;

                    case "Warm":
                        pp.WarmD        = double.Parse(basePoint.Attribute("W").Value);
                        pp.InitialWarmD = pp.WarmD;
                        sliderType      = SliderTypeEnum.Warm;
                        break;

                    case "Cold":
                        pp.ColdD        = double.Parse(basePoint.Attribute("W").Value);
                        pp.InitialColdD = pp.ColdD;
                        sliderType      = SliderTypeEnum.Cold;
                        break;
                    }

                    sliderList.Add(CreateSlider(sliderList, ix, Pos, (PointVariant)int.Parse(basePoint.Attribute("Variant").Value), sliderType));
                    ix++;
                }
            }
        }
Пример #13
0
 // Use this for initialization
 void Start()
 {
     rigid            = gameObject.GetComponent <Rigidbody2D>();
     anim             = gameObject.GetComponent <Animator>();
     currPatternPoint = PatternPointList[currPatternPointIndex].GetComponent <PatternPoint>();
 }
Пример #14
0
        void BuildGradient(SliderItem leftSlider, SliderItem rightSlider)
        {
            int leftIx    = Convert.ToInt32(leftSlider.Value);
            int rightIx   = Convert.ToInt32(rightSlider.Value);
            int stepCount = rightIx - leftIx;

            switch (leftSlider.SliderType)
            {
            case SliderTypeEnum.RGB:
                double deltaH, deltaS, deltaL;
                if (stepCount > 0)
                {
                    deltaH = (rightSlider.PatternPoint.H - leftSlider.PatternPoint.H) / stepCount;
                    deltaS = (rightSlider.PatternPoint.S - leftSlider.PatternPoint.S) / stepCount;
                    deltaL = (rightSlider.PatternPoint.L - leftSlider.PatternPoint.L) / stepCount;
                    for (int i = leftIx + 1; i < rightIx; i++)
                    {
                        PatternPoint pp = Pattern[i - 1 - 1];
                        Pattern[i - 1].SetPoint_HSL(pp.H + deltaH, pp.S + deltaS, pp.L + deltaL);
                    }
                }
                break;

            case SliderTypeEnum.W:
                double deltaWhite;
                {
                    if (stepCount > 0)
                    {
                        deltaWhite = (rightSlider.PatternPoint.WhiteD - leftSlider.PatternPoint.WhiteD) / stepCount;
                        for (int i = leftIx + 1; i < rightIx; i++)
                        {
                            PatternPoint pp = Pattern[i - 1 - 1];
                            Pattern[i - 1].WhiteD = pp.WhiteD + deltaWhite;
                        }
                    }
                }
                break;

            case SliderTypeEnum.WT:
                double deltaTemp;
                {
                    if (stepCount > 0)
                    {
                        deltaTemp  = (rightSlider.PatternPoint.Temp - leftSlider.PatternPoint.Temp) / stepCount;
                        deltaWhite = (rightSlider.PatternPoint.WhiteD - leftSlider.PatternPoint.WhiteD) / stepCount;

                        for (int i = leftIx + 1; i < rightIx; i++)
                        {
                            PatternPoint pp = Pattern[i - 1 - 1];
                            Pattern[i - 1].Temp   = pp.Temp + deltaTemp;
                            Pattern[i - 1].WhiteD = pp.WhiteD + deltaWhite;
                        }
                    }
                }
                break;

            case SliderTypeEnum.Cold:
                double deltaCold;
                {
                    if (stepCount > 0)
                    {
                        deltaCold = (rightSlider.PatternPoint.ColdD - leftSlider.PatternPoint.ColdD) / stepCount;
                        for (int i = leftIx + 1; i < rightIx; i++)
                        {
                            PatternPoint pp = Pattern[i - 1 - 1];
                            Pattern[i - 1].ColdD = pp.ColdD + deltaCold;
                        }
                    }
                }
                break;

            case SliderTypeEnum.Warm:
                double deltaWarm;
                {
                    if (stepCount > 0)
                    {
                        deltaWarm = (rightSlider.PatternPoint.WarmD - leftSlider.PatternPoint.WarmD) / stepCount;
                        for (int i = leftIx + 1; i < rightIx; i++)
                        {
                            PatternPoint pp = Pattern[i - 1 - 1];
                            Pattern[i - 1].WarmD = pp.WarmD + deltaWarm;
                        }
                    }
                }
                break;
            }
        }