#ifndef IGL_WRITEMESH_H #define IGL_WRITEMESH_H #include #include namespace igl { // save a tetrahedral volume mesh to a .mesh file // // Templates: // Scalar type for positions and vectors (will be cast as double) // Index type for indices (will be cast to int) // Input: // mesh_file_name path of .mesh file // Outputs: // V double matrix of vertex positions #V by 3 // T #T list of tet indices into vertex positions // F #F list of face indices into vertex positions template inline bool writeMESH( const std::string mesh_file_name, std::vector > & V, std::vector > & T, std::vector > & F); // Input: // mesh_file_name path of .mesh file // Outputs: // V eigen double matrix #V by 3 // T eigen int matrix #T by 4 // F eigen int matrix #F by 3 inline bool writeMESH( const std::string str, Eigen::MatrixXd& V, Eigen::MatrixXi& T, Eigen::MatrixXi& F); } // Implementation #include #include "verbose.h" template inline bool igl::writeMESH( const std::string mesh_file_name, std::vector > & V, std::vector > & T, std::vector > & F) { // not implemented but should be assert(false); return false; } #include inline bool igl::writeMESH( const std::string str, Eigen::MatrixXd& V, Eigen::MatrixXi& T, Eigen::MatrixXi& F) { using namespace std; using namespace igl; using namespace Eigen; FILE * mesh_file = fopen(str.c_str(),"w"); if(NULL==mesh_file) { fprintf(stderr,"IOError: %s could not be opened...",str.c_str()); return false; } // print header fprintf(mesh_file,"MeshVersionFormatted 1\n"); fprintf(mesh_file,"Dimension 3\n"); // print tet vertices fprintf(mesh_file,"Vertices\n"); // print number of tet vertices int number_of_tet_vertices = V.rows(); fprintf(mesh_file,"%d\n",number_of_tet_vertices); // loop over tet vertices for(int i = 0;i