// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2015 Qingnan Zhou // Copyright (C) 2021 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 "outer_vertex.h" #include "outer_edge.h" #include #include template < typename DerivedV, typename DerivedF, typename DerivedI, typename IndexType, typename DerivedA > IGL_INLINE void igl::copyleft::cgal::outer_vertex( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, const Eigen::PlainObjectBase & I, IndexType & v_index, Eigen::PlainObjectBase & A) { // Algorithm: // Find an outer vertex (i.e. vertex reachable from infinity) // Return the vertex with the largest X value. // If there is a tie, pick the one with largest Y value. // If there is still a tie, pick the one with the largest Z value. // If there is still a tie, then there are duplicated vertices within the // mesh, which violates the precondition. typedef typename DerivedF::Scalar Index; const Index INVALID = std::numeric_limits::max(); const size_t num_selected_faces = I.rows(); std::vector candidate_faces; Index outer_vid = INVALID; typename DerivedV::Scalar outer_val = 0; for (size_t i=0; i outer_val) { outer_val = vx; outer_vid = v; candidate_faces = {f}; } else if (v == outer_vid) { candidate_faces.push_back(f); } else if (vx == outer_val) { // Break tie. auto vy = V(v,1); auto vz = V(v, 2); auto outer_y = V(outer_vid, 1); auto outer_z = V(outer_vid, 2); assert(!(vy == outer_y && vz == outer_z)); bool replace = (vy > outer_y) || ((vy == outer_y) && (vz > outer_z)); if (replace) { outer_val = vx; outer_vid = v; candidate_faces = {f}; } } } } assert(outer_vid != INVALID); assert(candidate_faces.size() > 0); v_index = outer_vid; A.resize(candidate_faces.size()); std::copy(candidate_faces.begin(), candidate_faces.end(), A.data()); } #ifdef IGL_STATIC_LIBRARY #include // Explicit template instantiation // generated by autoexplicit.sh #include template void igl::copyleft::cgal::outer_vertex, Eigen::Matrix, Eigen::Matrix, std::ptrdiff_t, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::ptrdiff_t&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::outer_vertex, Eigen::Matrix, Eigen::Matrix, std::ptrdiff_t, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::ptrdiff_t&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::outer_vertex, Eigen::Matrix, Eigen::Matrix, std::ptrdiff_t, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::ptrdiff_t&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::outer_vertex, Eigen::Matrix, Eigen::Matrix, std::ptrdiff_t, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::ptrdiff_t&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::outer_vertex, Eigen::Matrix, Eigen::Matrix, std::ptrdiff_t, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::ptrdiff_t&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::outer_vertex, Eigen::Matrix, Eigen::Matrix, std::ptrdiff_t, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::ptrdiff_t&, Eigen::PlainObjectBase >&); // Linux template void igl::copyleft::cgal::outer_vertex, Eigen::Matrix, Eigen::Matrix, std::ptrdiff_t, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, std::ptrdiff_t&, Eigen::PlainObjectBase >&); #ifdef WIN32 template void __cdecl igl::copyleft::cgal::outer_vertex,class Eigen::Matrix,class Eigen::Matrix,__int64,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::PlainObjectBase > const &,class Eigen::PlainObjectBase > const &,class Eigen::PlainObjectBase > const &,__int64 &,class Eigen::PlainObjectBase > &); template void __cdecl igl::copyleft::cgal::outer_vertex,class Eigen::Matrix,class Eigen::Matrix,__int64,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::PlainObjectBase > const &,class Eigen::PlainObjectBase > const &,class Eigen::PlainObjectBase > const &,__int64 &,class Eigen::PlainObjectBase > &); template void __cdecl igl::copyleft::cgal::outer_vertex,class Eigen::Matrix,class Eigen::Matrix,__int64,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::PlainObjectBase > const &,class Eigen::PlainObjectBase > const &,class Eigen::PlainObjectBase > const &,__int64 &,class Eigen::PlainObjectBase > &); #endif #endif