A recursive approach to local mesh refinement in two and three dimensions