// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2016 Oded Stein // // 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 "loop.h" #include "adjacency_list.h" #include "triangle_triangle_adjacency.h" #include "unique.h" #include template < typename DerivedF, typename SType, typename DerivedNF> IGL_INLINE void igl::loop( const int n_verts, const Eigen::MatrixBase & F, Eigen::SparseMatrix& S, Eigen::PlainObjectBase & NF) { typedef Eigen::Triplet Triplet_t; //Ref. https://graphics.stanford.edu/~mdfisher/subdivision.html //Heavily borrowing from igl::upsample Eigen::Matrix FF, FFi; triangle_triangle_adjacency(F, FF, FFi); std::vector> adjacencyList; adjacency_list(F, adjacencyList, true); //Compute the number and positions of the vertices to insert (on edges) Eigen::MatrixXi NI = Eigen::MatrixXi::Constant(FF.rows(), FF.cols(), -1); Eigen::MatrixXi NIdoubles = Eigen::MatrixXi::Zero(FF.rows(), FF.cols()); Eigen::VectorXi vertIsOnBdry = Eigen::VectorXi::Zero(n_verts); int counter = 0; for(int i=0; i tripletList; for(int i=0; i VI(6); VI << F(i,0), F(i,1), F(i,2), NI(i,0) + n_odd, NI(i,1) + n_odd, NI(i,2) + n_odd; Eigen::Matrix f0(3), f1(3), f2(3), f3(3); f0 << VI(0), VI(3), VI(5); f1 << VI(1), VI(4), VI(3); f2 << VI(3), VI(4), VI(5); f3 << VI(4), VI(2), VI(5); NF.row((i*4)+0) = f0; NF.row((i*4)+1) = f1; NF.row((i*4)+2) = f2; NF.row((i*4)+3) = f3; } } template < typename DerivedV, typename DerivedF, typename DerivedNV, typename DerivedNF> IGL_INLINE void igl::loop( const Eigen::MatrixBase& V, const Eigen::MatrixBase& F, Eigen::PlainObjectBase& NV, Eigen::PlainObjectBase& NF, const int number_of_subdivs) { NV = V; NF = F; for(int i=0; i S; loop(NV.rows(), tempF, S, NF); // This .eval is super important NV = (S*NV).eval(); } } #ifdef IGL_STATIC_LIBRARY template void igl::loop, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix>(Eigen::MatrixBase> const &, Eigen::MatrixBase> const &, Eigen::PlainObjectBase> &, Eigen::PlainObjectBase> &, int); #endif