Topological analysis of functions on arbitrary grids: Applications to quantum chemistry