A low complexity algorithm to identify open and closed surfaces in complex geometries