Casey Stoner captured pole position for MotoGP's German Grand Prix as qualifying built to a scintillating crescendo.