#include "sort_triangles.h" #include "barycenter.h" #include "sort.h" #include "sortrows.h" #include "slice.h" #include "round.h" #include "colon.h" #include "matlab_format.h" #include "OpenGL_convenience.h" #include template < typename DerivedV, typename DerivedF, typename DerivedMV, typename DerivedP, typename DerivedFF, typename DerivedI> IGL_INLINE void igl::sort_triangles( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, const Eigen::PlainObjectBase & MV, const Eigen::PlainObjectBase & P, Eigen::PlainObjectBase & FF, Eigen::PlainObjectBase & I) { using namespace Eigen; using namespace igl; using namespace std; // Barycenter, centroid Eigen::Matrix D,sD; Eigen::Matrix BC,PBC; barycenter(V,F,BC); D = BC*(MV.transpose()*P.transpose().eval().col(2)); sort(D,1,false,sD,I); //// Closest corner //Eigen::Matrix D,sD; //D.setConstant(F.rows(),1,-1e26); //for(int c = 0;c<3;c++) //{ // Eigen::Matrix C; // Eigen::Matrix DC; // C.resize(F.rows(),4); // for(int f = 0;fD.array()).select(DC,D).eval(); //} //sort(D,1,false,sD,I); //// Closest corner with tie breaks //Eigen::Matrix D,sD,ssD; //D.resize(F.rows(),3); //for(int c = 0;c<3;c++) //{ // Eigen::Matrix C; // C.resize(F.rows(),4); // for(int f = 0;f void igl::sort_triangles( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, Eigen::PlainObjectBase & FF, Eigen::PlainObjectBase & I) { using namespace Eigen; using namespace igl; using namespace std; // Put model, projection, and viewport matrices into double arrays Matrix4d MV; Matrix4d P; glGetDoublev(GL_MODELVIEW_MATRIX, MV.data()); glGetDoublev(GL_PROJECTION_MATRIX, P.data()); if(V.cols() == 3) { Matrix hV; hV.resize(V.rows(),4); hV.block(0,0,V.rows(),V.cols()) = V; hV.col(3).setConstant(1); return sort_triangles(hV,F,MV,P,FF,I); }else { return sort_triangles(V,F,MV,P,FF,I); } } #include "project.h" #include template < typename DerivedV, typename DerivedF, typename DerivedFF, typename DerivedI> void igl::sort_triangles_slow( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, Eigen::PlainObjectBase & FF, Eigen::PlainObjectBase & I) { using namespace Eigen; using namespace igl; using namespace std; // Barycenter, centroid Eigen::Matrix D,sD; Eigen::Matrix BC; D.resize(F.rows(),3); barycenter(V,F,BC); for(int f = 0;f bc,pbc; bc = BC.row(f); project(bc,pbc); D(f) = pbc(2); } sort(D,1,false,sD,I); slice(F,I,1,FF); } #ifndef IGL_HEADER_ONLY // Explicit template instanciation template void igl::sort_triangles, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::sort_triangles_slow, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif