node.setMedianValue(medianValue);
if (leftIndex == rightIndex)
{
throw new IllegalArgumentException("Cannot split leaf that only holds one color. This should never happen.");
}
MedianCutNode left = new MedianCutNode(node, leftIndex, middleIndex);
MedianCutNode right = new MedianCutNode(node, middleIndex + 1, rightIndex);
node.setSuccessors(left, right);
for (int i = 0; i < 3; i++)
{
int max = node.getMaxColorSample(i);
left.setMaxColorSample(i, max);
right.setMaxColorSample(i, max);
int min = node.getMinColorSample(i);
left.setMinColorSample(i, min);
right.setMinColorSample(i, min);
}
left.setMaxColorSample(axis, medianValue);
right.setMinColorSample(axis, medianValue + 1);
}