瀏覽代碼

pull out tan_half_angle; templates

Alec Jacobson 6 年之前
父節點
當前提交
aa0faffe9f
共有 3 個文件被更改,包括 88 次插入36 次删除
  1. 16 36
      include/igl/is_intrinsic_delaunay.cpp
  2. 37 0
      include/igl/tan_half_angle.cpp
  3. 35 0
      include/igl/tan_half_angle.h

+ 16 - 36
include/igl/is_intrinsic_delaunay.cpp

@@ -7,6 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "is_intrinsic_delaunay.h"
 #include "unique_edge_map.h"
+#include "tan_half_angle.h"
 #include <cassert>
 template <
   typename Derivedl,
@@ -53,34 +54,13 @@ IGL_INLINE bool igl::is_intrinsic_delaunay(
   typedef typename Derivedl::Scalar Scalar;
   typedef typename DerivedF::Scalar Index;
 
-  //      .
-  //     /|
-  //   c/ |
-  //   /  |
-  //  /   |
-  // .α   | a
-  //  \   |
-  //   \  |
-  //   b\ |  
-  //     \| 
-  //
-  // tan(α/2)
-  const auto tan_alpha_over_2 = [](
+  const auto cot_alpha = [](
     const Scalar & a,
     const Scalar & b,
     const Scalar & c)->Scalar
   {
     // Fisher 2007
-    return sqrt(((a-b+c)*(a+b-c))/((a+b+c)*(-a+b+c)));
-  };
-
-  const auto cot_alpha = [&tan_alpha_over_2](
-    const Scalar & a,
-    const Scalar & b,
-    const Scalar & c)->Scalar
-  {
-    // Fisher 2007
-    const Scalar t = tan_alpha_over_2(a,b,c);
+    const Scalar t = tan_half_angle(a,b,c);
     return (1.0-t*t)/(2*t);
   };
 
@@ -98,19 +78,18 @@ IGL_INLINE bool igl::is_intrinsic_delaunay(
 
   const Index num_faces = F.rows();
   assert(uE2E[uei].size() == 2 && "edge should have 2 incident faces");
-  const Index he_left = uE2E[uei][0];
-  const Index he_right = uE2E[uei][1];
-  const Index f_left = he_left%num_faces;
-  const Index c_left = he_left/num_faces;
-  const Index f_right = he_right%num_faces;
-  const Index c_right = he_right/num_faces;
-
-  assert( std::abs(l(f_left,c_left)-l(f_right,c_right) < igl::EPS<Scalar>()) );
-  const Scalar e = l(f_left,c_left);
-  const Scalar a = l(f_left,(c_left+1)%3);
-  const Scalar b = l(f_left,(c_left+2)%3);
-  const Scalar c = l(f_right,(c_right+1)%3);
-  const Scalar d = l(f_right,(c_right+2)%3);
+  const Index he1 = uE2E[uei][0];
+  const Index he2 = uE2E[uei][1];
+  const Index f1 = he1%num_faces;
+  const Index c1 = he1/num_faces;
+  const Index f2 = he2%num_faces;
+  const Index c2 = he2/num_faces;
+  assert( std::abs(l(f1,c1)-l(f2,c2) < igl::EPS<Scalar>()) );
+  const Scalar e = l(f1,c1);
+  const Scalar a = l(f1,(c1+1)%3);
+  const Scalar b = l(f1,(c1+2)%3);
+  const Scalar c = l(f2,(c2+1)%3);
+  const Scalar d = l(f2,(c2+2)%3);
 
   const Scalar w = cot_alpha(e,a,b) + cot_alpha(e,c,d);
   return w >= 0;
@@ -119,5 +98,6 @@ IGL_INLINE bool igl::is_intrinsic_delaunay(
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // generated by autoexplicit.sh
+template bool igl::is_intrinsic_delaunay<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, int, unsigned long>(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, unsigned long);
 template void igl::is_intrinsic_delaunay<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<bool, -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<bool, -1, -1, 0, -1, -1> >&);
 #endif

+ 37 - 0
include/igl/tan_half_angle.cpp

@@ -0,0 +1,37 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
+// 
+// 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 "tan_half_angle.h"
+#include <cmath>
+template < typename Scalar>
+IGL_INLINE Scalar igl::tan_half_angle(
+  const Scalar & a,
+  const Scalar & b,
+  const Scalar & c)
+{
+  //      .
+  //     /|
+  //   c/ |
+  //   /  |
+  //  /   |
+  // .α   | a
+  //  \   |
+  //   \  |
+  //   b\ |  
+  //     \| 
+  //
+  // tan(α/2)
+  // Fisher 2007
+  return sqrt(((a-b+c)*(a+b-c))/((a+b+c)*(-a+b+c)));
+}
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template instantiation
+// generated by autoexplicit.sh
+template double igl::tan_half_angle<double>(double const&, double const&, double const&);
+#endif

+ 35 - 0
include/igl/tan_half_angle.h

@@ -0,0 +1,35 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
+// 
+// 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/.
+#ifndef IGL_TAN_HALF_ANGLE_H
+#define IGL_TAN_HALF_ANGLE_H
+#include "igl_inline.h"
+namespace igl
+{
+  // TAN_HALF_ANGLE Compute the tangent of half of the angle opposite the side
+  // with length a, in a triangle with side lengths (a,b,c).
+  //
+  // Inputs:
+  //   a  scalar edge length of first side of triangle
+  //   b  scalar edge length of second side of triangle
+  //   c  scalar edge length of third side of triangle
+  // Returns tangent of half of the angle opposite side with length a
+  //
+  // See also: is_intrinsic_delaunay
+  template < typename Scalar>
+  IGL_INLINE Scalar tan_half_angle(
+    const Scalar & a,
+    const Scalar & b,
+    const Scalar & c);
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "tan_half_angle.cpp"
+#endif
+
+#endif
+