private IEnumerable <Box> SplitData(ref int colorCount, ColorData data) { --colorCount; var next = 0; var volumeVariance = new float[MaxColor]; var cubes = new Box[MaxColor]; cubes[0].AlphaMaximum = MaxSideIndex; cubes[0].RedMaximum = MaxSideIndex; cubes[0].GreenMaximum = MaxSideIndex; cubes[0].BlueMaximum = MaxSideIndex; for (var cubeIndex = 1; cubeIndex < colorCount; ++cubeIndex) { if (Cut(data, ref cubes[next], ref cubes[cubeIndex])) { volumeVariance[next] = cubes[next].Size > 1 ? CalculateVariance(data, cubes[next]) : 0.0f; volumeVariance[cubeIndex] = cubes[cubeIndex].Size > 1 ? CalculateVariance(data, cubes[cubeIndex]) : 0.0f; } else { volumeVariance[next] = 0.0f; cubeIndex--; } next = 0; var temp = volumeVariance[0]; for (var index = 1; index <= cubeIndex; ++index) { if (volumeVariance[index] <= temp) { continue; } temp = volumeVariance[index]; next = index; } if (temp > 0.0) { continue; } colorCount = cubeIndex + 1; break; } return(cubes.Take(colorCount).ToList()); }
private static Box[] SplitData(ref int colorCount, int maxColors, ColorMoment[, , ,] moments) { --colorCount; var next = 0; var volumeVariance = new float[maxColors]; var cubes = new Box[maxColors]; cubes[0].AlphaMaximum = MaxSideIndex; cubes[0].RedMaximum = MaxSideIndex; cubes[0].GreenMaximum = MaxSideIndex; cubes[0].BlueMaximum = MaxSideIndex; for (var cubeIndex = 1; cubeIndex < colorCount; ++cubeIndex) { if (Cut(moments, ref cubes[next], ref cubes[cubeIndex])) { volumeVariance[next] = cubes[next].Size > 1 ? CalculateVariance(moments, cubes[next]) : 0.0f; volumeVariance[cubeIndex] = cubes[cubeIndex].Size > 1 ? CalculateVariance(moments, cubes[cubeIndex]) : 0.0f; } else { volumeVariance[next] = 0.0f; cubeIndex--; } next = 0; var temp = volumeVariance[0]; for (var index = 1; index <= cubeIndex; ++index) { if (volumeVariance[index] <= temp) { continue; } temp = volumeVariance[index]; next = index; } if (temp > 0.0) { continue; } colorCount = cubeIndex + 1; break; } return(cubes.Take(colorCount).ToArray()); }
private static Box[] SplitData(ref int colorCount, int maxColors, ColorMoment[, , ,] moments) { --colorCount; var next = 0; var volumeVariance = new float[maxColors]; var cubes = new Box[maxColors]; cubes[0].AlphaMaximum = MaxSideIndex; cubes[0].RedMaximum = MaxSideIndex; cubes[0].GreenMaximum = MaxSideIndex; cubes[0].BlueMaximum = MaxSideIndex; for (var cubeIndex = 1; cubeIndex < colorCount; ++cubeIndex) { if (Cut(moments, ref cubes[next], ref cubes[cubeIndex])) { volumeVariance[next] = cubes[next].Size > 1 ? CalculateVariance(moments, cubes[next]) : 0.0f; volumeVariance[cubeIndex] = cubes[cubeIndex].Size > 1 ? CalculateVariance(moments, cubes[cubeIndex]) : 0.0f; } else { volumeVariance[next] = 0.0f; cubeIndex--; } next = 0; var temp = volumeVariance[0]; for (var index = 1; index <= cubeIndex; ++index) { if (volumeVariance[index] <= temp) continue; temp = volumeVariance[index]; next = index; } if (temp > 0.0) continue; colorCount = cubeIndex + 1; break; } return cubes.Take(colorCount).ToArray(); }
private static IList<Box> SplitData(ref int colorCount, ColorData data) { --colorCount; var next = 0; var volumeVariance = new float[MaxColor]; var cubes = new Box[MaxColor]; cubes[0].AlphaMaximum = MaxSideIndex; cubes[0].RedMaximum = MaxSideIndex; cubes[0].GreenMaximum = MaxSideIndex; cubes[0].BlueMaximum = MaxSideIndex; for (var cubeIndex = 1; cubeIndex < colorCount; ++cubeIndex) { if (Cut(data, ref cubes[next], ref cubes[cubeIndex])) { volumeVariance[next] = cubes[next].Size > 1 ? CalculateVariance(data, cubes[next]) : 0.0f; volumeVariance[cubeIndex] = cubes[cubeIndex].Size > 1 ? CalculateVariance(data, cubes[cubeIndex]) : 0.0f; } else { volumeVariance[next] = 0.0f; cubeIndex--; } next = 0; var temp = volumeVariance[0]; for (var index = 1; index <= cubeIndex; ++index) { if (volumeVariance[index] <= temp) continue; temp = volumeVariance[index]; next = index; } if (temp > 0.0) continue; colorCount = cubeIndex + 1; break; } return cubes.Take(colorCount).ToList(); }