// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2019 Hanxiao Shen // // 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 #include "ear_clipping.h" #include "point_inside_convex_polygon.h" #include "predicates.h" template IGL_INLINE void igl::predicates::ear_clipping( const Eigen::MatrixBase& P, const Eigen::MatrixBase& RT, Eigen::PlainObjectBase& I, Eigen::PlainObjectBase& eF, Eigen::PlainObjectBase& nP ){ typedef typename DerivedF::Scalar Index; typedef typename DerivedP::Scalar Scalar; static_assert(std::is_same::value, "index type should be consistent"); // check whether vertex i is an ear auto is_ear = []( const Eigen::MatrixBase& P, const Eigen::MatrixBase& RT, const Eigen::Matrix& L, const Eigen::Matrix& R, const Index i ){ Index a = L(i), b = R(i); if(RT(i) != 0 || RT(a) != 0 || RT(b) != 0) return false; Eigen::Matrix pa = P.row(a); Eigen::Matrix pb = P.row(b); Eigen::Matrix pi = P.row(i); auto r = igl::predicates::orient2d(pa,pi,pb); if(r == igl::predicates::Orientation::NEGATIVE || r == igl::predicates::Orientation::COLLINEAR) return false; // check if any vertex is lying inside triangle (a,b,i); Index k=R(b); while(k!=a){ Eigen::Matrix T(3,2); T< q=P.row(k); if(igl::predicates::point_inside_convex_polygon(T,q)) return false; k=R(k); } return true; }; Eigen::Matrix L(P.rows()); Eigen::Matrix R(P.rows()); for(int i=0;i ears; // mark ears Eigen::Matrix X; // clipped vertices ears.setZero(P.rows()); X.setZero(P.rows()); // initialize ears for(int i=0;i, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif