Electromagnetic density of modes for a finite-size three-dimensional structure