Automatic Optimization Algorithm for a Direct 2D and 3D Mesh Generation from the Layout Information