Affine structures in 3-manifolds, V, The triangulation theorem and Hauptvermutung