#ifndef IGL_UPSAMPLE_H #define IGL_UPSAMPLE_H namespace igl { // Subdivide a mesh without moving vertices: loop subdivision but odd // vertices stay put and even vertices are just edge midpoints // // Templates: // MatV matrix for vertex positions, e.g. MatrixXd // MatF matrix for vertex positions, e.g. MatrixXi // Inputs: // V #V by dim mesh vertices // F #F by 3 mesh triangles // Outputs: // NV new vertex positions, V is guaranteed to be at top // NF new list of face indices // // NOTE: V should not be the same as NV, // NOTE: F should not be the same as NF, use other proto template void upsample( const MatV & V, const MatF & F, MatV & NV, MatF & NF); // Virtually in place wrapper template void upsample( MatV & V,MatF & F); } // Implementation #include #include #include template void igl::upsample( const MatV & V, const MatF & F, MatV & NV, MatF & NF) { // Use "in place" wrapper instead assert(&V != &NV); assert(&F != &NF); using namespace igl; using namespace std; using namespace Eigen; MatF FF, FFi; tt(V,F,FF,FFi); // TODO: Cache optimization missing from here, it is a mess // Compute the number and positions of the vertices to insert (on edges) MatF NI = MatF::Constant(FF.rows(),FF.cols(),-1); int counter = 0; for(int i=0;i SUBD(V.rows()+n_even,V.rows()); SUBD.reserve(15 * (V.rows()+n_even)); // Preallocate NV and NF NV = MatV(V.rows()+n_even,V.cols()); NF = MatF(F.rows()*4,3); // Fill the odd vertices position NV.block(0,0,V.rows(),V.cols()) = V; // Fill the even vertices position for(int i=0;i void igl::upsample( MatV & V,MatF & F) { const MatV V_copy = V; const MatF F_copy = F; return upsample(V_copy,F_copy,V,F); } #endif