Spacetimes characterized by their scalar curvature invariants