Browse Source

embree hits

Former-commit-id: c636d3569b093efa3a69bee82813a435af8518f4
Alec Jacobson (jalec 12 years ago
parent
commit
027c6c3e0c

+ 1 - 2
include/igl/bounding_box_diagonal.cpp

@@ -4,8 +4,7 @@
 #include <cmath>
 
 IGL_INLINE double igl::bounding_box_diagonal(
-  const Eigen::MatrixXd & V,
-  const Eigen::MatrixXi & F)
+  const Eigen::MatrixXd & V)
 {
   using namespace igl;
   using namespace Eigen;

+ 1 - 3
include/igl/bounding_box_diagonal.h

@@ -11,9 +11,7 @@ namespace igl
   //   V  #V by 3 list of vertex positions
   //   F  #F by 3 list of triangle indices into V
   // Returns length of bounding box diagonal
-  IGL_INLINE double bounding_box_diagonal(
-    const Eigen::MatrixXd & V,
-    const Eigen::MatrixXi & F);
+  IGL_INLINE double bounding_box_diagonal( const Eigen::MatrixXd & V);
 }
 
 #ifdef IGL_HEADER_ONLY

+ 29 - 3
include/igl/embree/EmbreeIntersector.cpp

@@ -1,4 +1,5 @@
 #include "EmbreeIntersector.h"
+#include <igl/EPS.h>
 
 template <typename RowVector3>
 inline embree::Vec3f toVec3f(const RowVector3 &p) { return embree::Vec3f((float)p[0], (float)p[1], (float)p[2]); }
@@ -71,18 +72,43 @@ igl::EmbreeIntersector < PointMatrixType, FaceMatrixType, RowVector3>
   const RowVector3& direction, 
   std::vector<embree::Hit > &hits) const
 {
+  using namespace std;
   hits.clear();
-  embree::Hit hit;
   embree::Vec3f o = toVec3f(origin);
   embree::Vec3f d = toVec3f(direction);
+  int last_id0 = -1;
+  double self_hits = 0;
+  const double eps = FLOAT_EPS*2.0;
   while(true)
   {
+    //cout<<
+    //  o[0]<<" "<<o[1]<<" "<<o[2]<<" + t*"<<
+    //  d[0]<<" "<<d[1]<<" "<<d[2]<<" ---> "<<
+    //  endl;
+    embree::Hit hit;
     embree::Ray ray(o,d,embree::zero);
     _intersector->intersect(ray, hit);
     if(hit)
     {
-      hits.push_back(hit);
-      o = o+hit.t*d;
+      // Hit self again
+      if(hit.id0 == last_id0)
+      {
+        // sanity check
+        assert(hit.t<1);
+        // move off origin
+        double t_push = pow(2.0,self_hits)*(hit.t<eps?eps:hit.t);
+        o = o+t_push*d;
+        self_hits++;
+      }else
+      {
+        hits.push_back(hit);
+        //cout<<"  t: "<<hit.t<<endl;
+        o = o+hit.t*d;
+        // reset t_scale
+        self_hits = 0;
+      }
+      last_id0 = hit.id0;
+      //cout<<"  id0: "<<hit.id0<<endl;
     }else
     {
       break;

+ 4 - 1
include/igl/xml/Makefile

@@ -23,12 +23,15 @@ INC+=-I../../../include/
 EIGEN3_INC=-I$(DEFAULT_PREFIX)/include/eigen3 -I$(DEFAULT_PREFIX)/include/eigen3/unsupported
 INC+=$(EIGEN3_INC)
 
+#AntTweakbar dependency
+ANTTWEAKBAR_INC=-I../../../external/AntTweakBar/include
+
 # xml dependency
 # TODO: linux, 32 bit etc
 TINYXML2=../../../external/tinyxml2
 TINYXML2_INC=-I$(TINYXML2)
 #TINYXML2_LIB=-L$(TINYXML2) -ltinyxml2
-INC+=$(TINYXML2_INC)
+INC+=$(TINYXML2_INC) $(ANTTWEAKBAR_INC)
 
 CFLAGS+=-std=c++11