ソースを参照

Fix https://github.com/libigl/libigl/issues/1168 (#1173)

* Replicate linking error described in https://github.com/libigl/libigl/issues/1168

* Fix https://github.com/libigl/libigl/issues/1168.

* Ensure header-only mode works.

* Disambiguate exactinit call in unit test.
Qingnan Zhou 6 年 前
コミット
e38ee99766

+ 4 - 4
cmake/LibiglDownloadExternal.cmake

@@ -139,8 +139,8 @@ endfunction()
 ## Triangle
 function(igl_download_triangle)
 	igl_download_project(triangle
-		GIT_REPOSITORY https://github.com/jdumas/triangle.git
-		GIT_TAG        2cd0672ff1f67f9f6bb8e556e84901293e637b76
+		GIT_REPOSITORY https://github.com/libigl/triangle.git
+		GIT_TAG        d284c4a843efac043c310f5fa640b17cf7d96170
 	)
 endfunction()
 
@@ -155,8 +155,8 @@ endfunction()
 ## Predicates
 function(igl_download_predicates)
 	igl_download_project(predicates
-		GIT_REPOSITORY https://github.com/libigl/libigl-predicates
-		GIT_TAG        ce494af8c90c2cc699146b61c33de102fa96635b
+		GIT_REPOSITORY https://github.com/libigl/libigl-predicates.git
+		GIT_TAG        4c57c1d3f31646b010d1d58bfbe201e75c2b2ad8
 	)
 endfunction()
 

+ 8 - 0
include/igl/predicates/predicates.cpp

@@ -27,6 +27,14 @@ using REAL = IGL_PREDICATES_REAL;
     "Shewchuk's exact predicates only support float and double")
 #endif
 
+IGL_INLINE void exactinit() {
+  static bool initialized = false;
+  if (! initialized) {
+    ::exactinit();
+    initialized = true;
+  }
+}
+
 template<typename Vector2D>
 IGL_INLINE Orientation orient2d(
     const Eigen::MatrixBase<Vector2D>& pa,

+ 4 - 0
include/igl/predicates/predicates.h

@@ -20,6 +20,10 @@ namespace igl {
       COLLINEAR=0, COPLANAR=0, COCIRCULAR=0, COSPHERICAL=0, DEGENERATE=0
     };
 
+    // Initialize internal variable used by predciates.  Must be called before
+    // using exact predicates.
+    IGL_INLINE void exactinit();
+
     // Compute the orientation of the triangle formed by pa, pb, pc.
     //
     // Input:

+ 1 - 1
tests/CMakeLists.txt

@@ -81,7 +81,7 @@ if(LIBIGL_WITH_PREDICATES)
   file(GLOB TEST_INC_FILES ./include/igl/predicates/*.h ./include/igl/predicates/*.inl)
   target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})
 
-  target_link_libraries(libigl_tests PUBLIC igl::predicates)
+  target_link_libraries(libigl_tests PUBLIC igl::predicates igl::triangle)
 endif()
 
 file(GLOB TEST_SRC_FILES ./include/igl/*.cpp)

+ 23 - 0
tests/include/igl/predicates/predicates.cpp

@@ -1,10 +1,12 @@
 #include <test_common.h>
 #include <igl/predicates/predicates.h>
 #include <limits>
+#include <igl/triangle/triangulate.h>
 
 TEST_CASE("predicates", "[igl][predicates]") {
     using namespace igl::predicates;
     using Scalar = double;
+    igl::predicates::exactinit();
 
     SECTION("2D") {
         using Point = Eigen::Matrix<Scalar, 2, 1>;
@@ -51,4 +53,25 @@ TEST_CASE("predicates", "[igl][predicates]") {
         REQUIRE(insphere(b, c, e, d, (-f).eval()) == Orientation::OUTSIDE);
         REQUIRE(insphere(f, b, d, c, e) == Orientation::INSIDE);
     }
+
+    SECTION("Predicate and triangle") {
+        Eigen::Matrix<double, -1, -1> vertices(4, 2);
+        Eigen::Matrix<double, -1, -1> holes;
+        Eigen::Matrix<int, -1, -1> edges;
+        vertices << 0.0, 0.0,
+                    1.0, 0.0,
+                    0.0, 1.0,
+                    1.0, 1.0;
+
+        Eigen::Matrix<double, -1, -1> out_vertices;
+        Eigen::Matrix<int, -1, -1> out_faces;
+
+        // Run constrained Delaunay.
+        igl::triangle::triangulate(vertices, edges, holes, "QcYY",
+                out_vertices, out_faces);
+        REQUIRE(out_vertices.rows() == 4);
+        REQUIRE(out_vertices.cols() == 2);
+        REQUIRE(out_faces.rows() == 2);
+        REQUIRE(out_faces.cols() == 3);
+    }
 }