#!/usr/bin/env python
#
# Copyright (C) 2009 Anders Logg
#
# This file is part of DOLFIN.
#
# DOLFIN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DOLFIN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#
# Simple script for mesh STL geometry with TetGen and converting to DOLFIN XML format

import sys, os

# Check command-line arguments
if len(sys.argv) != 3:
    print "Usage: dolfin-tetgen mesh.stl mesh.xml"
    sys.exit(1)
stl_file = sys.argv[1]
xml_file = sys.argv[2]

# Run TetGen
os.system("tetgen -g -p %s" % stl_file)

# Convert to DOLFIN
mesh_file = stl_file.split(".stl")[0] + ".1" + ".mesh"
os.system("dolfin-convert %s %s" % (mesh_file, xml_file))
