I'm not sure we've implemented the KDTree and KDElement class as clean as possible. Specifically, it shouldn't be necessary for the TileImage to explicitly implement KDElement. A better construction might be:
-- Move the KDElement class to an internal KDTree class
-- The KDTree template could be based on the element being used, along with callback functions for retrieving the number of levels and the value at each level.
I don't know the best way to do this in C++, but I don't think we're doing it right now. It could use a little work.