Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_IO_MESH_TETGEN_WRITE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_IO_MESH_TETGEN_WRITE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cassert>
00013 #include <string>
00014 #include <fstream>
00015 #include <iostream>
00016 #include <vector>
00017
00018 namespace OpenTissue
00019 {
00020 namespace mesh
00021 {
00022
00031 template<typename mesh_type>
00032 bool tetgen_write(std::string const & filename, mesh_type const & mesh)
00033 {
00034 typedef typename mesh_type::const_vertex_iterator const_vertex_iterator;
00035 typedef typename mesh_type::const_face_iterator const_face_iterator;
00036 typedef typename mesh_type::const_face_vertex_circulator const_face_vertex_circulator;
00037
00038
00039
00040
00041
00042 std::ofstream file(filename.c_str());
00043 file.precision(30);
00044 file << static_cast<int>(mesh.size_vertices()) << " 3" << std::endl;
00045 const_vertex_iterator vend = mesh.vertex_end();
00046 const_vertex_iterator v = mesh.vertex_begin();
00047 for(;v!=vend;++v)
00048 file << v->get_handle().get_idx() << " " << v->m_coord(0) << " " << v->m_coord(1) << " " << v->m_coord(2) << std::endl;
00049 file << std::endl;
00050
00051
00052
00053
00054
00055
00056
00057 file << static_cast<int>(mesh.size_faces()) << " 0" << std::endl;
00058 const_face_iterator fend = mesh.face_end();
00059 const_face_iterator f = mesh.face_begin();
00060 for(;f!=fend;++f)
00061 {
00062 file << "1" << std::endl;
00063 file << static_cast<int>(valency(*f));
00064 const_face_vertex_circulator fvc(*f),end;
00065 for(;fvc!=end;++fvc)
00066 file << " " << fvc->get_handle().get_idx();
00067 file << std::endl;
00068 }
00069
00070
00071
00072
00073
00074 file << "0" << std::endl;
00075
00076
00077
00078
00079
00080 file << "0" << std::endl;
00081 file.flush();
00082 file.close();
00083 std::cout << "tetgen_write(): wrote tetgen file: " << filename << std::endl;
00084 return true;
00085 }
00086
00087 }
00088 }
00089
00090
00091 #endif