Merged branch 'dev_native' into lm_sla_supports_auto

Added igl library files
This commit is contained in:
Lukas Matena 2018-10-26 15:45:52 +02:00
commit 7681d00ee5
2865 changed files with 142806 additions and 22325 deletions

View file

@ -0,0 +1,7 @@
IGL interface to tetgen library
Dependencies:
tetgen
Travel to $IGL/external/tetgen and issue:
make -f Makefile.igl tetlib

View file

@ -0,0 +1,64 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
//
// 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 "cdt.h"
#include "../../bounding_box.h"
#include "tetrahedralize.h"
template <
typename DerivedV,
typename DerivedF,
typename DerivedTV,
typename DerivedTT,
typename DerivedTF>
IGL_INLINE bool igl::copyleft::tetgen::cdt(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
const CDTParam & param,
Eigen::PlainObjectBase<DerivedTV>& TV,
Eigen::PlainObjectBase<DerivedTT>& TT,
Eigen::PlainObjectBase<DerivedTF>& TF)
{
using namespace Eigen;
using namespace std;
// Effective input mesh
DerivedV U;
DerivedF G;
if(param.use_bounding_box)
{
// Construct bounding box mesh
DerivedV BV;
DerivedF BF;
bounding_box(V,BV,BF);
// scale bounding box
const RowVector3d mid =
(BV.colwise().minCoeff() + BV.colwise().maxCoeff()).eval()*0.5;
BV.rowwise() -= mid;
assert(param.bounding_box_scale >= 1.);
BV.array() *= param.bounding_box_scale;
BV.rowwise() += mid;
// Append bounding box to mesh
U.resize(V.rows()+BV.rows(),V.cols());
U<<V,BV;
BF.array() += V.rows();
G.resize(F.rows()+BF.rows(),F.cols());
G<<F,BF;
}else
{
// needless copies
U = V;
G = F;
}
// effective flags;
string flags = param.flags + (param.use_bounding_box ? "" : "c");
return tetrahedralize(U,G,flags,TV,TT,TF);
}
#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
template bool igl::copyleft::tetgen::cdt<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, igl::copyleft::tetgen::CDTParam const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
#endif

View file

@ -0,0 +1,72 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
//
// 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/.
#ifndef IGL_COPYLEFT_TETGEN_CDT_H
#define IGL_COPYLEFT_TETGEN_CDT_H
#include "../../igl_inline.h"
#include <Eigen/Core>
#include <string>
#ifndef TETLIBRARY
# define TETLIBRARY
#endif
#include "tetgen.h" // Defined REAL
namespace igl
{
namespace copyleft
{
namespace tetgen
{
struct CDTParam
{
// Tetgen can compute mesh of convex hull of input (i.e. "c") but often
// chokes. One workaround is to force it to mesh the entire bounding box.
// {false}
bool use_bounding_box = false;
// Scale the bounding box a bit so that vertices near it do not give tetgen
// problems. {1.01}
double bounding_box_scale = 1.01;
// Flags to tetgen. Do not include the "c" flag here! {"Y"}
std::string flags = "Y";
};
// Create a constrained delaunay tessellation containing convex hull of the
// given **non-selfintersecting** mesh.
//
// Inputs:
// V #V by 3 list of input mesh vertices
// F #F by 3 list of input mesh facets
// param see above
// TV #TV by 3 list of output mesh vertices (V come first)
// TT #TT by 3 list of tetrahedra indices into TV.
// TF #TF by 3 list of facets from F potentially subdivided.
//
template <
typename DerivedV,
typename DerivedF,
typename DerivedTV,
typename DerivedTT,
typename DerivedTF>
IGL_INLINE bool cdt(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
const CDTParam & param,
Eigen::PlainObjectBase<DerivedTV>& TV,
Eigen::PlainObjectBase<DerivedTT>& TT,
Eigen::PlainObjectBase<DerivedTF>& TF);
}
}
}
#ifndef IGL_STATIC_LIBRARY
# include "cdt.cpp"
#endif
#endif

View file

@ -0,0 +1,78 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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 "mesh_to_tetgenio.h"
// IGL includes
#include "../../matrix_to_list.h"
// STL includes
#include <cassert>
IGL_INLINE bool igl::copyleft::tetgen::mesh_to_tetgenio(
const std::vector<std::vector<REAL > > & V,
const std::vector<std::vector<int> > & F,
tetgenio & in)
{
using namespace std;
// all indices start from 0
in.firstnumber = 0;
in.numberofpoints = V.size();
in.pointlist = new REAL[in.numberofpoints * 3];
// loop over points
for(int i = 0; i < (int)V.size(); i++)
{
assert(V[i].size() == 3);
in.pointlist[i*3+0] = V[i][0];
in.pointlist[i*3+1] = V[i][1];
in.pointlist[i*3+2] = V[i][2];
}
in.numberoffacets = F.size();
in.facetlist = new tetgenio::facet[in.numberoffacets];
in.facetmarkerlist = new int[in.numberoffacets];
// loop over face
for(int i = 0;i < (int)F.size(); i++)
{
in.facetmarkerlist[i] = i;
tetgenio::facet * f = &in.facetlist[i];
f->numberofpolygons = 1;
f->polygonlist = new tetgenio::polygon[f->numberofpolygons];
f->numberofholes = 0;
f->holelist = NULL;
tetgenio::polygon * p = &f->polygonlist[0];
p->numberofvertices = F[i].size();
p->vertexlist = new int[p->numberofvertices];
// loop around face
for(int j = 0;j < (int)F[i].size(); j++)
{
p->vertexlist[j] = F[i][j];
}
}
return true;
}
template <typename DerivedV, typename DerivedF>
IGL_INLINE bool igl::copyleft::tetgen::mesh_to_tetgenio(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
tetgenio & in)
{
using namespace std;
vector<vector<REAL> > vV;
vector<vector<int> > vF;
matrix_to_list(V,vV);
matrix_to_list(F,vF);
return mesh_to_tetgenio(vV,vF,in);
}
#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
template bool igl::copyleft::tetgen::mesh_to_tetgenio<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, tetgenio&);
#endif

View file

@ -0,0 +1,55 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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/.
#ifndef IGL_COPYLEFT_TETGEN_MESH_TO_TETGENIO_H
#define IGL_COPYLEFT_TETGEN_MESH_TO_TETGENIO_H
#include "../../igl_inline.h"
#ifndef TETLIBRARY
# define TETLIBRARY
#endif
#include "tetgen.h" // Defined tetgenio, REAL
#include <vector>
#include <Eigen/Core>
namespace igl
{
namespace copyleft
{
namespace tetgen
{
// Load a vertex list and face list into a tetgenio object
// Inputs:
// V #V by 3 vertex position list
// F #F list of polygon face indices into V (0-indexed)
// Outputs:
// in tetgenio input object
// Returns true on success, false on error
IGL_INLINE bool mesh_to_tetgenio(
const std::vector<std::vector<REAL > > & V,
const std::vector<std::vector<int> > & F,
tetgenio & in);
// Wrapper with Eigen types
// Templates:
// DerivedV real-value: i.e. from MatrixXd
// DerivedF integer-value: i.e. from MatrixXi
template <typename DerivedV, typename DerivedF>
IGL_INLINE bool mesh_to_tetgenio(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
tetgenio & in);
}
}
}
#ifndef IGL_STATIC_LIBRARY
# include "mesh_to_tetgenio.cpp"
#endif
#endif

View file

@ -0,0 +1,102 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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 "mesh_with_skeleton.h"
#include "tetrahedralize.h"
#include "../../sample_edges.h"
#include "../../cat.h"
#include <iostream>
// Default settings pq2Y tell tetgen to mesh interior of triangle mesh and
// to produce a graded tet mesh
const static std::string DEFAULT_TETGEN_FLAGS = "pq2Y";
IGL_INLINE bool igl::copyleft::tetgen::mesh_with_skeleton(
const Eigen::MatrixXd & V,
const Eigen::MatrixXi & F,
const Eigen::MatrixXd & C,
const Eigen::VectorXi & /*P*/,
const Eigen::MatrixXi & BE,
const Eigen::MatrixXi & CE,
const int samples_per_bone,
const std::string & tetgen_flags,
Eigen::MatrixXd & VV,
Eigen::MatrixXi & TT,
Eigen::MatrixXi & FF)
{
using namespace Eigen;
using namespace std;
const string eff_tetgen_flags =
(tetgen_flags.length() == 0?DEFAULT_TETGEN_FLAGS:tetgen_flags);
// Collect all edges that need samples:
MatrixXi BECE = cat(1,BE,CE);
MatrixXd S;
// Sample each edge with 10 samples. (Choice of 10 doesn't seem to matter so
// much, but could under some circumstances)
sample_edges(C,BECE,samples_per_bone,S);
// Vertices we'll constrain tet mesh to meet
MatrixXd VS = cat(1,V,S);
// Use tetgen to mesh the interior of surface, this assumes surface:
// * has no holes
// * has no non-manifold edges or vertices
// * has consistent orientation
// * has no self-intersections
// * has no 0-volume pieces
cerr<<"tetgen begin()"<<endl;
int status = tetrahedralize( VS,F,eff_tetgen_flags,VV,TT,FF);
cerr<<"tetgen end()"<<endl;
if(FF.rows() != F.rows())
{
// Issue a warning if the surface has changed
cerr<<"mesh_with_skeleton: Warning: boundary faces != input faces"<<endl;
}
if(status != 0)
{
cerr<<
"***************************************************************"<<endl<<
"***************************************************************"<<endl<<
"***************************************************************"<<endl<<
"***************************************************************"<<endl<<
"* mesh_with_skeleton: tetgen failed. Just meshing convex hull *"<<endl<<
"***************************************************************"<<endl<<
"***************************************************************"<<endl<<
"***************************************************************"<<endl<<
"***************************************************************"<<endl;
// If meshing convex hull then use more regular mesh
status = tetrahedralize(VS,F,"q1.414",VV,TT,FF);
// I suppose this will fail if the skeleton is outside the mesh
assert(FF.maxCoeff() < VV.rows());
if(status != 0)
{
cerr<<"mesh_with_skeleton: tetgen failed again."<<endl;
return false;
}
}
return true;
}
IGL_INLINE bool igl::copyleft::tetgen::mesh_with_skeleton(
const Eigen::MatrixXd & V,
const Eigen::MatrixXi & F,
const Eigen::MatrixXd & C,
const Eigen::VectorXi & P,
const Eigen::MatrixXi & BE,
const Eigen::MatrixXi & CE,
const int samples_per_bone,
Eigen::MatrixXd & VV,
Eigen::MatrixXi & TT,
Eigen::MatrixXi & FF)
{
return mesh_with_skeleton(
V,F,C,P,BE,CE,samples_per_bone,DEFAULT_TETGEN_FLAGS,VV,TT,FF);
}
#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
#endif

View file

@ -0,0 +1,72 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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/.
#ifndef IGL_COPYLEFT_TETGEN_MESH_WITH_SKELETON_H
#define IGL_COPYLEFT_TETGEN_MESH_WITH_SKELETON_H
#include "../../igl_inline.h"
#include <Eigen/Dense>
#include <string>
namespace igl
{
namespace copyleft
{
namespace tetgen
{
// Mesh the interior of a given surface with tetrahedra which are graded
// (tend to be small near the surface and large inside) and conform to the
// given handles and samplings thereof.
//
// Inputs:
// V #V by 3 list of mesh vertex positions
// F #F by 3 list of triangle indices
// C #C by 3 list of vertex positions
// P #P list of point handle indices
// BE #BE by 2 list of bone-edge indices
// CE #CE by 2 list of cage-edge indices
// samples_per_bone #samples to add per bone
// tetgen_flags flags to pass to tetgen {""-->"pq2Y"} otherwise you're on
// your own and it's your funeral if you pass nonsense flags
// Outputs:
// VV #VV by 3 list of tet-mesh vertex positions
// TT #TT by 4 list of tetrahedra indices
// FF #FF by 3 list of surface triangle indices
// Returns true only on success
IGL_INLINE bool mesh_with_skeleton(
const Eigen::MatrixXd & V,
const Eigen::MatrixXi & F,
const Eigen::MatrixXd & C,
const Eigen::VectorXi & /*P*/,
const Eigen::MatrixXi & BE,
const Eigen::MatrixXi & CE,
const int samples_per_bone,
const std::string & tetgen_flags,
Eigen::MatrixXd & VV,
Eigen::MatrixXi & TT,
Eigen::MatrixXi & FF);
// Wrapper using default tetgen_flags
IGL_INLINE bool mesh_with_skeleton(
const Eigen::MatrixXd & V,
const Eigen::MatrixXi & F,
const Eigen::MatrixXd & C,
const Eigen::VectorXi & /*P*/,
const Eigen::MatrixXi & BE,
const Eigen::MatrixXi & CE,
const int samples_per_bone,
Eigen::MatrixXd & VV,
Eigen::MatrixXi & TT,
Eigen::MatrixXi & FF);
}
}
}
#ifndef IGL_STATIC_LIBRARY
# include "mesh_with_skeleton.cpp"
#endif
#endif

View file

@ -0,0 +1,74 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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_into_tetgenio.h"
#include "mesh_to_tetgenio.h"
// IGL includes
#include "../../pathinfo.h"
#ifndef IGL_NO_EIGEN
# define IGL_NO_EIGEN_WAS_NOT_ALREADY_DEFINED
# define IGL_NO_EIGEN
#endif
// Include igl headers without including Eigen
#include "../../readOBJ.h"
#ifdef IGL_NO_EIGEN_WAS_NOT_ALREADY_DEFINED
# undef IGL_NO_EIGEN
#endif
// STL includes
#include <algorithm>
#include <iostream>
#include <vector>
IGL_INLINE bool igl::copyleft::tetgen::read_into_tetgenio(
const std::string & path,
tetgenio & in)
{
using namespace std;
// get file extension
string dirname,basename,ext,filename;
pathinfo(path,dirname,basename,ext,filename);
// convert to lower case for easy comparison
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
bool success = false;
char basename_char[1024];
strcpy(basename_char,basename.c_str());
if(ext == "obj")
{
// read obj into vertex list and face list
vector<vector<REAL> > V,TC,N;
vector<vector<int> > F,FTC,FN;
success = readOBJ(path,V,TC,N,F,FTC,FN);
success &= mesh_to_tetgenio(V,F,in);
}else if(ext == "off")
{
success = in.load_off(basename_char);
}else if(ext == "node")
{
success = in.load_node(basename_char);
}else
{
if(ext.length() > 0)
{
cerr<<"^read_into_tetgenio Warning: Unsupported extension ("<<ext<<
"): try to load as basename..."<<endl;
}
// This changed as of (the so far unreleased) tetgen 1.5
//success = in.load_tetmesh(basename_char);
//int object = tetgenbehavior::NODES;
//if(ext == "mesh")
//{
// object = tetgenbehavior::MEDIT;
//}
success = in.load_tetmesh(basename_char,!tetgenbehavior::MEDIT);
}
return success;
}

View file

@ -0,0 +1,62 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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/.
#ifndef IGL_COPYLEFT_TETGEN_READ_INTO_TETGENIO_H
#define IGL_COPYLEFT_TETGEN_READ_INTO_TETGENIO_H
#include "../../igl_inline.h"
#include <string>
#ifndef TETLIBRARY
#define TETLIBRARY
#endif
#include "tetgen.h" // Defined tetgenio, REAL
namespace igl
{
namespace copyleft
{
namespace tetgen
{
// Read a mesh or point set into tetgenio (input object for calling
// tetgen). Many file formats are already supported by tetgen:
// .off
// .ply
// .node
// .ply
// .medit
// .vtk
// etc.
// Notably it does not support .obj which is loaded by hand here (also
// demonstrating how to load points/faces programmatically)
//
// If the file extension is not recognized the filename is assumed to be
// the basename of a collection describe a tetmesh, (of which at least
// the .node file must exist):
// [filename].node
// [filename].ele
// [filename].face
// [filename].edge
// [filename].vol
//
// Inputs:
// path path to file or basename to files
// Outputs:
// in tetgenio input object
// Returns true on success, false on error
IGL_INLINE bool read_into_tetgenio(
const std::string & path,
tetgenio & in);
}
}
}
#ifndef IGL_STATIC_LIBRARY
# include "read_into_tetgenio.cpp"
#endif
#endif

View file

@ -0,0 +1,146 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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 "tetgenio_to_tetmesh.h"
// IGL includes
#include "../../list_to_matrix.h"
// STL includes
#include <iostream>
IGL_INLINE bool igl::copyleft::tetgen::tetgenio_to_tetmesh(
const tetgenio & out,
std::vector<std::vector<REAL > > & V,
std::vector<std::vector<int> > & T,
std::vector<std::vector<int> > & F)
{
using namespace std;
// process points
if(out.pointlist == NULL)
{
cerr<<"^tetgenio_to_tetmesh Error: point list is NULL\n"<<endl;
return false;
}
V.resize(out.numberofpoints,vector<REAL>(3));
// loop over points
for(int i = 0;i < out.numberofpoints; i++)
{
V[i][0] = out.pointlist[i*3+0];
V[i][1] = out.pointlist[i*3+1];
V[i][2] = out.pointlist[i*3+2];
}
// process tets
if(out.tetrahedronlist == NULL)
{
cerr<<"^tetgenio_to_tetmesh Error: tet list is NULL\n"<<endl;
return false;
}
// When would this not be 4?
assert(out.numberofcorners == 4);
T.resize(out.numberoftetrahedra,vector<int>(out.numberofcorners));
int min_index = 1e7;
int max_index = -1e7;
// loop over tetrahedra
for(int i = 0; i < out.numberoftetrahedra; i++)
{
for(int j = 0; j<out.numberofcorners; j++)
{
int index = out.tetrahedronlist[i * out.numberofcorners + j];
T[i][j] = index;
min_index = (min_index > index ? index : min_index);
max_index = (max_index < index ? index : max_index);
}
}
assert(min_index >= 0);
assert(max_index >= 0);
assert(max_index < (int)V.size());
cout<<out.numberoftrifaces<<endl;
// When would this not be 4?
F.clear();
// loop over tetrahedra
for(int i = 0; i < out.numberoftrifaces; i++)
{
if(out.trifacemarkerlist[i]>=0)
{
vector<int> face(3);
for(int j = 0; j<3; j++)
{
face[j] = out.trifacelist[i * 3 + j];
}
F.push_back(face);
}
}
return true;
}
IGL_INLINE bool igl::copyleft::tetgen::tetgenio_to_tetmesh(
const tetgenio & out,
std::vector<std::vector<REAL > > & V,
std::vector<std::vector<int> > & T)
{
std::vector<std::vector<int> > F;
return tetgenio_to_tetmesh(out,V,T,F);
}
template <typename DerivedV, typename DerivedT, typename DerivedF>
IGL_INLINE bool igl::copyleft::tetgen::tetgenio_to_tetmesh(
const tetgenio & out,
Eigen::PlainObjectBase<DerivedV>& V,
Eigen::PlainObjectBase<DerivedT>& T,
Eigen::PlainObjectBase<DerivedF>& F)
{
using namespace std;
vector<vector<REAL> > vV;
vector<vector<int> > vT;
vector<vector<int> > vF;
bool success = tetgenio_to_tetmesh(out,vV,vT,vF);
if(!success)
{
return false;
}
bool V_rect = list_to_matrix(vV,V);
if(!V_rect)
{
// igl::list_to_matrix(vV,V) already printed error message to std err
return false;
}
bool T_rect = list_to_matrix(vT,T);
if(!T_rect)
{
// igl::list_to_matrix(vT,T) already printed error message to std err
return false;
}
bool F_rect = list_to_matrix(vF,F);
if(!F_rect)
{
return false;
}
return true;
}
template <typename DerivedV, typename DerivedT>
IGL_INLINE bool igl::copyleft::tetgen::tetgenio_to_tetmesh(
const tetgenio & out,
Eigen::PlainObjectBase<DerivedV>& V,
Eigen::PlainObjectBase<DerivedT>& T)
{
Eigen::Matrix<typename DerivedT::Scalar,Eigen::Dynamic,3> F;
return tetgenio_to_tetmesh(out,V,T,F);
}
#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
template bool igl::copyleft::tetgen::tetgenio_to_tetmesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(tetgenio const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
#endif

View file

@ -0,0 +1,66 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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/.
#ifndef IGL_COPYLEFT_TETGEN_TETGENIO_TO_TETMESH_H
#define IGL_COPYLEFT_TETGEN_TETGENIO_TO_TETMESH_H
#include "../../igl_inline.h"
#ifndef TETLIBRARY
#define TETLIBRARY
#endif
#include "tetgen.h" // Defined tetgenio, REAL
#include <vector>
#include <Eigen/Core>
namespace igl
{
namespace copyleft
{
namespace tetgen
{
// Extract a tetrahedral mesh from a tetgenio object
// Inputs:
// out tetgenio output object
// Outputs:
// V #V by 3 vertex position list
// T #T by 4 list of tetrahedra indices into V
// F #F by 3 list of marked facets
// Returns true on success, false on error
IGL_INLINE bool tetgenio_to_tetmesh(
const tetgenio & out,
std::vector<std::vector<REAL > > & V,
std::vector<std::vector<int> > & T,
std::vector<std::vector<int> > & F);
IGL_INLINE bool tetgenio_to_tetmesh(
const tetgenio & out,
std::vector<std::vector<REAL > > & V,
std::vector<std::vector<int> > & T);
// Wrapper with Eigen types
// Templates:
// DerivedV real-value: i.e. from MatrixXd
// DerivedT integer-value: i.e. from MatrixXi
template <typename DerivedV, typename DerivedT, typename DerivedF>
IGL_INLINE bool tetgenio_to_tetmesh(
const tetgenio & out,
Eigen::PlainObjectBase<DerivedV>& V,
Eigen::PlainObjectBase<DerivedT>& T,
Eigen::PlainObjectBase<DerivedF>& F);
template <typename DerivedV, typename DerivedT>
IGL_INLINE bool tetgenio_to_tetmesh(
const tetgenio & out,
Eigen::PlainObjectBase<DerivedV>& V,
Eigen::PlainObjectBase<DerivedT>& T);
}
}
}
#ifndef IGL_STATIC_LIBRARY
# include "tetgenio_to_tetmesh.cpp"
#endif
#endif

View file

@ -0,0 +1,220 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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 <cassert>
#include <iostream>
IGL_INLINE int igl::copyleft::tetgen::tetrahedralize(
const std::vector<std::vector<REAL > > & V,
const std::vector<std::vector<int> > & F,
const std::string switches,
std::vector<std::vector<REAL > > & TV,
std::vector<std::vector<int > > & TT,
std::vector<std::vector<int> > & 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!!!"<<endl;
return 1;
}
if(out.numberoftetrahedra == 0)
{
cerr<<"^"<<__FUNCTION__<<": Tetgen failed to create tets"<<endl;
return 2;
}
success = tetgenio_to_tetmesh(out,TV,TT,TF);
if(!success)
{
return -1;
}
//boundary_facets(TT,TF);
return 0;
}
template <
typename DerivedV,
typename DerivedF,
typename DerivedTV,
typename DerivedTT,
typename DerivedTF>
IGL_INLINE int igl::copyleft::tetgen::tetrahedralize(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
const std::string switches,
Eigen::PlainObjectBase<DerivedTV>& TV,
Eigen::PlainObjectBase<DerivedTT>& TT,
Eigen::PlainObjectBase<DerivedTF>& TF)
{
using namespace std;
vector<vector<REAL> > vV,vTV;
vector<vector<int> > 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<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
const Eigen::PlainObjectBase<DerivedVM>& VM,
const Eigen::PlainObjectBase<DerivedFM>& FM,
const std::string switches,
Eigen::PlainObjectBase<DerivedTV>& TV,
Eigen::PlainObjectBase<DerivedTT>& TT,
Eigen::PlainObjectBase<DerivedTF>& TF,
Eigen::PlainObjectBase<DerivedTM>& TM)
{
using namespace std;
vector<vector<REAL> > vV,vTV;
vector<vector<int> > vF,vTT,vTF;
vector<int> vTM;
matrix_to_list(V,vV);
matrix_to_list(F,vF);
vector<int> vVM = matrix_to_list(VM);
vector<int> 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<std::vector<REAL > > & V,
const std::vector<std::vector<int> > & F,
const std::vector<int> & VM,
const std::vector<int> & FM,
const std::string switches,
std::vector<std::vector<REAL > > & TV,
std::vector<std::vector<int > > & TT,
std::vector<std::vector<int> > & TF,
std::vector<int> & 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!!!"<<endl;
return 1;
}
if(out.numberoftetrahedra == 0)
{
cerr<<"^"<<__FUNCTION__<<": Tetgen failed to create tets"<<endl;
return 2;
}
success = tetgenio_to_tetmesh(out,TV,TT,TF);
if(!success)
{
return -1;
}
TM.resize(out.numberofpoints);
for (int i = 0; i < out.numberofpoints; ++i) {
TM[i] = out.pointmarkerlist[i];
}
//boundary_facets(TT,TF);
return 0;
}
#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
template int igl::copyleft::tetgen::tetrahedralize<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
template int igl::copyleft::tetgen::tetrahedralize<Eigen::Matrix<double, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, 1, 0, -1, 1>,Eigen::Matrix<int, -1, 1, 0, -1, 1>,Eigen::Matrix<double, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, 1, 0, -1, 1> >(const Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > &,const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > &,const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > &,const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > &,const std::basic_string<char, std::char_traits<char>, std::allocator<char> >,Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > &,Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > &,Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > &, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > &);
template int igl::copyleft::tetgen::tetrahedralize<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
#endif

View file

@ -0,0 +1,136 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// 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/.
#ifndef IGL_COPYLEFT_TETGEN_TETRAHEDRALIZE_H
#define IGL_COPYLEFT_TETGEN_TETRAHEDRALIZE_H
#include "../../igl_inline.h"
#include <vector>
#include <string>
#include <Eigen/Core>
#ifndef TETLIBRARY
#define TETLIBRARY
#endif
#include "tetgen.h" // Defined REAL
namespace igl
{
namespace copyleft
{
namespace tetgen
{
// Mesh the interior of a surface mesh (V,F) using tetgen
//
// Inputs:
// V #V by 3 vertex position list
// F #F list of polygon face indices into V (0-indexed)
// switches string of tetgen options (See tetgen documentation) e.g.
// "pq1.414a0.01" tries to mesh the interior of a given surface with
// quality and area constraints
// "" will mesh the convex hull constrained to pass through V (ignores F)
// Outputs:
// TV #V by 3 vertex position list
// TT #T by 4 list of tet face indices
// TF #F by 3 list of triangle face indices
// Returns status:
// 0 success
// 1 tetgen threw exception
// 2 tetgen did not crash but could not create any tets (probably there are
// holes, duplicate faces etc.)
// -1 other error
IGL_INLINE int tetrahedralize(
const std::vector<std::vector<REAL > > & V,
const std::vector<std::vector<int> > & F,
const std::string switches,
std::vector<std::vector<REAL > > & TV,
std::vector<std::vector<int > > & TT,
std::vector<std::vector<int> > & TF);
// Wrapper with Eigen types
// Templates:
// DerivedV real-value: i.e. from MatrixXd
// DerivedF integer-value: i.e. from MatrixXi
template <
typename DerivedV,
typename DerivedF,
typename DerivedTV,
typename DerivedTT,
typename DerivedTF>
IGL_INLINE int tetrahedralize(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
const std::string switches,
Eigen::PlainObjectBase<DerivedTV>& TV,
Eigen::PlainObjectBase<DerivedTT>& TT,
Eigen::PlainObjectBase<DerivedTF>& TF);
// Mesh the interior of a surface mesh (V,F) using tetgen
//
// Inputs:
// V #V by 3 vertex position list
// F #F list of polygon face indices into V (0-indexed)
// M #V list of markers for vertices
// switches string of tetgen options (See tetgen documentation) e.g.
// "pq1.414a0.01" tries to mesh the interior of a given surface with
// quality and area constraints
// "" will mesh the convex hull constrained to pass through V (ignores F)
// Outputs:
// TV #V by 3 vertex position list
// TT #T by 4 list of tet face indices
// TF #F by 3 list of triangle face indices
// TM #V list of markers for vertices
// Returns status:
// 0 success
// 1 tetgen threw exception
// 2 tetgen did not crash but could not create any tets (probably there are
// holes, duplicate faces etc.)
// -1 other error
IGL_INLINE int tetrahedralize(
const std::vector<std::vector<REAL > > & V,
const std::vector<std::vector<int> > & F,
const std::vector<int> & VM,
const std::vector<int> & FM,
const std::string switches,
std::vector<std::vector<REAL > > & TV,
std::vector<std::vector<int > > & TT,
std::vector<std::vector<int> > & TF,
std::vector<int> & TM);
// Wrapper with Eigen types
// Templates:
// DerivedV real-value: i.e. from MatrixXd
// DerivedF integer-value: i.e. from MatrixXi
template <
typename DerivedV,
typename DerivedF,
typename DerivedVM,
typename DerivedFM,
typename DerivedTV,
typename DerivedTT,
typename DerivedTF,
typename DerivedTM>
IGL_INLINE int tetrahedralize(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
const Eigen::PlainObjectBase<DerivedVM>& VM,
const Eigen::PlainObjectBase<DerivedFM>& FM,
const std::string switches,
Eigen::PlainObjectBase<DerivedTV>& TV,
Eigen::PlainObjectBase<DerivedTT>& TT,
Eigen::PlainObjectBase<DerivedTF>& TF,
Eigen::PlainObjectBase<DerivedTM>& TM);
}
}
}
#ifndef IGL_STATIC_LIBRARY
# include "tetrahedralize.cpp"
#endif
#endif