#include "order_facets_around_edge.h" #include #include #include // adj_faces contains signed index starting from +- 1. template< typename DerivedV, typename DerivedF, typename DerivedI > void igl::copyleft::cgal::order_facets_around_edge( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, size_t s, size_t d, const std::vector& adj_faces, Eigen::PlainObjectBase& order, bool debug) { // Although we only need exact predicates in the algorithm, // exact constructions are needed to avoid degeneracies due to // casting to double. typedef CGAL::Exact_predicates_exact_constructions_kernel K; typedef K::Point_3 Point_3; typedef K::Plane_3 Plane_3; auto get_face_index = [&](int adj_f)->size_t { return abs(adj_f) - 1; }; auto get_opposite_vertex = [&](size_t fid)->size_t { typedef typename DerivedF::Scalar Index; if (F(fid, 0) != (Index)s && F(fid, 0) != (Index)d) return F(fid, 0); if (F(fid, 1) != (Index)s && F(fid, 1) != (Index)d) return F(fid, 1); if (F(fid, 2) != (Index)s && F(fid, 2) != (Index)d) return F(fid, 2); assert(false); return -1; }; // Handle base cases if (adj_faces.size() == 0) { order.resize(0, 1); return; } else if (adj_faces.size() == 1) { order.resize(1, 1); order(0, 0) = 0; return; } else if (adj_faces.size() == 2) { const size_t o1 = get_opposite_vertex(get_face_index(adj_faces[0])); const size_t o2 = get_opposite_vertex(get_face_index(adj_faces[1])); const Point_3 ps(V(s, 0), V(s, 1), V(s, 2)); const Point_3 pd(V(d, 0), V(d, 1), V(d, 2)); const Point_3 p1(V(o1, 0), V(o1, 1), V(o1, 2)); const Point_3 p2(V(o2, 0), V(o2, 1), V(o2, 2)); order.resize(2, 1); switch (CGAL::orientation(ps, pd, p1, p2)) { case CGAL::POSITIVE: order(0, 0) = 1; order(1, 0) = 0; break; case CGAL::NEGATIVE: order(0, 0) = 0; order(1, 0) = 1; break; case CGAL::COPLANAR: { switch (CGAL::coplanar_orientation(ps, pd, p1, p2)) { case CGAL::POSITIVE: // Duplicated face, use index to break tie. order(0, 0) = adj_faces[0] < adj_faces[1] ? 0:1; order(1, 0) = adj_faces[0] < adj_faces[1] ? 1:0; break; case CGAL::NEGATIVE: // Coplanar faces, one on each side of the edge. // It is equally valid to order them (0, 1) or (1, 0). // I cannot think of any reason to prefer one to the // other. So just use (0, 1) ordering by default. order(0, 0) = 0; order(1, 0) = 1; break; case CGAL::COLLINEAR: std::cerr << "Degenerated triangle detected." << std::endl; assert(false); break; default: assert(false); } } break; default: assert(false); } return; } const size_t num_adj_faces = adj_faces.size(); const size_t o = get_opposite_vertex( get_face_index(adj_faces[0])); const Point_3 p_s(V(s, 0), V(s, 1), V(s, 2)); const Point_3 p_d(V(d, 0), V(d, 1), V(d, 2)); const Point_3 p_o(V(o, 0), V(o, 1), V(o, 2)); const Plane_3 separator(p_s, p_d, p_o); if (separator.is_degenerate()) { throw std::runtime_error( "Cannot order facets around edge due to degenerated facets"); } std::vector opposite_vertices; for (size_t i=0; i positive_side; std::vector negative_side; std::vector tie_positive_oriented; std::vector tie_negative_oriented; std::vector positive_side_index; std::vector negative_side_index; std::vector tie_positive_oriented_index; std::vector tie_negative_oriented_index; for (size_t i=0; i& data) -> std::vector{ const size_t len = data.size(); std::vector order(len); for (size_t i=0; i tie_positive_order = index_sort(tie_positive_oriented); std::vector tie_negative_order = index_sort(tie_negative_oriented); // Copy results into order vector. const size_t tie_positive_size = tie_positive_oriented.size(); const size_t tie_negative_size = tie_negative_oriented.size(); const size_t positive_size = positive_order.size(); const size_t negative_size = negative_order.size(); order.resize( tie_positive_size + positive_size + tie_negative_size + negative_size,1); size_t count=0; for (size_t i=0; i IGL_INLINE void igl::copyleft::cgal::order_facets_around_edge( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, size_t s, size_t d, const std::vector& adj_faces, const Eigen::PlainObjectBase& pivot_point, Eigen::PlainObjectBase& order) { assert(V.cols() == 3); assert(F.cols() == 3); assert(pivot_point.cols() == 3); auto signed_index_to_index = [&](int signed_idx) { return abs(signed_idx) -1; }; auto get_opposite_vertex_index = [&](size_t fid) -> typename DerivedF::Scalar { typedef typename DerivedF::Scalar Index; if (F(fid, 0) != (Index)s && F(fid, 0) != (Index)d) return F(fid, 0); if (F(fid, 1) != (Index)s && F(fid, 1) != (Index)d) return F(fid, 1); if (F(fid, 2) != (Index)s && F(fid, 2) != (Index)d) return F(fid, 2); assert(false); // avoid warning return -1; }; { // Check if s, d and pivot are collinear. typedef CGAL::Exact_predicates_exact_constructions_kernel K; K::Point_3 ps(V(s,0), V(s,1), V(s,2)); K::Point_3 pd(V(d,0), V(d,1), V(d,2)); K::Point_3 pp(pivot_point(0,0), pivot_point(0,1), pivot_point(0,2)); if (CGAL::collinear(ps, pd, pp)) { throw std::runtime_error( "Pivot point is collinear with the outer edge!"); } } const size_t N = adj_faces.size(); const size_t num_faces = N + 1; // N adj faces + 1 pivot face // Because face indices are used for tie breaking, the original face indices // in the new faces array must be ascending. auto comp = [&](int i, int j) { return signed_index_to_index(adj_faces[i]) < signed_index_to_index(adj_faces[j]); }; std::vector adj_order(N); for (size_t i=0; i adj_faces_with_pivot(num_faces); for (size_t i=0; i, -1, -1, 1, -1, -1>, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 1, -1, -1>, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase >&, bool); // generated by autoexplicit.sh template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 1, -1, -1>, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 1, -1, -1>, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase >&, bool); template void igl::copyleft::cgal::order_facets_around_edge, -1, 3, 0, -1, 3>, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase >&, bool); template void igl::copyleft::cgal::order_facets_around_edge, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase >&, bool); template void igl::copyleft::cgal::order_facets_around_edge, -1, 3, 0, -1, 3>, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::order_facets_around_edge, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::order_facets_around_edge, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 0, -1, -1>, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase > const&, unsigned long, unsigned long, std::vector > const&, Eigen::PlainObjectBase, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase >&); #ifdef WIN32 template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 0, -1, -1>, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase> &); template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 0, -1, -1>, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase, -1, -1, 0, -1, -1>> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase> &, bool); template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 1, -1, -1>, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase> &); template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 1, -1, -1>, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase> &, bool); template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 1, -1, -1>, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase> &); template void igl::copyleft::cgal::order_facets_around_edge, -1, -1, 1, -1, -1>, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase, -1, -1, 1, -1, -1>> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase> &, bool); template void igl::copyleft::cgal::order_facets_around_edge, -1, 3, 0, -1, 3>, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase, -1, 3, 0, -1, 3>> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase, -1, 3, 0, -1, 3>> const &, class Eigen::PlainObjectBase> &); template void igl::copyleft::cgal::order_facets_around_edge, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase> const &, class Eigen::PlainObjectBase> &); template void igl::copyleft::cgal::order_facets_around_edge, class Eigen::Matrix, class Eigen::Matrix>(class Eigen::PlainObjectBase> const &, class Eigen::PlainObjectBase> const &, unsigned __int64, unsigned __int64, class std::vector> const &, class Eigen::PlainObjectBase> const &, class Eigen::PlainObjectBase> &); #endif #endif