A robust direct variational approach for generation of quadrangular and triangular grids on planar domains