فهرست منبع

Orient2d vectorized (#2492) [skip ci]

* orient2d

* missing include

* missing include

* fix include
Alec Jacobson 4 ماه پیش
والد
کامیت
b0aa5f2a1c
2فایلهای تغییر یافته به همراه51 افزوده شده و 0 حذف شده
  1. 33 0
      include/igl/predicates/orient2d.cpp
  2. 18 0
      include/igl/predicates/orient2d.h

+ 33 - 0
include/igl/predicates/orient2d.cpp

@@ -6,6 +6,8 @@
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // 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/.
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "orient2d.h"
 #include "orient2d.h"
+#include "exactinit.h"
+#include "../parallel_for.h"
 #include <predicates.h>
 #include <predicates.h>
 
 
 namespace igl {
 namespace igl {
@@ -35,6 +37,37 @@ IGL_INLINE Orientation orient2d(
   else return Orientation::COLLINEAR;
   else return Orientation::COLLINEAR;
 }
 }
 
 
+template 
+  <typename DerivedA,
+   typename DerivedB,
+   typename DerivedC,
+   typename DerivedR>
+IGL_INLINE void orient2d(
+    const Eigen::MatrixBase<DerivedA>& A,
+    const Eigen::MatrixBase<DerivedB>& B,
+    const Eigen::MatrixBase<DerivedC>& C,
+    Eigen::PlainObjectBase<DerivedR>& R)
+{
+  igl::predicates::exactinit();
+  typedef typename DerivedR::Scalar RScalar;
+  typedef typename DerivedA::Scalar Scalar;
+  typedef Eigen::Matrix<Scalar, 1, 2> RowVector2S;
+
+  // max(A.rows(),B.rows(),C.rows()) is the number of points
+  const int np = std::max(
+    std::max(A.rows(), B.rows()),C.rows());
+  R.resize(np, 1);
+  igl::parallel_for(np, [&](const int p)
+    {
+      // Not sure if these copies are needed
+      const RowVector2S a = A.row(p % A.rows());
+      const RowVector2S b = B.row(p % B.rows());
+      const RowVector2S c = C.row(p % C.rows());
+      // Compute the orientation
+      R(p) = static_cast<RScalar>(igl::predicates::orient2d(a, b, c));
+    },1000);
+}
+
 }
 }
 }
 }
 
 

+ 18 - 0
include/igl/predicates/orient2d.h

@@ -30,6 +30,24 @@ namespace igl {
         const Eigen::MatrixBase<Vector2D>& pa,
         const Eigen::MatrixBase<Vector2D>& pa,
         const Eigen::MatrixBase<Vector2D>& pb,
         const Eigen::MatrixBase<Vector2D>& pb,
         const Eigen::MatrixBase<Vector2D>& pc);
         const Eigen::MatrixBase<Vector2D>& pc);
+    /// Compute the orientation of the tetrahedron formed by each 4-tuple of
+    /// points
+    ///
+    /// @param[in] A  #P|1 by 3 matrix of 3D points
+    /// @param[in] B  #P|1 by 3 matrix of 3D points
+    /// @param[in] C  #P|1 by 3 matrix of 3D points
+    /// @param[out] R  #P vector of orientations
+    ///
+    template 
+      <typename DerivedA,
+       typename DerivedB,
+       typename DerivedC,
+       typename DerivedR>
+    IGL_INLINE void orient2d(
+        const Eigen::MatrixBase<DerivedA>& A,
+        const Eigen::MatrixBase<DerivedB>& B,
+        const Eigen::MatrixBase<DerivedC>& C,
+        Eigen::PlainObjectBase<DerivedR>& R);
   }
   }
 }
 }