Calculation of the local optical density of states in absorbing and gain media