#include "polygons_to_triangles.h" #include "ear_clipping.h" #include "../sort.h" #include template < typename DerivedV, typename DerivedI, typename DerivedC, typename DerivedF, typename DerivedJ> IGL_INLINE void igl::predicates::polygons_to_triangles( const Eigen::MatrixBase & V, const Eigen::MatrixBase & I, const Eigen::MatrixBase & C, Eigen::PlainObjectBase & F, Eigen::PlainObjectBase & J) { typedef Eigen::Index Index; // Each polygon results in #sides-2 triangles. So ∑#sides-2 F.resize(C(C.size()-1) - (C.size()-1)*2,3); J.resize(F.rows()); { Index f = 0; for(Index p = 0;p(); break; case 3: { Eigen::MatrixXd P = (pV.rowwise() - pV.colwise().mean()).template cast(); Eigen::Matrix3d O = P.transpose() * P; Eigen::EigenSolver es(O); Eigen::Matrix3d C = es.eigenvectors().real(); { Eigen::Vector3d _1; Eigen::Vector3i I; igl::sort(es.eigenvalues().real().eval(),1,false,_1,I); C = C(Eigen::all,I).eval(); } S = P*C.leftCols(2); break; } default: assert(false && "dim>3 not supported"); } Eigen::VectorXi RT = Eigen::VectorXi::Zero(S.rows(),1); Eigen::VectorXi _I; Eigen::MatrixXd _nS; // compute signed area { double area = 0; for(Index c = 0;c0 && c1) //{ // // Delaunay-ize // Eigen::MatrixXd pl; // igl::edge_lengths(pV,pF,pl); // typedef Eigen::Matrix MatrixX2I; // typedef Eigen::Matrix VectorXI; // MatrixX2I E,uE; // VectorXI EMAP; // std::vector > uE2E; // igl::unique_edge_map(pF, E, uE, EMAP, uE2E); // typedef Index Index; // typedef double Scalar; // const Index num_faces = pF.rows(); // std::vector Q; // Q.reserve(uE2E.size()); // for (size_t uei=0; uei v3 /__f__\ v4 // // \ e / \ f2 / // // d\ | /a d\ /a // // \|/ \ / // // v2 v2 // // // // hmm... is the flip actually in the other direction? // const Index f1 = uE2E[uei][0]%num_faces; // const Index f2 = uE2E[uei][1]%num_faces; // const Index c1 = uE2E[uei][0]/num_faces; // const Index c2 = uE2E[uei][1]/num_faces; // const size_t e_24 = f1 + ((c1 + 1) % 3) * num_faces; // const size_t e_41 = f1 + ((c1 + 2) % 3) * num_faces; // const size_t e_13 = f2 + ((c2 + 1) % 3) * num_faces; // const size_t e_32 = f2 + ((c2 + 2) % 3) * num_faces; // const size_t ue_24 = EMAP(e_24); // const size_t ue_41 = EMAP(e_41); // const size_t ue_13 = EMAP(e_13); // const size_t ue_32 = EMAP(e_32); // // new edge lengths // const Index v1 = pF(f1, (c1+1)%3); // const Index v2 = pF(f1, (c1+2)%3); // const Index v4 = pF(f1, c1); // const Index v3 = pF(f2, c2); // { // const Scalar e = pl(f1,c1); // const Scalar a = pl(f1,(c1+1)%3); // const Scalar b = pl(f1,(c1+2)%3); // const Scalar c = pl(f2,(c2+1)%3); // const Scalar d = pl(f2,(c2+2)%3); // const double f = (pV.row(v3)-pV.row(v4)).norm(); // // New order // pl(f1,0) = f; // pl(f1,1) = b; // pl(f1,2) = c; // pl(f2,0) = f; // pl(f2,1) = d; // pl(f2,2) = a; // } // prIndexf("%d,%d %d,%d -> %d,%d\n",uE(uei,0),uE(uei,1),v1,v2,v3,v4); // igl::flip_edge(pF, E, uE, EMAP, uE2E, uei); // std::cout<<" "<