// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2014 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 "readSTL.h" #include "list_to_matrix.h" #include template IGL_INLINE bool igl::readSTL( const std::string & filename, Eigen::PlainObjectBase & V, Eigen::PlainObjectBase & F, Eigen::PlainObjectBase & N) { using namespace std; vector > vV; vector > vN; vector > vF; if(!readSTL(filename,vV,vF,vN)) { return false; } if(!list_to_matrix(vV,V)) { return false; } if(!list_to_matrix(vF,F)) { return false; } if(!list_to_matrix(vN,N)) { return false; } return true; } template IGL_INLINE bool igl::readSTL( const std::string & filename, std::vector > & V, std::vector > & F, std::vector > & N) { using namespace std; // Should test for ascii // Open file, and check for error FILE * stl_file = fopen(filename.c_str(),"r"); if(NULL==stl_file) { fprintf(stderr,"IOError: %s could not be opened...\n", filename.c_str()); return false; } V.clear(); F.clear(); N.clear(); #ifndef IGL_LINE_MAX # define IGL_LINE_MAX 2048 #endif char solid[IGL_LINE_MAX]; if(fscanf(stl_file,"%s",solid)!=1) { // file too short cerr<<"IOError: "< n(3); ret = fscanf(stl_file,"%s %s %lg %lg %lg",facet,normal,&n[0],&n[1],&n[2]); if(string("endsolid") == facet) { break; } if(ret != 5 || string("facet") != facet || string("normal") != normal) { cerr<<"IOError: "< f; while(true) { char word[IGL_LINE_MAX]; int ret = fscanf(stl_file,"%s",word); if(ret == 1 && string("endloop") == word) { break; }else if(ret == 1 && string("vertex") == word) { vector v(3); int ret = fscanf(stl_file,"%lg %lg %lg",&v[0],&v[1],&v[2]); if(ret != 3) { cerr<<"IOError: "<(3,0)); N.resize(num_tri,vector(3,0)); F.resize(num_tri,vector(3,0)); for(int t = 0;t<(int)num_tri;t++) { // Read normal float n[3]; if(fread(n,sizeof(float),3,stl_file)!=3) { cerr<<"IOError: "<, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template bool igl::readSTL, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif