// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2014 Daniele Panozzo // // 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 "triangle_triangle_adjacency.h" #include #include template IGL_INLINE void igl::triangle_triangle_adjacency_preprocess(const Eigen::PlainObjectBase& /*V*/, const Eigen::PlainObjectBase& F, std::vector >& TTT) { for(int f=0;f v2) std::swap(v1,v2); std::vector r(4); r[0] = v1; r[1] = v2; r[2] = f; r[3] = i; TTT.push_back(r); } std::sort(TTT.begin(),TTT.end()); } // Extract the face adjacencies template IGL_INLINE void igl::triangle_triangle_adjacency_extractTT(const Eigen::PlainObjectBase& F, std::vector >& TTT, Eigen::PlainObjectBase& TT) { TT = Eigen::PlainObjectBase::Constant((int)(F.rows()),F.cols(),-1); for(int i=1;i<(int)TTT.size();++i) { std::vector& r1 = TTT[i-1]; std::vector& r2 = TTT[i]; if ((r1[0] == r2[0]) && (r1[1] == r2[1])) { TT(r1[2],r1[3]) = r2[2]; TT(r2[2],r2[3]) = r1[2]; } } } // Extract the face adjacencies indices (needed for fast traversal) template IGL_INLINE void igl::triangle_triangle_adjacency_extractTTi(const Eigen::PlainObjectBase& F, std::vector >& TTT, Eigen::PlainObjectBase& TTi) { TTi = Eigen::PlainObjectBase::Constant((int)(F.rows()),F.cols(),-1); for(int i=1;i<(int)TTT.size();++i) { std::vector& r1 = TTT[i-1]; std::vector& r2 = TTT[i]; if ((r1[0] == r2[0]) && (r1[1] == r2[1])) { TTi(r1[2],r1[3]) = r2[3]; TTi(r2[2],r2[3]) = r1[3]; } } } // Compute triangle-triangle adjacency template IGL_INLINE void igl::triangle_triangle_adjacency(const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& TT) { //assert(igl::is_edge_manifold(V,F)); std::vector > TTT; triangle_triangle_adjacency_preprocess(V,F,TTT); triangle_triangle_adjacency_extractTT(F,TTT,TT); } // Compute triangle-triangle adjacency with indices template IGL_INLINE void igl::triangle_triangle_adjacency(const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& TT, Eigen::PlainObjectBase& TTi) { //assert(igl::is_edge_manifold(V,F)); std::vector > TTT; triangle_triangle_adjacency_preprocess(V,F,TTT); triangle_triangle_adjacency_extractTT(F,TTT,TT); triangle_triangle_adjacency_extractTTi(F,TTT,TTi); } #ifdef IGL_STATIC_LIBRARY // Explicit template specialization template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif