Density classification on infinite lattices and trees