소스 검색

bump embree version; bump sse2 to avx2 (#1648)

* bump embree version; bump sse2 to avx2

* Use default ISA instead.

* better comments

* non degenerate tests

Co-authored-by: Jérémie Dumas <[email protected]>
Alec Jacobson 5 년 전
부모
커밋
59b517a4a4
4개의 변경된 파일42개의 추가작업 그리고 35개의 파일을 삭제
  1. 1 1
      cmake/LibiglDownloadExternal.cmake
  2. 2 1
      cmake/libigl.cmake
  3. 7 3
      include/igl/Hit.h
  4. 32 30
      tests/include/igl/embree/EmbreeIntersector.cpp

+ 1 - 1
cmake/LibiglDownloadExternal.cmake

@@ -77,7 +77,7 @@ endfunction()
 function(igl_download_embree)
 	igl_download_project(embree
 		GIT_REPOSITORY https://github.com/embree/embree.git
-		GIT_TAG        v3.5.2
+		GIT_TAG        v3.12.1
 		${LIBIGL_BRANCH_OPTIONS}
 	)
 endfunction()

+ 2 - 1
cmake/libigl.cmake

@@ -301,11 +301,12 @@ if(LIBIGL_WITH_EMBREE)
   if(NOT TARGET embree)
     igl_download_embree()
 
+    # Note: On macOS, building embree as a static lib can only be done with a single ISA target.
+    set(EMBREE_MAX_ISA "DEFAULT" CACHE STRING "Selects highest ISA to support.")
     set(EMBREE_TESTING_INTENSITY 0 CACHE STRING "")
     set(EMBREE_ISPC_SUPPORT OFF CACHE BOOL " ")
     set(EMBREE_TASKING_SYSTEM "INTERNAL" CACHE BOOL " ")
     set(EMBREE_TUTORIALS OFF CACHE BOOL " ")
-    set(EMBREE_MAX_ISA "SSE2" CACHE STRING " ")
     set(EMBREE_STATIC_LIB ON CACHE BOOL " ")
     if(MSVC)
       set(EMBREE_STATIC_RUNTIME ${IGL_STATIC_RUNTIME} CACHE BOOL "Use the static version of the C/C++ runtime library.")

+ 7 - 3
include/igl/Hit.h

@@ -17,9 +17,13 @@ namespace igl
   struct Hit
   {
     int id; // primitive id
-    int gid; // geometry id
-    float u,v; // barycentric coordinates
-    float t; // distance = direction*t to intersection
+    int gid; // geometry id (not used)
+    // barycentric coordinates so that 
+    //   pos = V.row(F(id,0))*(1-u-v)+V.row(F(id,1))*u+V.row(F(id,2))*v;
+    float u,v; 
+    // parametric distance so that
+    //   pos = origin + t * dir
+    float t; 
   };
 }
 #endif 

+ 32 - 30
tests/include/igl/embree/EmbreeIntersector.cpp

@@ -15,9 +15,32 @@ TEST_CASE("EmbreeIntersector: cube", "[igl/embree]")
   igl::embree::EmbreeIntersector embree;
   embree.init(V.cast<float>(),F.cast<int>());
 
-  const int expected_id[] = {4,8,5,2,7,0};
+  // These are not expected to be exact if the hit is on a vertex of edge.
+  const int expected_id[] =  {4,8,5,2,7,0};
   const float expected_u[] = {0.5,0.5,0.5,0.5,0.5,0.5};
   const float expected_v[] = {0.5,0.0,0.0,0.0,0.5,0.0};
+  Eigen::MatrixXd hit_P(6,3);
+  for (int dim=0; dim<6; ++dim)
+  {
+    hit_P.row(dim) = 
+      V.row(F(expected_id[dim],0))*(1.f - expected_u[dim] - expected_v[dim])+
+      V.row(F(expected_id[dim],1))*expected_u[dim] + 
+      V.row(F(expected_id[dim],2))*expected_v[dim];
+  }
+  const auto test_hit = [&](const bool hitP, const igl::Hit& hit, const int dim)
+  {
+    CHECK(hitP);
+    if(hitP)
+    {
+      const Eigen::RowVectorXd hit_p = 
+        V.row(F(hit.id,0))*(1.f - hit.u - hit.v) +
+        V.row(F(hit.id,1))*hit.u + 
+        V.row(F(hit.id,2))*hit.v;
+      // hits will be along diagonal edge so expected_id may be different
+      test_common::assert_near(hit_P.row(dim),hit_p,epsilon);
+    }
+  };
+
 
   // Shoot ray from inside out
   for (int dim=0; dim<6; ++dim)
@@ -28,11 +51,7 @@ TEST_CASE("EmbreeIntersector: cube", "[igl/embree]")
     dir[dim/2] = dim%2 ? -1 : 1;
     igl::Hit hit;
     bool hitP = embree.intersectRay(pos, dir, hit);
-    CHECK(hitP);
-    REQUIRE(hit.t == Approx(0.5).margin(epsilon));
-    REQUIRE(hit.id == expected_id[dim]);
-    REQUIRE(hit.u == Approx(expected_u[dim]).margin(epsilon));
-    REQUIRE(hit.v == Approx(expected_v[dim]).margin(epsilon));
+    test_hit(hitP,hit,dim);
   }
 
   // Shoot ray from outside in
@@ -46,11 +65,7 @@ TEST_CASE("EmbreeIntersector: cube", "[igl/embree]")
 
     igl::Hit hit;
     bool hitP = embree.intersectRay(pos, dir, hit);
-    CHECK(hitP);
-    REQUIRE(hit.t == Approx(0.5).margin(epsilon));
-    REQUIRE(hit.id == expected_id[dim]);
-    REQUIRE(hit.u == Approx(expected_u[dim]).margin(epsilon));
-    REQUIRE(hit.v == Approx(expected_v[dim]).margin(epsilon));
+    test_hit(hitP,hit,dim);
   }
 
   // Rays that miss
@@ -69,29 +84,16 @@ TEST_CASE("EmbreeIntersector: cube", "[igl/embree]")
 
   // intersect beam
   {
-    Eigen::Vector3f pos(-0.5,-0.5,1);
-    Eigen::Vector3f dir(0,0,-1);
-
-    igl::Hit hit;
-    bool hitP = embree.intersectBeam(pos, dir, hit);
-    CHECK(hitP);
-    REQUIRE(hit.t == Approx(0.5).margin(epsilon));
-    REQUIRE(hit.id == 7);
-    REQUIRE(hit.u == Approx(0).margin(epsilon));
-    REQUIRE(hit.v == Approx(1).margin(epsilon));
-  }
-
-  {
-    Eigen::Vector3f pos(0.5,-1,0.5);
-    Eigen::Vector3f dir(0,1,0);
+    Eigen::Vector3f pos(1.75,0.25,0);
+    Eigen::Vector3f dir(-1,0,0);
 
     igl::Hit hit;
     bool hitP = embree.intersectBeam(pos, dir, hit);
     CHECK(hitP);
-    REQUIRE(hit.t == Approx(0.5).margin(epsilon));
-    REQUIRE(hit.id == 2);
-    REQUIRE(hit.u == Approx(0).margin(epsilon));
-    REQUIRE(hit.v == Approx(0).margin(epsilon));
+    REQUIRE(hit.t == Approx(1.25).margin(epsilon));
+    REQUIRE(hit.id == 4);
+    REQUIRE(hit.u == Approx(0.5).margin(epsilon));
+    REQUIRE(hit.v == Approx(0.25).margin(epsilon));
   }
 }