// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 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 "sort_triangles.h" #include "project.h" #include "../sort_triangles.h" #include "gl.h" #include "../sort.h" #include "../slice.h" #include "../barycenter.h" #include template < typename DerivedV, typename DerivedF, typename DerivedFF, typename DerivedI> void igl::opengl2::sort_triangles( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, Eigen::PlainObjectBase & FF, Eigen::PlainObjectBase & I) { using namespace Eigen; 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 igl::sort_triangles(hV,F,MV,P,FF,I); }else { return igl::sort_triangles(V,F,MV,P,FF,I); } } template < typename DerivedV, typename DerivedF, typename DerivedFF, typename DerivedI> void igl::opengl2::sort_triangles_slow( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, Eigen::PlainObjectBase & FF, Eigen::PlainObjectBase & I) { using namespace Eigen; 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); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation template void igl::opengl2::sort_triangles, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::opengl2::sort_triangles_slow, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif