  We investigate the particle and kinetic-energy densities for a system of $N$
fermions bound in a local (mean-field) potential $V(\bfr)$. We generalize a
recently developed semiclassical theory [J. Roccia and M. Brack, Phys. Rev.\
Lett. {\bf 100}, 200408 (2008)], in which the densities are calculated in terms
of the closed orbits of the corresponding classical system, to $D>1$
dimensions. We regularize the semiclassical results $(i)$ for the U(1) symmetry
breaking occurring for spherical systems at $r=0$ and $(ii)$ near the classical
turning points where the Friedel oscillations are predominant and well
reproduced by the shortest orbit going from $r$ to the closest turning point
and back. For systems with spherical symmetry, we show that there exist two
types of oscillations which can be attributed to radial and non-radial orbits,
respectively. The semiclassical theory is tested against exact
quantum-mechanical calculations for a variety of model potentials. We find a
very good overall numerical agreement between semiclassical and exact numerical
densities even for moderate particle numbers $N$. Using a "local virial
theorem", shown to be valid (except for a small region around the classical
turning points) for arbitrary local potentials, we can prove that the
Thomas-Fermi functional $\tau_{\text{TF}}[\rho]$ reproduces the oscillations in
the quantum-mechanical densities to first order in the oscillating parts.
