浏览代码

fixed examples and ambient occlusion to compile and run with embree 2.0

Former-commit-id: c16cb9ac5b26946ce7ba61e1a7d2cdc4ecf97861
Alec Jacobson (jalec 11 年之前
父节点
当前提交
41fdc8f8ba

+ 6 - 0
.hgignore

@@ -4,6 +4,7 @@ syntax: glob
 *.a
 *.dylib
 *~
+*CMakeFiles*
 example
 examples/bbw/bbw_demo_selfcontained/*
 examples/bbw/bbw_demo_selfcontained.zip
@@ -14,6 +15,11 @@ example1
 external/yimg/.git*
 external/tinyxml2/CMakeFiles*
 external/tinyxml2/CMakeCache.txt
+external/embree/bin/*
+external/embree/bin
+external/embree/doc/html/*
+external/embree/doc/latex/*
+*.cmake
 .DS_Store
 libigl.zip
 *tags

+ 3 - 3
examples/ambient-occlusion-mex/compile.m

@@ -2,8 +2,8 @@ mex -v -o ambient_occlusion -DMEX -largeArrayDims ...
   -I/opt/local/include/eigen3 -I/usr/local/igl/libigl/include ...
   -L/usr/local/igl/libigl/lib -ligl -liglmatlab -liglembree ...
   CXXFLAGS="\$CXXFLAGS -m64 -msse4.2 -fopenmp" ...
-  -I/usr/local/igl/libigl/external/embree/rtcore ...
-  -I/usr/local/igl/libigl/external/embree/common ...
-  -L/usr/local/igl/libigl/external/embree/bin -lrtcore -lsys ... 
+  -I/usr/local/igl/libigl/external/embree/embree/ ...
+  -I/usr/local/igl/libigl/external/embree/ ...
+  -L/usr/local/igl/libigl/external/embree/bin -lembree -lsys ... 
   mexFunction.cpp parse_rhs.cpp;
 

+ 8 - 10
examples/ambient-occlusion-mex/mexFunction.cpp

@@ -37,16 +37,14 @@ void mexFunction(int nlhs, mxArray *plhs[],
   //read("../shared/cheburashka.obj",V,F);
   //P = V;
   //per_vertex_normals(V,F,N);
-  EmbreeIntersector<::MatrixXd::Scalar,::MatrixXi::Scalar> ei;
-  ei = EmbreeIntersector<MatrixXd::Scalar,MatrixXi::Scalar>(V,F);
-  ambient_occlusion(ei,P,N,num_samples,S);
-  MatlabWorkspace mw;
-  mw.save(V,"V");
-  mw.save(P,"P");
-  mw.save(N,"N");
-  mw.save_index(F,"F");
-  mw.save(S,"S");
-  mw.write("out.mat");
+  ambient_occlusion(V,F,P,N,num_samples,S);
+  //MatlabWorkspace mw;
+  //mw.save(V,"V");
+  //mw.save(P,"P");
+  //mw.save(N,"N");
+  //mw.save_index(F,"F");
+  //mw.save(S,"S");
+  //mw.write("out.mat");
 
   plhs[0] = mxCreateDoubleMatrix(S.rows(),S.cols(), mxREAL);
   copy(S.data(),S.data()+S.size(),mxGetPr(plhs[0]));

+ 2 - 2
examples/ambient-occlusion/Makefile

@@ -9,8 +9,8 @@ all: example
 .PHONY: example
 
 LIBIGL=../../
-LIBIGL_INC=-I$(LIBIGL)/include
-LIBIGL_LIB=-L$(LIBIGL)/lib -ligl -liglembree
+LIBIGL_INC=-I$(LIBIGL)/include -DIGL_HEADER_ONLY
+#LIBIGL_LIB=-L$(LIBIGL)/lib -ligl -liglembree
 
 EIGEN3_INC=-I/opt/local/include/eigen3 -I/opt/local/include/eigen3/unsupported
 

+ 6 - 6
examples/ambient-occlusion/example.cpp

@@ -15,10 +15,10 @@
 #include <igl/material_colors.h>
 #include <igl/barycenter.h>
 #include <igl/matlab_format.h>
-#include <igl/embree/EmbreeIntersector.h>
-#include <igl/embree/ambient_occlusion.h>
 #include <igl/ReAntTweakBar.h>
 #include <igl/pathinfo.h>
+#include <igl/embree/EmbreeIntersector.h>
+#include <igl/embree/ambient_occlusion.h>
 
 #ifdef __APPLE__
 #  include <GLUT/glut.h>
@@ -48,7 +48,7 @@ Eigen::MatrixXd V,N,C,mid;
 Eigen::MatrixXi F;
 // Bounding box diagonal length
 double bbd;
-igl::EmbreeIntersector<Eigen::MatrixXd::Scalar,Eigen::MatrixXi::Scalar> ei;
+igl::EmbreeIntersector<Eigen::MatrixXd::Scalar,Eigen::MatrixXi::Scalar> * ei;
 // Running ambient occlusion
 Eigen::VectorXd S;
 int tot_num_samples = 0;
@@ -154,7 +154,7 @@ void display()
     }
     VectorXd Si;
     const int num_samples = 20;
-    ambient_occlusion(ei,V,N,num_samples,Si);
+    ambient_occlusion(*ei,V,N,num_samples,Si);
     S *= (double)tot_num_samples;
     S += Si*(double)num_samples;
     tot_num_samples += num_samples;
@@ -373,8 +373,7 @@ int main(int argc, char * argv[])
   bbd = (V.colwise().maxCoeff() - V.colwise().minCoeff()).maxCoeff();
 
   // Init embree
-  cout<<"init embree..."<<endl;
-  ei = EmbreeIntersector<MatrixXd::Scalar,MatrixXi::Scalar>(V,F);
+  ei = new EmbreeIntersector<MatrixXd::Scalar,MatrixXi::Scalar>(V,F);
 
   // Init glut
   glutInit(&argc,argv);
@@ -406,5 +405,6 @@ int main(int argc, char * argv[])
   glutMotionFunc(mouse_drag);
   glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
   glutMainLoop();
+  delete ei;
   return 0;
 }

+ 9 - 2
examples/embree/example.cpp

@@ -1,4 +1,5 @@
 #define IGL_HEADER_ONLY
+#include <igl/embree/EmbreeIntersector.h>
 #include <igl/OpenGL_convenience.h>
 #include <igl/per_face_normals.h>
 #include <igl/read.h>
@@ -7,7 +8,6 @@
 #include <igl/draw_floor.h>
 #include <igl/unproject.h>
 #include <igl/quat_to_mat.h>
-#include <igl/embree/EmbreeIntersector.h>
 #include <igl/trackball.h>
 #include <igl/report_gl_error.h>
 
@@ -417,6 +417,12 @@ void mouse_drag(int mouse_x, int mouse_y)
 }
 
 
+void cleanup()
+{
+  using namespace std;
+  delete ei;
+}
+
 void key(unsigned char key, int mouse_x, int mouse_y)
 {
   using namespace std;
@@ -425,6 +431,7 @@ void key(unsigned char key, int mouse_x, int mouse_y)
     // Ctrl-c and esc exit
     case char(3):
     case char(27):
+      cleanup();
       exit(0);
     default:
       cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
@@ -478,6 +485,6 @@ int main(int argc, char * argv[])
   glutMotionFunc(mouse_drag);
   glutPassiveMotionFunc(mouse_move);
   glutMainLoop();
-  delete ei;
+  cleanup();
   return 0;
 }

+ 0 - 11
examples/patches/Makefile

@@ -20,19 +20,8 @@ ANTTWEAKBAR_INC=-I$(LIBIGL)/external/AntTweakBar/include
 ANTTWEAKBAR_LIB=-L$(LIBIGL)/external/AntTweakBar/lib -lAntTweakBar -framework AppKit
 
 EMBREE=$(LIBIGL)/external/embree
-<<<<<<< local
-<<<<<<< local
-EMBREE_INC=-I$(EMBREE)/rtcore -I$(EMBREE)/common
-EMBREE_LIB=-L$(EMBREE)/bin -lrtcore -lsys
-=======
-=======
->>>>>>> other
 EMBREE_INC=-I$(EMBREE)/ -I$(EMBREE)/embree
 EMBREE_LIB=-L$(EMBREE)/bin -lembree -lsys
-<<<<<<< local
->>>>>>> other
-=======
->>>>>>> other
 
 MATLAB_INC=-I$(MATLAB)/extern/include/
 MATLAB_LIB=-L$(MATLAB)/bin/maci64 -lmx -lmat -lmex -lstdc++

+ 4 - 0
examples/patches/example.cpp

@@ -740,7 +740,11 @@ int main(int argc, char * argv[])
   animation_start_time = get_seconds();
 
   // Init antweakbar
+#ifdef __APPLE__
+  glutInitDisplayString( "rgba depth double samples>=8");
+#else
   glutInitDisplayString( "rgba depth double ");   // samples>=8 somehow not supported on Kenshi's machines...?
+#endif
   glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0);
   glutCreateWindow("patches");
   glutDisplayFunc(display);

+ 1 - 1
examples/patches/temp.rbr

@@ -1,5 +1,5 @@
 wireframe_visible: TW_TYPE_BOOLCPP 1
 fill_visible: TW_TYPE_BOOLCPP 1
-camera_rotation: TW_TYPE_QUAT4D 0.231837 0.00812583 0.00193725 0.972719
+camera_rotation: TW_TYPE_QUAT4D 0.20801 0.244181 0.0537125 0.945633
 rotation_type: RotationType two axis fixed up
 

+ 3 - 5
include/igl/embree/EmbreeIntersector.h

@@ -110,10 +110,8 @@ igl::EmbreeIntersector < Scalar, Index>
   static bool inited = false;
   if(!inited)
   {
-    cout<<"before rtcInit()"<<endl;
     embree::rtcInit();
-    cout<<"after rtcInit()"<<endl;
-#ifdef VERBOSE
+#ifdef IGL_VERBOSE
     embree::rtcSetVerbose(3);
 #endif
     embree::rtcStartThreads();
@@ -230,7 +228,7 @@ igl::EmbreeIntersector < Scalar, Index>
         // push min_t a bit more
         //double t_push = pow(2.0,self_hits-4)*(hit.t<eps?eps:hit.t);
         double t_push = pow(2.0,self_hits)*eps;
-#ifdef VERBOSE
+#ifdef IGL_VERBOSE
         cout<<"  t_push: "<<t_push<<endl;
 #endif
         //o = o+t_push*d;
@@ -245,7 +243,7 @@ igl::EmbreeIntersector < Scalar, Index>
         hit.v = ray.v;
         hit.t = ray.tfar;
         hits.push_back(hit);
-#ifdef VERBOSE
+#ifdef IGL_VERBOSE
         cout<<"  t: "<<hit.t<<endl;
 #endif
         // Instead of moving origin, just change min_t. That way calculations

+ 9 - 3
include/igl/embree/ambient_occlusion.cpp

@@ -1,6 +1,7 @@
 #include "ambient_occlusion.h"
 #include "EmbreeIntersector.h"
 #include <igl/random_dir.h>
+#include <igl/EPS.h>
 
 template <
   typename Scalar,
@@ -39,7 +40,8 @@ void igl::ambient_occlusion(
         d *= -1;
       }
       igl::Hit hit;
-      if(ei.intersectRay(origin,d,hit))
+      const float tnear = 1e-4f;
+      if(ei.intersectRay(origin,d,hit,tnear))
       {
         num_hits++;
       }
@@ -66,12 +68,16 @@ void igl::ambient_occlusion(
   using namespace Eigen;
   EmbreeIntersector<
     typename DerivedV::Scalar,
-    typename DerivedF::Scalar > ei(V,F);
-  return ambient_occlusion(ei,P,N,num_samples,S);
+    typename DerivedF::Scalar > * ei = new EmbreeIntersector<
+    typename DerivedV::Scalar,
+    typename DerivedF::Scalar >(V,F);
+  ambient_occlusion(*ei,P,N,num_samples,S);
+  delete ei;
 }
 
 #ifndef IGL_HEADER_ONLY
 // Explicit template instanciation
 template void igl::ambient_occlusion<double, int, 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<double, int> 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<double, int, 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<double, int> 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> >&);
+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> >&);
 #endif

+ 0 - 2
include/igl/list_to_matrix.cpp

@@ -7,8 +7,6 @@
 
 #include "max_size.h"
 #include "min_size.h"
-#define VERBOSE
-#include "verbose.h"
 
 template <typename T, class Mat>
 IGL_INLINE bool igl::list_to_matrix(const std::vector<std::vector<T > > & V,Mat & M)