|
@@ -4,47 +4,45 @@
|
|
|
#include "point_inside_polygon.h"
|
|
#include "point_inside_polygon.h"
|
|
|
#include "predicates.h"
|
|
#include "predicates.h"
|
|
|
|
|
|
|
|
-template <typename DerivedP>
|
|
|
|
|
-IGL_INLINE bool igl::predicates::is_ear(
|
|
|
|
|
- const Eigen::MatrixBase<DerivedP>& P,
|
|
|
|
|
- const Eigen::VectorXi& RT,
|
|
|
|
|
- const Eigen::VectorXi& L,
|
|
|
|
|
- const Eigen::VectorXi& R,
|
|
|
|
|
- const int i
|
|
|
|
|
-){
|
|
|
|
|
- typedef typename DerivedP::Scalar Scalar;
|
|
|
|
|
-
|
|
|
|
|
- int a = L(i), b = R(i);
|
|
|
|
|
- if(RT(i) != 0 || RT(a) != 0 || RT(b) != 0) return false;
|
|
|
|
|
- Eigen::RowVector2d pa = P.row(a);
|
|
|
|
|
- Eigen::RowVector2d pb = P.row(b);
|
|
|
|
|
- Eigen::RowVector2d pi = P.row(i);
|
|
|
|
|
- auto r = igl::predicates::orient2d(pa,pi,pb);
|
|
|
|
|
- if(r == igl::predicates::Orientation::NEGATIVE ||
|
|
|
|
|
- r == igl::predicates::Orientation::COLLINEAR) return false;
|
|
|
|
|
-
|
|
|
|
|
- // check if any vertex is lying inside triangle (a,b,i);
|
|
|
|
|
- int k=R(b);
|
|
|
|
|
- while(k!=a){
|
|
|
|
|
- Eigen::MatrixX2d T(3,2);
|
|
|
|
|
- T<<P.row(a),P.row(i),P.row(b);
|
|
|
|
|
- Eigen::RowVector2d q=P.row(k);
|
|
|
|
|
- if(point_inside_polygon(T,q))
|
|
|
|
|
- return false;
|
|
|
|
|
- k=R(k);
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
|
|
|
|
|
-template <typename DerivedP>
|
|
|
|
|
|
|
+template <typename DerivedP, typename DerivedRT,
|
|
|
|
|
+ typename DerivedF, typename DerivedI>
|
|
|
IGL_INLINE void igl::predicates::ear_clipping(
|
|
IGL_INLINE void igl::predicates::ear_clipping(
|
|
|
const Eigen::MatrixBase<DerivedP>& P,
|
|
const Eigen::MatrixBase<DerivedP>& P,
|
|
|
- const Eigen::VectorXi& RT,
|
|
|
|
|
- Eigen::VectorXi& I,
|
|
|
|
|
- Eigen::MatrixXi& eF,
|
|
|
|
|
|
|
+ const Eigen::MatrixBase<DerivedRT>& RT,
|
|
|
|
|
+ Eigen::PlainObjectBase<DerivedI>& I,
|
|
|
|
|
+ Eigen::PlainObjectBase<DerivedF>& eF,
|
|
|
Eigen::PlainObjectBase<DerivedP>& nP
|
|
Eigen::PlainObjectBase<DerivedP>& nP
|
|
|
){
|
|
){
|
|
|
|
|
+
|
|
|
|
|
+ // check whether vertex i is an ear
|
|
|
|
|
+ auto is_ear = [](
|
|
|
|
|
+ const Eigen::MatrixBase<DerivedP>& P,
|
|
|
|
|
+ const Eigen::MatrixBase<DerivedRT>& RT,
|
|
|
|
|
+ const Eigen::VectorXi& L,
|
|
|
|
|
+ const Eigen::VectorXi& R,
|
|
|
|
|
+ const int i
|
|
|
|
|
+ ){
|
|
|
|
|
+ int a = L(i), b = R(i);
|
|
|
|
|
+ if(RT(i) != 0 || RT(a) != 0 || RT(b) != 0) return false;
|
|
|
|
|
+ Eigen::RowVector2d pa = P.row(a);
|
|
|
|
|
+ Eigen::RowVector2d pb = P.row(b);
|
|
|
|
|
+ Eigen::RowVector2d pi = P.row(i);
|
|
|
|
|
+ auto r = igl::predicates::orient2d(pa,pi,pb);
|
|
|
|
|
+ if(r == igl::predicates::Orientation::NEGATIVE ||
|
|
|
|
|
+ r == igl::predicates::Orientation::COLLINEAR) return false;
|
|
|
|
|
+
|
|
|
|
|
+ // check if any vertex is lying inside triangle (a,b,i);
|
|
|
|
|
+ int k=R(b);
|
|
|
|
|
+ while(k!=a){
|
|
|
|
|
+ Eigen::MatrixX2d T(3,2);
|
|
|
|
|
+ T<<P.row(a),P.row(i),P.row(b);
|
|
|
|
|
+ Eigen::RowVector2d q=P.row(k);
|
|
|
|
|
+ if(igl::predicates::point_inside_polygon(T,q))
|
|
|
|
|
+ return false;
|
|
|
|
|
+ k=R(k);
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
Eigen::VectorXi L(P.rows());
|
|
Eigen::VectorXi L(P.rows());
|
|
|
Eigen::VectorXi R(P.rows());
|
|
Eigen::VectorXi R(P.rows());
|
|
@@ -109,5 +107,5 @@ IGL_INLINE void igl::predicates::ear_clipping(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
|
-template void igl::predicates::ear_clipping<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&, Eigen::Matrix<int, -1, -1, 0, -1, -1>&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
|
|
|
|
|
+template void igl::predicates::ear_clipping<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
|
#endif
|
|
#endif
|