A general theory for the evaluation of X-ray diagrams of biomembranes and other lamellar systems