Пример #1
0
        // Split specified list of cubes into smaller cubes until the list gets the specified size
        private static void SplitCubes(List <MedianCutCube> cubes, int count)
        {
            int cubeIndexToSplit = cubes.Count - 1;

            while (cubes.Count < count)
            {
                MedianCutCube cubeToSplit = cubes[cubeIndexToSplit];
                MedianCutCube cube1, cube2;

                // find the longest color size to use for splitting
                if ((cubeToSplit.RedSize >= cubeToSplit.GreenSize) && (cubeToSplit.RedSize >= cubeToSplit.BlueSize))
                {
                    cubeToSplit.SplitAtMedian(RGB.R, out cube1, out cube2);
                }
                else if (cubeToSplit.GreenSize >= cubeToSplit.BlueSize)
                {
                    cubeToSplit.SplitAtMedian(RGB.G, out cube1, out cube2);
                }
                else
                {
                    cubeToSplit.SplitAtMedian(RGB.B, out cube1, out cube2);
                }

                // remove the old "big" cube
                cubes.RemoveAt(cubeIndexToSplit);
                // add two smaller cubes instead
                cubes.Insert(cubeIndexToSplit, cube1);
                cubes.Insert(cubeIndexToSplit, cube2);

                if (--cubeIndexToSplit < 0)
                {
                    cubeIndexToSplit = cubes.Count - 1;
                }
            }
        }
Пример #2
0
        // Split the cube into 2 smaller cubes using the specified color side for splitting
        public void SplitAtMedian(int rgbComponent, out MedianCutCube cube1, out MedianCutCube cube2)
        {
            switch (rgbComponent)
            {
            case RGB.R:
                colors.Sort(new RedComparer( ));
                break;

            case RGB.G:
                colors.Sort(new GreenComparer( ));
                break;

            case RGB.B:
                colors.Sort(new BlueComparer( ));
                break;
            }

            int median = colors.Count / 2;

            cube1 = new MedianCutCube(colors.GetRange(0, median));
            cube2 = new MedianCutCube(colors.GetRange(median, colors.Count - median));
        }