Functionals defined on partitions in sets of finite perimeter. I. Integral representation and G-convergence.