// 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 "is_edge_manifold.h" #include "all_edges.h" #include "unique_simplices.h" #include "unique_edge_map.h" #include #include // Extract the face adjacencies template IGL_INLINE void igl::triangle_triangle_adjacency_extractTT( const Eigen::PlainObjectBase& F, std::vector >& TTT, Eigen::PlainObjectBase& TT) { TT.setConstant((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]; } } } template IGL_INLINE void igl::triangle_triangle_adjacency( const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& TT) { DerivedTT TTi; return triangle_triangle_adjacency(F,TT,TTi); } template IGL_INLINE void igl::triangle_triangle_adjacency_preprocess( 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 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.setConstant((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 with indices template IGL_INLINE void igl::triangle_triangle_adjacency( const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& TT, Eigen::PlainObjectBase& TTi) { std::vector > TTT; triangle_triangle_adjacency_preprocess(F,TTT); triangle_triangle_adjacency_extractTT(F,TTT,TT); triangle_triangle_adjacency_extractTTi(F,TTT,TTi); } template < typename DerivedF, typename TTIndex, typename TTiIndex> IGL_INLINE void igl::triangle_triangle_adjacency( const Eigen::PlainObjectBase & F, std::vector > > & TT, std::vector > > & TTi) { return triangle_triangle_adjacency(F,true,TT,TTi); } template < typename DerivedF, typename TTIndex> IGL_INLINE void igl::triangle_triangle_adjacency( const Eigen::PlainObjectBase & F, std::vector > > & TT) { std::vector > > not_used; return triangle_triangle_adjacency(F,false,TT,not_used); } template < typename DerivedF, typename TTIndex, typename TTiIndex> IGL_INLINE void igl::triangle_triangle_adjacency( const Eigen::PlainObjectBase & F, const bool construct_TTi, std::vector > > & TT, std::vector > > & TTi) { using namespace Eigen; using namespace std; assert(F.cols() == 3 && "Faces must be triangles"); // number of faces typedef typename DerivedF::Index Index; typedef Matrix MatrixX2I; typedef Matrix VectorXI; MatrixX2I E,uE; VectorXI EMAP; vector > uE2E; unique_edge_map(F,E,uE,EMAP,uE2E); return triangle_triangle_adjacency(E,EMAP,uE2E,construct_TTi,TT,TTi); } template < typename DerivedE, typename DerivedEMAP, typename uE2EType, typename TTIndex, typename TTiIndex> IGL_INLINE void igl::triangle_triangle_adjacency( const Eigen::PlainObjectBase & E, const Eigen::PlainObjectBase & EMAP, const std::vector > & uE2E, const bool construct_TTi, std::vector > > & TT, std::vector > > & TTi) { using namespace std; using namespace Eigen; typedef typename DerivedE::Index Index; const size_t m = E.rows()/3; assert((size_t)E.rows() == m*3 && "E should come from list of triangles."); // E2E[i] --> {j,k,...} means face edge i corresponds to other faces edges j // and k TT.resize (m,vector >(3)); if(construct_TTi) { TTi.resize(m,vector >(3)); } // No race conditions because TT*[f][c]'s are in bijection with e's // Minimum number of iterms per openmp thread //const size_t num_e = E.rows(); # ifndef IGL_OMP_MIN_VALUE # define IGL_OMP_MIN_VALUE 1000 # endif # pragma omp parallel for if (m>IGL_OMP_MIN_VALUE) // Slightly better memory access than loop over E for(Index f = 0;f<(Index)m;f++) { for(Index c = 0;c<3;c++) { const Index e = f + m*c; //const Index c = e/m; const vector & N = uE2E[EMAP(e)]; for(const auto & ne : N) { const Index nf = ne%m; // don't add self if(nf != f) { TT[f][c].push_back(nf); if(construct_TTi) { const Index nc = ne/m; TTi[f][c].push_back(nc); } } } } } } #ifdef IGL_STATIC_LIBRARY // Explicit template specialization // generated by autoexplicit.sh template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); template void igl::triangle_triangle_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::triangle_triangle_adjacency, Eigen::Matrix, long, long, long>(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::vector >, std::allocator > > > const&, bool, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&); template void igl::triangle_triangle_adjacency, Eigen::Matrix, unsigned long, int, int>(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::vector >, std::allocator > > > const&, bool, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&); #endif