Browse Source

makefile for patches, potential fix for orient_outward_ao

Former-commit-id: a3c0b99108b2f5902ac931b981f377bf10333251
Alec Jacobson (jalec 11 years ago
parent
commit
e7288c56ad

+ 6 - 2
examples/patches/Makefile

@@ -19,6 +19,10 @@ EIGEN3_INC=-I/opt/local/include/eigen3 -I/opt/local/include/eigen3/unsupported
 ANTTWEAKBAR_INC=-I$(LIBIGL)/external/AntTweakBar/include
 ANTTWEAKBAR_LIB=-L$(LIBIGL)/external/AntTweakBar/lib -lAntTweakBar -framework AppKit
 
+EMBREE=$(LIBIGL)/external/embree
+EMBREE_INC=-I$(EMBREE)/rtcore -I$(EMBREE)/common
+EMBREE_LIB=-L$(EMBREE)/bin -lrtcore -lsys
+
 MATLAB_INC=-I$(MATLAB)/extern/include/
 MATLAB_LIB=-L$(MATLAB)/bin/maci64 -lmx -lmat -lmex -lstdc++
 
@@ -26,8 +30,8 @@ MATLAB_LIB=-L$(MATLAB)/bin/maci64 -lmx -lmat -lmex -lstdc++
 GLUT_LIB=-framework GLUT
 GLUT_INC=-framework GLUT
 
-INC=$(LIBIGL_INC) $(ANTTWEAKBAR_INC) $(EIGEN3_INC) $(MATLAB_INC) $(GLUT_INC)
-LIB=$(OPENGL_LIB) $(GLUT_LIB) $(ANTTWEAKBAR_LIB) $(LIBIGL_LIB) $(MATLAB_LIB)
+INC=$(LIBIGL_INC) $(ANTTWEAKBAR_INC) $(EIGEN3_INC) $(MATLAB_INC) $(GLUT_INC) $(EMBREE_INC)
+LIB=$(OPENGL_LIB) $(GLUT_LIB) $(ANTTWEAKBAR_LIB) $(LIBIGL_LIB) $(MATLAB_LIB) $(EMBREE_LIB)
 
 CPP_FILES=$(wildcard ./*.cpp)
 OBJ_FILES=$(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o))) 

+ 2 - 2
examples/patches/temp.rbr

@@ -1,5 +1,5 @@
-wireframe_visible: TW_TYPE_BOOLCPP 0
+wireframe_visible: TW_TYPE_BOOLCPP 1
 fill_visible: TW_TYPE_BOOLCPP 1
-camera_rotation: TW_TYPE_QUAT4D 0.0952898 0.224325 0.0220463 0.969594
+camera_rotation: TW_TYPE_QUAT4D 0.231837 0.00812583 0.00193725 0.972719
 rotation_type: RotationType two axis fixed up
 

+ 1 - 0
include/igl/embree/ambient_occlusion.cpp

@@ -76,4 +76,5 @@ void igl::ambient_occlusion(
 // Explicit template instanciation
 template void igl::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(igl::EmbreeIntersector<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, const int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
 template void igl::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
+template void igl::ambient_occlusion<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >, Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(igl::EmbreeIntersector<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >, Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
 #endif

+ 25 - 14
include/igl/embree/orient_outward_ao.cpp

@@ -66,9 +66,11 @@ IGL_INLINE void igl::orient_outward_ao(
   // uniform real between in [0, 1]
   vector<uniform_real_distribution<double>> rdist(max_threads);
   
-  // occlusion count per component: +1 when front ray is occluded, -1 when back ray is occluded
-  Matrix<int, Dynamic, 1> C_occlude_count;
-  C_occlude_count.setZero(m, 1);
+  //// occlusion count per component: +1 when front ray is occluded, -1 when back ray is occluded
+  // occlussion count per component, per back/front: C(c,0) --> number of
+  // front-side rays occluded, C(c,1) --> number of back-side rays occluded
+  Matrix<int, Dynamic, 2> C_occlude_count;
+  C_occlude_count.setZero(num_cc, 2);
   
 #pragma omp parallel for
   for (int i = 0; i < num_samples; ++i)
@@ -84,24 +86,29 @@ IGL_INLINE void igl::orient_outward_ao(
     t2 /= t_sum;
     RowVector3d p = t0 * V.row(F(f,0)) + t1 * V.row(F(f,1)) + t1 * V.row(F(f,2));
     RowVector3d n = N.row(f);
-    bool is_backside = rdist[thread_num](engine[thread_num]) < 0.5;
-    if (is_backside)
-    {
-        n *= -1;
-    }
-    Matrix<typename DerivedV::Scalar,Dynamic,1> S;
-    ambient_occlusion(ei, p, n, 1, S);
-    if (S(0) > 0)
+    //bool is_backside = rdist[thread_num](engine[thread_num]) < 0.5;
+    // Loop over front or back side
+    for(int s = 0;s<2;s++)
     {
+      if(s==1)
+      {
+          n *= -1;
+      }
+      Matrix<typename DerivedV::Scalar,Dynamic,1> S;
+      ambient_occlusion(ei, p, n, 1, S);
+      if (S(0) > 0)
+      {
 #pragma omp atomic
-        C_occlude_count(C(f)) += is_backside ? -1 : 1;
+        C_occlude_count(C(f),s)++;
+      }
     }
 
   }
   
   for(int c = 0;c<num_cc;c++)
   {
-    I(c) = C_occlude_count(c) > 0;
+    //I(c) = C_occlude_count(c) > 0;
+    I(c) = C_occlude_count(c,0) > C_occlude_count(c,1);
   }
   // flip according to I
   for(int f = 0;f<m;f++)
@@ -130,10 +137,14 @@ IGL_INLINE void igl::orient_outward_ao(
 {
   using namespace igl;
   using namespace Eigen;
+  // Both sides
+  MatrixXi F2;
+  F2.resize(F.rows()*2,F.cols());
+  F2 << F, F.rowwise().reverse().eval();
   EmbreeIntersector<
     PlainObjectBase<DerivedV>,
     PlainObjectBase<DerivedF>,
-    Matrix<typename DerivedV::Scalar,3,1> > ei(V,F);
+    Matrix<typename DerivedV::Scalar,3,1> > ei(V,F2);
   return orient_outward_ao(V, F, C, ei, num_samples, FF, I);
 }