// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2024 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 "refine.h" #include "triangle_header.h" template < typename DerivedV, typename DerivedE, typename DerivedF, typename DerivedV2, typename DerivedF2> IGL_INLINE void igl::triangle::refine( const Eigen::MatrixBase & V, const Eigen::MatrixBase & E, const Eigen::MatrixBase & F, const std::string flags, Eigen::PlainObjectBase & V2, Eigen::PlainObjectBase & F2) { assert(V.cols() == 2); assert(F.cols() == 3); // Prepare the flags std::string full_flags = flags + "rzB" + (E.size()?"p":""); typedef Eigen::Map< Eigen::Matrix > MapXdr; typedef Eigen::Map< Eigen::Matrix > MapXir; // To-do: reduce duplicate code with triangulate.cpp // 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.numberoftriangleattributes = 0; in.triangleattributelist = NULL; // Why? in.numberofcorners = 3; //in.numberofsegments = 0; //in.segmentlist = NULL; //in.segmentmarkerlist = NULL; in.numberofsegments = E.size()?E.rows():0; in.segmentlist = (int*)calloc(E.size(),sizeof(int)); { MapXir insl(in.segmentlist,E.rows(),E.cols()); insl = E.template cast(); } // Empty edge markers (to-do) Eigen::VectorXi EM; in.segmentmarkerlist = (int*)calloc(E.rows(),sizeof(int)); for (unsigned i=0;i(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(); // Cleanup in free(in.pointlist); free(in.pointmarkerlist); free(in.trianglelist ); // Cleanup out free(out.pointlist); free(out.trianglelist); free(out.segmentlist); free(out.segmentmarkerlist); free(out.pointmarkerlist); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation template void igl::triangle::refine, 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