Particle-vortex duality in topological insulators and superconductors