// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "read_triangle_mesh.h" #include "list_to_matrix.h" #include "readMESH.h" #include "readOBJ.h" #include "readOFF.h" #include "readSTL.h" #include "readPLY.h" #include "readWRL.h" #include "pathinfo.h" #include "boundary_facets.h" #include "polygon_mesh_to_triangle_mesh.h" #include #include template IGL_INLINE bool igl::read_triangle_mesh( const std::string str, std::vector > & V, std::vector > & F) { using namespace std; // dirname, basename, extension and filename string d,b,e,f; pathinfo(str,d,b,e,f); // Convert extension to lower case std::transform(e.begin(), e.end(), e.begin(), ::tolower); vector > TC, N, C; vector > FTC, FN; if(e == "obj") { // Annoyingly obj can store 4 coordinates, truncate to xyz for this generic // read_triangle_mesh bool success = readOBJ(str,V,TC,N,F,FTC,FN); for(auto & v : V) { v.resize(std::min(v.size(),(size_t)3)); } return success; }else if(e == "off") { return readOFF(str,V,F,N,C); } cerr<<"Error: "<<__FUNCTION__<<": "<< str<<" is not a recognized mesh file format."< IGL_INLINE bool igl::read_triangle_mesh( const std::string str, Eigen::PlainObjectBase& V, Eigen::PlainObjectBase& F) { std::string _1,_2,_3,_4; return read_triangle_mesh(str,V,F,_1,_2,_3,_4); } template IGL_INLINE bool igl::read_triangle_mesh( const std::string filename, Eigen::PlainObjectBase& V, Eigen::PlainObjectBase& F, std::string & dir, std::string & base, std::string & ext, std::string & name) { using namespace std; using namespace Eigen; // dirname, basename, extension and filename pathinfo(filename,dir,base,ext,name); // Convert extension to lower case transform(ext.begin(), ext.end(), ext.begin(), ::tolower); FILE * fp = fopen(filename.c_str(),"rb"); if(NULL==fp) { fprintf(stderr,"IOError: %s could not be opened...\n", filename.c_str()); return false; } return read_triangle_mesh(ext,fp,V,F); } template IGL_INLINE bool igl::read_triangle_mesh( const std::string & ext, FILE * fp, Eigen::PlainObjectBase& V, Eigen::PlainObjectBase& F) { using namespace std; using namespace Eigen; vector > vV,vN,vTC,vC; vector > vF,vFTC,vFN; if(ext == "mesh") { // Convert extension to lower case MatrixXi T; if(!readMESH(fp,V,T,F)) { return 1; } //if(F.size() > T.size() || F.size() == 0) { boundary_facets(T,F); } }else if(ext == "obj") { if(!readOBJ(fp,vV,vTC,vN,vF,vFTC,vFN)) { return false; } // Annoyingly obj can store 4 coordinates, truncate to xyz for this generic // read_triangle_mesh for(auto & v : vV) { v.resize(std::min(v.size(),(size_t)3)); } }else if(ext == "off") { if(!readOFF(fp,vV,vF,vN,vC)) { return false; } }else if(ext == "ply") { if(!readPLY(fp,vV,vF,vN,vTC)) { return false; } }else if(ext == "stl") { if(!readSTL(fp,vV,vF,vN)) { return false; } }else if(ext == "wrl") { if(!readWRL(fp,vV,vF)) { return false; } }else { cerr<<"Error: unknown extension: "< 0) { if(!list_to_matrix(vV,V)) { return false; } polygon_mesh_to_triangle_mesh(vF,F); } return true; } #endif #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template bool igl::read_triangle_mesh(std::basic_string, std::allocator >, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); template bool igl::read_triangle_mesh, Eigen::Matrix >(std::string, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&); template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&); #endif