// 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 "tetrahedralize.h" #include "mesh_to_tetgenio.h" #include "tetgenio_to_tetmesh.h" // IGL includes #include "../../matrix_to_list.h" #include "../../list_to_matrix.h" #include "../../boundary_facets.h" // STL includes #include #include IGL_INLINE int igl::copyleft::tetgen::tetrahedralize( const std::vector > & V, const std::vector > & F, const std::string switches, std::vector > & TV, std::vector > & TT, std::vector > & TF) { using namespace std; tetgenio in,out; bool success; success = mesh_to_tetgenio(V,F,in); if(!success) { return -1; } try { char * cswitches = new char[switches.size() + 1]; std::strcpy(cswitches,switches.c_str()); ::tetrahedralize(cswitches,&in, &out); delete[] cswitches; }catch(int e) { cerr<<"^"<<__FUNCTION__<<": TETGEN CRASHED... KABOOOM!!!"< IGL_INLINE int igl::copyleft::tetgen::tetrahedralize( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, const std::string switches, Eigen::PlainObjectBase& TV, Eigen::PlainObjectBase& TT, Eigen::PlainObjectBase& TF) { using namespace std; vector > vV,vTV; vector > vF,vTT,vTF; matrix_to_list(V,vV); matrix_to_list(F,vF); int e = tetrahedralize(vV,vF,switches,vTV,vTT,vTF); if(e == 0) { bool TV_rect = list_to_matrix(vTV,TV); if(!TV_rect) { return 3; } bool TT_rect = list_to_matrix(vTT,TT); if(!TT_rect) { return 3; } bool TF_rect = list_to_matrix(vTF,TF); if(!TF_rect) { return 3; } } return e; } template < typename DerivedV, typename DerivedF, typename DerivedVM, typename DerivedFM, typename DerivedTV, typename DerivedTT, typename DerivedTF, typename DerivedTM> IGL_INLINE int igl::copyleft::tetgen::tetrahedralize( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, const Eigen::PlainObjectBase& VM, const Eigen::PlainObjectBase& FM, const std::string switches, Eigen::PlainObjectBase& TV, Eigen::PlainObjectBase& TT, Eigen::PlainObjectBase& TF, Eigen::PlainObjectBase& TM) { using namespace std; vector > vV,vTV; vector > vF,vTT,vTF; vector vTM; matrix_to_list(V,vV); matrix_to_list(F,vF); vector vVM = matrix_to_list(VM); vector vFM = matrix_to_list(FM); int e = tetrahedralize(vV,vF,vVM,vFM,switches,vTV,vTT,vTF,vTM); if(e == 0) { bool TV_rect = list_to_matrix(vTV,TV); if(!TV_rect) { return false; } bool TT_rect = list_to_matrix(vTT,TT); if(!TT_rect) { return false; } bool TF_rect = list_to_matrix(vTF,TF); if(!TF_rect) { return false; } bool TM_rect = list_to_matrix(vTM,TM); if(!TM_rect) { return false; } } return e; } IGL_INLINE int igl::copyleft::tetgen::tetrahedralize( const std::vector > & V, const std::vector > & F, const std::vector & VM, const std::vector & FM, const std::string switches, std::vector > & TV, std::vector > & TT, std::vector > & TF, std::vector & TM) { using namespace std; tetgenio in,out; bool success; success = mesh_to_tetgenio(V,F,in); if(!success) { return -1; } in.pointmarkerlist = new int[VM.size()]; for (int i = 0; i < VM.size(); ++i) { in.pointmarkerlist[i] = VM[i]; } // These have already been created in mesh_to_tetgenio. // Reset them here. for (int i = 0; i < FM.size(); ++i) { in.facetmarkerlist[i] = FM[i]; } try { char * cswitches = new char[switches.size() + 1]; std::strcpy(cswitches,switches.c_str()); ::tetrahedralize(cswitches,&in, &out); delete[] cswitches; }catch(int e) { cerr<<"^"<<__FUNCTION__<<": TETGEN CRASHED... KABOOOM!!!"<, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template int igl::copyleft::tetgen::tetrahedralize,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(const Eigen::PlainObjectBase > &,const Eigen::PlainObjectBase > &,const Eigen::PlainObjectBase > &,const Eigen::PlainObjectBase > &,const std::basic_string, std::allocator >,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &, Eigen::PlainObjectBase > &); template int igl::copyleft::tetgen::tetrahedralize, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif