diff --git a/BGL/examples/BGL_surface_mesh/write_inp.cpp b/BGL/examples/BGL_surface_mesh/write_inp.cpp new file mode 100644 index 00000000000..6011a1c0cd5 --- /dev/null +++ b/BGL/examples/BGL_surface_mesh/write_inp.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef CGAL::Surface_mesh Mesh; + +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +int main() +{ + Mesh sm; + CGAL::make_quad(Point(0,0,0), Point(1,0,0),Point(1,1,0),Point(0,1,0), sm); + CGAL::make_quad(Point(0,0,1), Point(1,0,1),Point(1,1,1),Point(0,1,1), sm); + + std::ofstream out("out.inp"); + CGAL::write_inp(out, sm, "out.inp", "S4R"); + return 0; +} diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 4bf5a520912..67baef342ac 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -197,6 +197,43 @@ bool read_off(const char* fname, return false; } + +template +bool write_inp(std::ostream& os, + const FaceGraph& g, + std::string name, + std::string type) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename boost::graph_traits::vertices_size_type vertices_size_type; + + typedef typename boost::property_map::const_type VPM; + typedef typename boost::property_traits::value_type Point_3; + + VPM vpm = get(CGAL::vertex_point,g); + + os << "*Part, name=" << name << "\n*Node\n"; + boost::container::flat_map reindex; + int n = 1; + BOOST_FOREACH(vertex_descriptor v, vertices(g)){ + Point_3 p = get(vpm,v); + os << n << ", " << p.x() << ", " << p.y() << ", " << p.z() << '\n'; + reindex[v]=n++; + } + n = 1; + os << "*Element, type=" << type << std::endl; + BOOST_FOREACH(face_descriptor f, faces(g)){ + os << n++; + BOOST_FOREACH(vertex_descriptor v, vertices_around_face(halfedge(f,g),g)){ + os << ", " << reindex[v]; + } + os << '\n'; + } + os << "*End Part"<< std::endl; + return os.good(); +} + } // namespace CGAL