Exemplo n.º 1
0
        private int BinSearchSaturation(int hueIndex, double satKey)
        {
            int low  = 0;
            int high = subTreesHue[hueIndex].subTreesSaturation.Count - 1;

            while (low <= high)
            {
                int     mid    = low + high >> 1;
                SatTree midVal = subTreesHue[hueIndex].
                                 subTreesSaturation[mid];

                if (midVal.Magnitude < satKey)
                {
                    low = mid + 1;
                }
                else if (midVal.Magnitude > satKey)
                {
                    high = mid - 1;
                }
                else
                {
                    return(mid);
                }
            }
            return(-1);
        }
Exemplo n.º 2
0
        private void PopulateTree(double hue, double saturation, double value, int frequency)
        {
            if (subTreesHue.Exists(bt => bt.Magnitude == hue))
            {
                int indexHue = subTreesHue.FindIndex(bt => bt.Magnitude == hue);

                // next find if the specific green exists in a subtree of blue
                // such that Gn | Bn

                if (subTreesHue[indexHue].subTreesSaturation.
                    Exists(gt => gt.Magnitude == saturation))
                {
                    int      indexSat = subTreesHue[indexHue].subTreesSaturation.FindIndex(gt => gt.Magnitude == saturation);
                    ValueFIP valueFIP = new ValueFIP();
                    valueFIP.Magnitude = value;
                    valueFIP.Frequency = frequency;
                    subTreesHue[indexHue].subTreesSaturation[indexSat].valueNodes.Add(valueFIP);
                }
                else
                {
                    SatTree st = new SatTree();
                    st.Magnitude = saturation;
                    ValueFIP valueFIP = new ValueFIP();
                    valueFIP.Magnitude = value;
                    valueFIP.Frequency = frequency;

                    st.valueNodes.Add(valueFIP);
                    subTreesHue[indexHue].subTreesSaturation.Add(st);
                }
            }
            else
            {
                HueTree  ht       = new HueTree();
                SatTree  st       = new SatTree();
                ValueFIP valueFIP = new ValueFIP();

                valueFIP.Magnitude = value;
                valueFIP.Frequency = frequency;

                st.Magnitude = saturation;
                ht.Magnitude = hue;

                st.valueNodes.Add(valueFIP);
                ht.subTreesSaturation.Add(st);
                subTreesHue.Add(ht);
            }
        }