Exemple #1
0
        // Split specified list of cubes into smaller cubes until the list gets the specified size
        private 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;
                }
            }
        }
Exemple #2
0
        private void SplitCubes(List <MedianCutCube> cubes, int count)
        {
            int num = cubes.Count - 1;

            while (cubes.Count < count)
            {
                MedianCutCube medianCutCube = cubes[num];
                MedianCutCube cube;
                MedianCutCube cube2;
                if (medianCutCube.RedSize >= medianCutCube.GreenSize && medianCutCube.RedSize >= medianCutCube.BlueSize)
                {
                    medianCutCube.SplitAtMedian(2, out cube, out cube2);
                }
                else if (medianCutCube.GreenSize >= medianCutCube.BlueSize)
                {
                    medianCutCube.SplitAtMedian(1, out cube, out cube2);
                }
                else
                {
                    medianCutCube.SplitAtMedian(0, out cube, out cube2);
                }
                cubes.RemoveAt(num);
                cubes.Insert(num, cube);
                cubes.Insert(num, cube2);
                if (--num < 0)
                {
                    num = cubes.Count - 1;
                }
            }
        }
        private void SplitCubes(List <MedianCutCube> cubes, int count)
        {
            int index = cubes.Count - 1;

            while (cubes.Count < count)
            {
                MedianCutCube cube2;
                MedianCutCube cube3;
                MedianCutCube cube = cubes[index];
                if ((cube.RedSize >= cube.GreenSize) && (cube.RedSize >= cube.BlueSize))
                {
                    cube.SplitAtMedian(2, out cube2, out cube3);
                }
                else if (cube.GreenSize >= cube.BlueSize)
                {
                    cube.SplitAtMedian(1, out cube2, out cube3);
                }
                else
                {
                    cube.SplitAtMedian(0, out cube2, out cube3);
                }
                cubes.RemoveAt(index);
                cubes.Insert(index, cube2);
                cubes.Insert(index, cube3);
                if (--index < 0)
                {
                    index = cubes.Count - 1;
                }
            }
        }
        public void SplitAtMedian(int rgbComponent, out MedianCutCube cube1, out MedianCutCube cube2)
        {
            switch (rgbComponent)
            {
            case 0:
                this.colors.Sort(new BlueComparer());
                break;

            case 1:
                this.colors.Sort(new GreenComparer());
                break;

            case 2:
                this.colors.Sort(new RedComparer());
                break;
            }
            int count = this.colors.Count / 2;

            cube1 = new MedianCutCube(this.colors.GetRange(0, count));
            cube2 = new MedianCutCube(this.colors.GetRange(count, this.colors.Count - count));
        }
Exemple #5
0
        public void SplitAtMedian(int rgbComponent, out MedianCutCube cube1, out MedianCutCube cube2)
        {
            switch (rgbComponent)
            {
            case 2:
                colors.Sort(new RedComparer());
                break;

            case 1:
                colors.Sort(new GreenComparer());
                break;

            case 0:
                colors.Sort(new BlueComparer());
                break;
            }
            int num = colors.Count / 2;

            cube1 = new MedianCutCube(colors.GetRange(0, num));
            cube2 = new MedianCutCube(colors.GetRange(num, colors.Count - num));
        }
Exemple #6
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:
                this.colors.Sort(new RedComparer( ));
                break;

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

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

            var median = this.colors.Count / 2;

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