// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2014 Daniele Panozzo // // 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 "triangulate.h" #ifdef ANSI_DECLARATORS # define IGL_PREVIOUSLY_DEFINED_ANSI_DECLARATORS ANSI_DECLARATORS # undef ANSI_DECLARATORS #endif #ifdef REAL # define IGL_PREVIOUSLY_DEFINED_REAL REAL # undef REAL #endif #ifdef VOID # define IGL_PREVIOUSLY_DEFINED_VOID VOID # undef VOID #endif #define ANSI_DECLARATORS #define REAL double #define VOID int extern "C" { #include } #undef ANSI_DECLARATORS #ifdef IGL_PREVIOUSLY_DEFINED_ANSI_DECLARATORS # define ANSI_DECLARATORS IGL_PREVIOUSLY_DEFINED_ANSI_DECLARATORS #endif #undef REAL #ifdef IGL_PREVIOUSLY_DEFINED_REAL # define REAL IGL_PREVIOUSLY_DEFINED_REAL #endif #undef VOID #ifdef IGL_PREVIOUSLY_DEFINED_VOID # define VOID IGL_PREVIOUSLY_DEFINED_VOID #endif template < typename DerivedV, typename DerivedE, typename DerivedH, typename DerivedV2, typename DerivedF2> IGL_INLINE void igl::triangle::triangulate( const Eigen::MatrixBase & V, const Eigen::MatrixBase & E, const Eigen::MatrixBase & H, const std::string flags, Eigen::PlainObjectBase & V2, Eigen::PlainObjectBase & F2) { Eigen::VectorXi VM,EM,VM2,EM2; return triangulate(V,E,H,VM,EM,flags,V2,F2,VM2,EM2); } template < typename DerivedV, typename DerivedE, typename DerivedH, typename DerivedVM, typename DerivedEM, typename DerivedV2, typename DerivedF2, typename DerivedVM2, typename DerivedEM2> IGL_INLINE void igl::triangle::triangulate( const Eigen::MatrixBase & V, const Eigen::MatrixBase & E, const Eigen::MatrixBase & H, const Eigen::MatrixBase & VM, const Eigen::MatrixBase & EM, const std::string flags, Eigen::PlainObjectBase & V2, Eigen::PlainObjectBase & F2, Eigen::PlainObjectBase & VM2, Eigen::PlainObjectBase & EM2) { using namespace std; using namespace Eigen; assert( (VM.size() == 0 || V.rows() == VM.size()) && "Vertex markers must be empty or same size as V"); assert( (EM.size() == 0 || E.rows() == EM.size()) && "Segment markers must be empty or same size as E"); assert(V.cols() == 2); assert(E.size() == 0 || E.cols() == 2); assert(H.size() == 0 || H.cols() == 2); // Prepare the flags string full_flags = flags + "pz" + (EM.size() || VM.size() ? "" : "B"); typedef Map< Matrix > MapXdr; typedef Map< Matrix > MapXir; // Prepare the input struct triangulateio in; in.numberofpoints = V.rows(); in.pointlist = (double*)calloc(V.size(),sizeof(double)); { MapXdr inpl(in.pointlist,V.rows(),V.cols()); inpl = V.template cast(); } in.numberofpointattributes = 0; in.pointmarkerlist = (int*)calloc(V.size(),sizeof(int)) ; for(unsigned i=0;i(); } in.segmentmarkerlist = (int*)calloc(E.rows(),sizeof(int)); for (unsigned i=0;i(); } in.numberofregions = 0; // Prepare the output struct triangulateio out; out.pointlist = NULL; out.trianglelist = NULL; out.segmentlist = NULL; out.segmentmarkerlist = NULL; out.pointmarkerlist = NULL; // Call triangle ::triangulate(const_cast(full_flags.c_str()), &in, &out, 0); // Return the mesh V2 = MapXdr(out.pointlist,out.numberofpoints,2).cast(); F2 = MapXir(out.trianglelist,out.numberoftriangles,3).cast(); if(VM.size()) { VM2 = MapXir(out.pointmarkerlist,out.numberofpoints,1).cast(); } if(EM.size()) { EM2 = MapXir(out.segmentmarkerlist,out.numberofsegments,1).cast(); } // Cleanup in free(in.pointlist); free(in.pointmarkerlist); free(in.segmentlist); free(in.segmentmarkerlist); free(in.holelist); // Cleanup out free(out.pointlist); free(out.trianglelist); free(out.segmentlist); free(out.segmentmarkerlist); free(out.pointmarkerlist); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template void igl::triangle::triangulate, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template void igl::triangle::triangulate, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif