// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2015 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 "exterior_edges.h" #include "oriented_facets.h" #include "sort.h" #include "unique_rows.h" #include #include #include #include //template inline int sgn(T val) { // return (T(0) < val) - (val < T(0)); //} //static void mod2(std::pair, int>& p) //{ // using namespace std; // // Be sure that sign of mod matches sign of argument // p.second = p.second%2 ? sgn(p.second) : 0; //} //// http://stackoverflow.com/a/5517869/148668 //struct Compare //{ // int i; // Compare(const int& i) : i(i) {} //}; //bool operator==(const std::pair,int>&p, const Compare& c) //{ // return c.i == p.second; //} //bool operator==(const Compare& c, const std::pair, int> &p) //{ // return c.i == p.second; //} IGL_INLINE void igl::exterior_edges( const Eigen::MatrixXi & F, Eigen::MatrixXi & E) { using namespace Eigen; using namespace std; assert(F.cols() == 3); const size_t m = F.rows(); MatrixXi all_E,sall_E,sort_order; // Sort each edge by index oriented_facets(F,all_E); sort(all_E,2,true,sall_E,sort_order); // Find unique edges MatrixXi uE; VectorXi IA,EMAP; unique_rows(sall_E,uE,IA,EMAP); VectorXi counts = VectorXi::Zero(uE.rows()); for(size_t a = 0;a<3*m;a++) { counts(EMAP(a)) += (sort_order(a)==0?1:-1); } E.resize(all_E.rows(),2); { int e = 0; const size_t nue = uE.rows(); // Append each unique edge with a non-zero amount of signed occurrences for(size_t ue = 0; ue 0) { i = uE(ue,0); j = uE(ue,1); } // Append edge for every repeated entry const int abs_count = abs(count); for(int k = 0;k