// 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 "writeSTL.h" #include template IGL_INLINE bool igl::writeSTL( const std::string & filename, const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, const Eigen::PlainObjectBase & N, const bool ascii) { using namespace std; assert(N.rows() == 0 || F.rows() == N.rows()); if(ascii) { FILE * stl_file = fopen(filename.c_str(),"w"); if(stl_file == NULL) { cerr<<"IOError: "<0) { fprintf(stl_file,"%e %e %e\n", (float)N(f,0), (float)N(f,1), (float)N(f,2)); }else { fprintf(stl_file,"0 0 0\n"); } fprintf(stl_file,"outer loop\n"); for(int c = 0;c n(3,0); if(N.rows() > 0) { n[0] = N(f,0); n[1] = N(f,1); n[2] = N(f,2); } fwrite(&n[0],sizeof(float),3,stl_file); for(int c = 0;c<3;c++) { vector v(3); v[0] = V(F(f,c),0); v[1] = V(F(f,c),1); v[2] = V(F(f,c),2); fwrite(&v[0],sizeof(float),3,stl_file); } unsigned short att_count = 0; fwrite(&att_count,sizeof(unsigned short),1,stl_file); } fclose(stl_file); return true; } } template IGL_INLINE bool igl::writeSTL( const std::string & filename, const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, const bool ascii) { return writeSTL(filename,V,F, DerivedV(), ascii); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, bool); // generated by autoexplicit.sh template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, bool); // generated by autoexplicit.sh template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, bool); template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, bool); template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, bool); #endif