From 41fdc8f8ba5116a777af2916efa14bc606347351 Mon Sep 17 00:00:00 2001 From: "Alec Jacobson (jalec" Date: Tue, 29 Oct 2013 13:17:17 +0100 Subject: [PATCH] fixed examples and ambient occlusion to compile and run with embree 2.0 Former-commit-id: c16cb9ac5b26946ce7ba61e1a7d2cdc4ecf97861 --- .hgignore | 6 ++++++ examples/ambient-occlusion-mex/compile.m | 6 +++--- examples/ambient-occlusion-mex/mexFunction.cpp | 18 ++++++++---------- examples/ambient-occlusion/Makefile | 4 ++-- examples/ambient-occlusion/example.cpp | 12 ++++++------ examples/embree/example.cpp | 11 +++++++++-- examples/patches/Makefile | 11 ----------- examples/patches/example.cpp | 4 ++++ examples/patches/temp.rbr | 2 +- include/igl/embree/EmbreeIntersector.h | 8 +++----- include/igl/embree/ambient_occlusion.cpp | 12 +++++++++--- include/igl/list_to_matrix.cpp | 2 -- 12 files changed, 51 insertions(+), 45 deletions(-) diff --git a/.hgignore b/.hgignore index ee3221bab..5585bb1ca 100644 --- a/.hgignore +++ b/.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 diff --git a/examples/ambient-occlusion-mex/compile.m b/examples/ambient-occlusion-mex/compile.m index b1e335fff..7f84491a9 100644 --- a/examples/ambient-occlusion-mex/compile.m +++ b/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; diff --git a/examples/ambient-occlusion-mex/mexFunction.cpp b/examples/ambient-occlusion-mex/mexFunction.cpp index 89a4bd310..67a615847 100644 --- a/examples/ambient-occlusion-mex/mexFunction.cpp +++ b/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(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])); diff --git a/examples/ambient-occlusion/Makefile b/examples/ambient-occlusion/Makefile index d83c28ea8..aa8af751d 100644 --- a/examples/ambient-occlusion/Makefile +++ b/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 diff --git a/examples/ambient-occlusion/example.cpp b/examples/ambient-occlusion/example.cpp index 9bdcf1cd6..a2d789b23 100644 --- a/examples/ambient-occlusion/example.cpp +++ b/examples/ambient-occlusion/example.cpp @@ -15,10 +15,10 @@ #include #include #include -#include -#include #include #include +#include +#include #ifdef __APPLE__ # include @@ -48,7 +48,7 @@ Eigen::MatrixXd V,N,C,mid; Eigen::MatrixXi F; // Bounding box diagonal length double bbd; -igl::EmbreeIntersector ei; +igl::EmbreeIntersector * 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..."<(V,F); + ei = new EmbreeIntersector(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; } diff --git a/examples/embree/example.cpp b/examples/embree/example.cpp index d49ad7adb..21ae5fa4f 100644 --- a/examples/embree/example.cpp +++ b/examples/embree/example.cpp @@ -1,4 +1,5 @@ #define IGL_HEADER_ONLY +#include #include #include #include @@ -7,7 +8,6 @@ #include #include #include -#include #include #include @@ -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: "<>>>>>> 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++ diff --git a/examples/patches/example.cpp b/examples/patches/example.cpp index 07e99d411..ea40f76bd 100644 --- a/examples/patches/example.cpp +++ b/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); diff --git a/examples/patches/temp.rbr b/examples/patches/temp.rbr index 65b3e3da6..de8af8813 100644 --- a/examples/patches/temp.rbr +++ b/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 diff --git a/include/igl/embree/EmbreeIntersector.h b/include/igl/embree/EmbreeIntersector.h index b86ec1529..a13a64b6d 100644 --- a/include/igl/embree/EmbreeIntersector.h +++ b/include/igl/embree/EmbreeIntersector.h @@ -110,10 +110,8 @@ igl::EmbreeIntersector < Scalar, Index> static bool inited = false; if(!inited) { - cout<<"before rtcInit()"< // push min_t a bit more //double t_push = pow(2.0,self_hits-4)*(hit.t hit.v = ray.v; hit.t = ray.tfar; hits.push_back(hit); -#ifdef VERBOSE +#ifdef IGL_VERBOSE cout<<" t: "< +#include 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, Eigen::Matrix, Eigen::Matrix >(igl::EmbreeIntersector const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, int, Eigen::PlainObjectBase >&); template void igl::ambient_occlusion, Eigen::Matrix, Eigen::Matrix >(igl::EmbreeIntersector const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, int, Eigen::PlainObjectBase >&); +template void igl::ambient_occlusion, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, int, Eigen::PlainObjectBase >&); #endif diff --git a/include/igl/list_to_matrix.cpp b/include/igl/list_to_matrix.cpp index e5e34af77..a0284071c 100644 --- a/include/igl/list_to_matrix.cpp +++ b/include/igl/list_to_matrix.cpp @@ -7,8 +7,6 @@ #include "max_size.h" #include "min_size.h" -#define VERBOSE -#include "verbose.h" template IGL_INLINE bool igl::list_to_matrix(const std::vector > & V,Mat & M)