Osmotic pressure of foams and highly concentrated emulsions. I. Theoretical considerations