Browse Source

hit class and continue trying to get embreeintersector to work on mac os x (not yet)

Former-commit-id: f9f6def936b772829caba2ab1e40f8b341bf2b15
Alec Jacobson (jalec 11 years ago
parent
commit
2796dccbe6

+ 1 - 0
.hgignore

@@ -18,6 +18,7 @@ external/tinyxml2/CMakeCache.txt
 external/embree/bin/*
 external/embree/doc/html/*
 external/embree/doc/latex/*
+*.cmake
 .DS_Store
 libigl.zip
 *tags

+ 2 - 2
examples/ambient-occlusion-mex/mexFunction.cpp

@@ -37,8 +37,8 @@ void mexFunction(int nlhs, mxArray *plhs[],
   //read("../shared/cheburashka.obj",V,F);
   //P = V;
   //per_vertex_normals(V,F,N);
-  EmbreeIntersector<Eigen::MatrixXd,Eigen::MatrixXi,Eigen::Vector3d> ei;
-  ei = EmbreeIntersector<MatrixXd,MatrixXi,Vector3d>(V,F);
+  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");

+ 5 - 2
examples/ambient-occlusion/Makefile

@@ -14,9 +14,12 @@ LIBIGL_LIB=-L$(LIBIGL)/lib -ligl -liglembree
 
 EIGEN3_INC=-I/opt/local/include/eigen3 -I/opt/local/include/eigen3/unsupported
 
+#EMBREE=$(LIBIGL)/external/embree
+#EMBREE_INC=-I$(EMBREE)/rtcore -I$(EMBREE)/common
+#EMBREE_LIB=-L$(EMBREE)/bin -lrtcore -lsys
 EMBREE=$(LIBIGL)/external/embree
-EMBREE_INC=-I$(EMBREE)/rtcore -I$(EMBREE)/common
-EMBREE_LIB=-L$(EMBREE)/bin -lrtcore -lsys
+EMBREE_INC=-I$(EMBREE)/ -I$(EMBREE)/embree
+EMBREE_LIB=-L$(EMBREE)/bin -lembree -lsys
 
 ANTTWEAKBAR_INC=-I$(LIBIGL)/external/AntTweakBar/include
 ANTTWEAKBAR_LIB=-L$(LIBIGL)/external/AntTweakBar/lib -lAntTweakBar -framework AppKit

+ 3 - 2
examples/ambient-occlusion/example.cpp

@@ -48,7 +48,7 @@ Eigen::MatrixXd V,N,C,mid;
 Eigen::MatrixXi F;
 // Bounding box diagonal length
 double bbd;
-igl::EmbreeIntersector<Eigen::MatrixXd,Eigen::MatrixXi,Eigen::Vector3d> ei;
+igl::EmbreeIntersector<Eigen::MatrixXd::Scalar,Eigen::MatrixXi::Scalar> ei;
 // Running ambient occlusion
 Eigen::VectorXd S;
 int tot_num_samples = 0;
@@ -373,7 +373,8 @@ int main(int argc, char * argv[])
   bbd = (V.colwise().maxCoeff() - V.colwise().minCoeff()).maxCoeff();
 
   // Init embree
-  ei = EmbreeIntersector<MatrixXd,MatrixXi,Vector3d>(V,F);
+  cout<<"init embree..."<<endl;
+  ei = EmbreeIntersector<MatrixXd::Scalar,MatrixXi::Scalar>(V,F);
 
   // Init glut
   glutInit(&argc,argv);

+ 4 - 2
examples/embree/Makefile

@@ -15,14 +15,16 @@ LIBIGL_LIB=-L$(LIBIGL)/lib -ligl -liglembree
 EIGEN3_INC=-I/opt/local/include/eigen3 -I/opt/local/include/eigen3/unsupported
 
 EMBREE=$(LIBIGL)/external/embree
-EMBREE_INC=-I$(EMBREE)/rtcore -I$(EMBREE)/common
-EMBREE_LIB=-L$(EMBREE)/bin -lrtcore -lsys
+EMBREE_INC=-I$(EMBREE)/ -I$(EMBREE)/embree
+EMBREE_LIB=-L$(EMBREE)/bin -lembree -lsys
 
 ANTTWEAKBAR_INC=-I$(LIBIGL)/external/AntTweakBar/include
 ANTTWEAKBAR_LIB=-L$(LIBIGL)/external/AntTweakBar/lib -lAntTweakBar -framework AppKit
 INC=$(LIBIGL_INC) $(ANTTWEAKBAR_INC) $(EIGEN3_INC) $(EMBREE_INC)
 LIB=$(OPENGL_LIB) $(GLUT_LIB) $(ANTTWEAKBAR_LIB) $(LIBIGL_LIB) $(EMBREE_LIB)
 
+CFLAGS+=-g
+
 example: example.o
 	g++ $(OPENMP) $(AFLAGS) $(CFLAGS) -o example example.o $(LIB)
 

+ 472 - 471
examples/embree/example.cpp

@@ -1,482 +1,483 @@
-#define IGL_HEADER_ONLY
-#include <igl/OpenGL_convenience.h>
-#include <igl/per_face_normals.h>
-#include <igl/read.h>
-#include <igl/normalize_row_lengths.h>
-#include <igl/draw_mesh.h>
-#include <igl/draw_floor.h>
-#include <igl/unproject.h>
-#include <igl/quat_to_mat.h>
+//#define IGL_HEADER_ONLY
+//#include <igl/OpenGL_convenience.h>
+//#include <igl/per_face_normals.h>
+//#include <igl/read.h>
+//#include <igl/normalize_row_lengths.h>
+//#include <igl/draw_mesh.h>
+//#include <igl/draw_floor.h>
+//#include <igl/unproject.h>
+//#include <igl/quat_to_mat.h>
+//#include <igl/trackball.h>
+//#include <igl/report_gl_error.h>
 #include <igl/embree/EmbreeIntersector.h>
-#include <igl/trackball.h>
-#include <igl/report_gl_error.h>
 
-#ifdef __APPLE__
-#  include <GLUT/glut.h>
-#else
-#  include <GL/glut.h>
-#endif
-#include <Eigen/Core>
-
-#include <vector>
+//#ifdef __APPLE__
+//#  include <GLUT/glut.h>
+//#else
+//#  include <GL/glut.h>
+//#endif
+//#include <Eigen/Core>
+//
+//#include <vector>
 #include <iostream>
 
-// Width and height of window
-int width,height;
-// Rotation of scene
-float scene_rot[4] = {0,0,0,1};
-// information at mouse down
-float down_scene_rot[4] = {0,0,0,1};
-bool trackball_on = false;
-int down_mouse_x,down_mouse_y;
-// Position of light
-float light_pos[4] = {0.1,0.1,-0.9,0};
-// Vertex positions, normals, colors and centroid
-Eigen::MatrixXd V,N,C,mean;
-// Bounding box diagonal length
-double bbd;
-// Faces
-Eigen::MatrixXi F;
+//// Width and height of window
+//int width,height;
+//// Rotation of scene
+//float scene_rot[4] = {0,0,0,1};
+//// information at mouse down
+//float down_scene_rot[4] = {0,0,0,1};
+//bool trackball_on = false;
+//int down_mouse_x,down_mouse_y;
+//// Position of light
+//float light_pos[4] = {0.1,0.1,-0.9,0};
+//// Vertex positions, normals, colors and centroid
+//Eigen::MatrixXd V,N,C,mean;
+//// Bounding box diagonal length
+//double bbd;
+//// Faces
+//Eigen::MatrixXi F;
 // Embree intersection structure
 igl::EmbreeIntersector<double,int> ei;
-// Hits collected
-std::vector<igl::Hit > hits;
-// Ray information, "projection screen" corners
-Eigen::Vector3d win_s,s,d,dir,NW,NE,SE,SW;
-// Textures and framebuffers for "projection screen"
-GLuint tex_id = 0, fbo_id = 0, dfbo_id = 0;
-
-// Initialize textures and framebuffers. Must be called if window changes
-// dimension
-void init_texture()
-{
-  using namespace igl;
-  using namespace std;
-  // Set up a "render-to-texture" frame buffer and texture combo
-  glDeleteTextures(1,&tex_id);
-  glDeleteFramebuffersEXT(1,&fbo_id);
-  glDeleteFramebuffersEXT(1,&dfbo_id);
-  // http://www.opengl.org/wiki/Framebuffer_Object_Examples#Quick_example.2C_render_to_texture_.282D.29
-  glGenTextures(1, &tex_id);
-  glBindTexture(GL_TEXTURE_2D, tex_id);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-  //NULL means reserve texture memory, but texels are undefined
-  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-  glBindTexture(GL_TEXTURE_2D, 0);
-  //-------------------------
-  glGenFramebuffersEXT(1, &fbo_id);
-  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id);
-  //Attach 2D texture to this FBO
-  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex_id, 0);
-  glGenRenderbuffersEXT(1, &dfbo_id);
-  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dfbo_id);
-  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);
-  //-------------------------
-  //Attach depth buffer to FBO
-  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, dfbo_id);
-  //-------------------------
-  //Does the GPU support current FBO configuration?
-  GLenum status;
-  status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-  switch(status)
-  {
-    case GL_FRAMEBUFFER_COMPLETE_EXT:
-      break;
-    default:
-      cout<<"error"<<endl;
-  }
-  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-}
-
-void reshape(int width,int height)
-{
-  using namespace std;
-  // Save width and height
-  ::width = width;
-  ::height = height;
-  // Re-initialize textures and frame bufferes
-  init_texture();
-  glMatrixMode(GL_PROJECTION);
-  glLoadIdentity();
-  glViewport(0,0,width,height);
-}
-
-// Set up double-sided lights
-void lights()
-{
-  using namespace std;
-  glEnable(GL_LIGHTING);
-  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
-  glEnable(GL_LIGHT0);
-  glEnable(GL_LIGHT1);
-  float ones[4] = {1.0,1.0,1.0,1.0};
-  float zeros[4] = {0.0,0.0,0.0,0.0};
-  float pos[4];
-  copy(light_pos,light_pos+4,pos);
-  glLightfv(GL_LIGHT0,GL_AMBIENT,zeros);
-  glLightfv(GL_LIGHT0,GL_DIFFUSE,ones);
-  glLightfv(GL_LIGHT0,GL_SPECULAR,zeros);
-  glLightfv(GL_LIGHT0,GL_POSITION,pos);
-  pos[0] *= -1;
-  pos[1] *= -1;
-  pos[2] *= -1;
-  glLightfv(GL_LIGHT1,GL_AMBIENT,zeros);
-  glLightfv(GL_LIGHT1,GL_DIFFUSE,ones);
-  glLightfv(GL_LIGHT1,GL_SPECULAR,zeros);
-  glLightfv(GL_LIGHT1,GL_POSITION,pos);
-}
-
-// Set up projection and model view of scene
-void push_scene()
-{
-  using namespace igl;
-  glMatrixMode(GL_PROJECTION);
-  glLoadIdentity();
-  gluPerspective(45,(double)width/(double)height,1e-2,100);
-  glMatrixMode(GL_MODELVIEW);
-  glLoadIdentity();
-  gluLookAt(0,0,3,0,0,0,0,1,0);
-  glPushMatrix();
-  float mat[4*4];
-  quat_to_mat(scene_rot,mat);
-  glMultMatrixf(mat);
-}
-
-void pop_scene()
-{
-  glPopMatrix();
-}
-
-// Scale and shift for object
-void push_object()
-{
-  glPushMatrix();
-  glScaled(2./bbd,2./bbd,2./bbd);
-  glTranslated(-mean(0,0),-mean(0,1),-mean(0,2));
-}
-
-void pop_object()
-{
-  glPopMatrix();
-}
-
-const float back[4] = {190.0/255.0,190.0/255.0,190.0/255.0,0};
-void display()
-{
-  using namespace Eigen;
-  using namespace igl;
-  using namespace std;
-  glClearColor(back[0],back[1],back[2],0);
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-  // All smooth points
-  glEnable( GL_POINT_SMOOTH );
-
-  lights();
-  push_scene();
-  glEnable(GL_DEPTH_TEST);
-  glDepthFunc(GL_LEQUAL);
-  glEnable(GL_NORMALIZE);
-  glEnable(GL_COLOR_MATERIAL);
-  glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
-  push_object();
-
-  if(trackball_on)
-  {
-    // Draw a "laser" line
-    glLineWidth(3.0);
-    glDisable(GL_LIGHTING);
-    glEnable(GL_DEPTH_TEST);
-    glBegin(GL_LINES);
-    glColor3f(1,0,0);
-    glVertex3dv(s.data());
-    glColor3f(1,0,0);
-    glVertex3dv(d.data());
-    glEnd();
-
-    // Draw the start and end points used for ray
-    glPointSize(10.0);
-    glBegin(GL_POINTS);
-    glColor3f(1,0,0);
-    glVertex3dv(s.data());
-    glColor3f(0,0,1);
-    glVertex3dv(d.data());
-    glEnd();
-  }
-
-  // Draw the model
-  glEnable(GL_LIGHTING);
-  draw_mesh(V,F,N,C);
-
-  // Draw all hits
-  glBegin(GL_POINTS);
-  glColor3f(0,0.2,0.2);
-  for(vector<igl::Hit>::iterator hit = hits.begin();
-      hit != hits.end();
-      hit++)
-  {
-    const double w0 = (1.0-hit->u-hit->v);
-    const double w1 = hit->u;
-    const double w2 = hit->v;
-    VectorXd hitP = 
-      w0 * V.row(F(hit->id,0)) + 
-      w1 * V.row(F(hit->id,1)) + 
-      w2 * V.row(F(hit->id,2));
-    glVertex3dv(hitP.data());
-  }
-  glEnd();
-
-  pop_object();
-
-  // Draw a nice floor
-  glPushMatrix();
-  glEnable(GL_LIGHTING);
-  glTranslated(0,-1,0);
-  draw_floor();
-  glPopMatrix();
-
-  // draw a transparent "projection screen" show model at time of hit (aka
-  // mouse down)
-  push_object();
-  if(trackball_on)
-  {
-    glColor4f(0,0,0,1.0);
-    glPointSize(10.0);
-    glBegin(GL_POINTS);
-    glVertex3dv(SW.data());
-    glVertex3dv(SE.data());
-    glVertex3dv(NE.data());
-    glVertex3dv(NW.data());
-    glEnd();
-
-    glDisable(GL_LIGHTING);
-    glEnable(GL_TEXTURE_2D);
-    glBindTexture(GL_TEXTURE_2D, tex_id);
-    glColor4f(1,1,1,0.7);
-    glBegin(GL_QUADS);
-    glTexCoord2d(0,0);
-    glVertex3dv(SW.data());
-    glTexCoord2d(1,0);
-    glVertex3dv(SE.data());
-    glTexCoord2d(1,1);
-    glVertex3dv(NE.data());
-    glTexCoord2d(0,1);
-    glVertex3dv(NW.data());
-    glEnd();
-    glBindTexture(GL_TEXTURE_2D, 0);
-    glDisable(GL_TEXTURE_2D);
-  }
-  pop_object();
-  pop_scene();
-
-  // Draw a faint point over mouse
-  if(!trackball_on)
-  {
-    glDisable(GL_LIGHTING);
-    glDisable(GL_COLOR_MATERIAL);
-    glDisable(GL_DEPTH_TEST);
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
-    glColor4f(1.0,0.3,0.3,0.6);
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-    gluOrtho2D(0,width,0,height);
-    glMatrixMode(GL_MODELVIEW);
-    glLoadIdentity();
-    glPointSize(20.0);
-    glBegin(GL_POINTS);
-    glVertex2dv(win_s.data());
-    glEnd();
-  }
-  report_gl_error();
-
-  glutSwapBuffers();
-  glutPostRedisplay();
-}
-
-// Initialize colors to a boring green
-void init_C()
-{
-  C.col(0).setConstant(0.4);
-  C.col(1).setConstant(0.8);
-  C.col(2).setConstant(0.3);
-}
-
-void mouse_move(int mouse_x, int mouse_y)
-{
-  using namespace std;
-  using namespace Eigen;
-  using namespace igl;
-  using namespace std;
-  init_C();
-  glutSetCursor(GLUT_CURSOR_CROSSHAIR);
-  // Push scene and object
-  push_scene();
-  push_object();
-  // Unproject mouse at 0 depth and some positive depth
-  win_s = Vector3d(mouse_x,height-mouse_y,0);
-  Vector3d win_d(mouse_x,height-mouse_y,1);
-  unproject(win_s,s);
-  unproject(win_d,d);
-  pop_object();
-  pop_scene();
-  report_gl_error();
-  // Shoot ray at unprojected mouse in view direction
-  dir = d-s;
-  int num_rays_shot;
-  ei.intersectRay(s,dir,hits,num_rays_shot);
-  for(vector<igl::Hit>::iterator hit = hits.begin();
-      hit != hits.end();
-      hit++)
-  {
-    // Change color of hit faces
-    C(hit->id,0) = 1;
-    C(hit->id,1) = 0.4;
-    C(hit->id,2) = 0.4;
-  }
-}
-
-void mouse(int glutButton, int glutState, int mouse_x, int mouse_y)
-{
-  using namespace std;
-  using namespace Eigen;
-  using namespace igl;
-  switch(glutState)
-  {
-    case 1:
-      // up
-      glutSetCursor(GLUT_CURSOR_CROSSHAIR);
-      trackball_on = false;
-      hits.clear();
-      init_C();
-      break;
-    case 0:
-      // be sure this has been called recently
-      mouse_move(mouse_x,mouse_y);
-      // down
-      glutSetCursor(GLUT_CURSOR_CYCLE);
-      // collect information for trackball
-      trackball_on = true;
-      copy(scene_rot,scene_rot+4,down_scene_rot);
-      down_mouse_x = mouse_x;
-      down_mouse_y = mouse_y;
-      // Collect "projection screen" locations
-      push_scene();
-      push_object();
-      // unproject corners of window
-      const double depth = 0.999;
-      Vector3d win_NW(    0,height,depth);
-      Vector3d win_NE(width,height,depth);
-      Vector3d win_SE(width,0,depth);
-      Vector3d win_SW(0,0,depth);
-      unproject(win_NW,NW);
-      unproject(win_NE,NE);
-      unproject(win_SE,SE);
-      unproject(win_SW,SW);
-      // render to framebuffer
-      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id);
-      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dfbo_id);
-      glClearColor(0,0,0,1);
-      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-      // Render the model ---> to the framebuffer attached to the "projection
-      // screen" texture
-      glEnable(GL_COLOR_MATERIAL);
-      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
-      glEnable(GL_LIGHTING);
-      glEnable(GL_DEPTH_TEST);
-      draw_mesh(V,F,N,C);
-      pop_object();
-      pop_scene();
-      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-    break;
-  }
-}
-
-void mouse_drag(int mouse_x, int mouse_y)
-{
-  using namespace igl;
-
-  if(trackball_on)
-  {
-    // Rotate according to trackball
-    trackball<float>(
-      width,
-      height,
-      2,
-      down_scene_rot,
-      down_mouse_x,
-      down_mouse_y,
-      mouse_x,
-      mouse_y,
-      scene_rot);
-  }
-}
-
-
-void key(unsigned char key, int mouse_x, int mouse_y)
-{
-  using namespace std;
-  switch(key)
-  {
-    // Ctrl-c and esc exit
-    case char(3):
-    case char(27):
-      exit(0);
-    default:
-      cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
-  }
-  
-}
-
-int main(int argc, char * argv[])
+//// Hits collected
+//std::vector<igl::Hit > hits;
+//// Ray information, "projection screen" corners
+//Eigen::Vector3d win_s,s,d,dir,NW,NE,SE,SW;
+//// Textures and framebuffers for "projection screen"
+//GLuint tex_id = 0, fbo_id = 0, dfbo_id = 0;
+//
+//// Initialize textures and framebuffers. Must be called if window changes
+//// dimension
+//void init_texture()
+//{
+//  using namespace igl;
+//  using namespace std;
+//  // Set up a "render-to-texture" frame buffer and texture combo
+//  glDeleteTextures(1,&tex_id);
+//  glDeleteFramebuffersEXT(1,&fbo_id);
+//  glDeleteFramebuffersEXT(1,&dfbo_id);
+//  // http://www.opengl.org/wiki/Framebuffer_Object_Examples#Quick_example.2C_render_to_texture_.282D.29
+//  glGenTextures(1, &tex_id);
+//  glBindTexture(GL_TEXTURE_2D, tex_id);
+//  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+//  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+//  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+//  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+//  //NULL means reserve texture memory, but texels are undefined
+//  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+//  glBindTexture(GL_TEXTURE_2D, 0);
+//  //-------------------------
+//  glGenFramebuffersEXT(1, &fbo_id);
+//  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id);
+//  //Attach 2D texture to this FBO
+//  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex_id, 0);
+//  glGenRenderbuffersEXT(1, &dfbo_id);
+//  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dfbo_id);
+//  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);
+//  //-------------------------
+//  //Attach depth buffer to FBO
+//  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, dfbo_id);
+//  //-------------------------
+//  //Does the GPU support current FBO configuration?
+//  GLenum status;
+//  status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+//  switch(status)
+//  {
+//    case GL_FRAMEBUFFER_COMPLETE_EXT:
+//      break;
+//    default:
+//      cout<<"error"<<endl;
+//  }
+//  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+//  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+//}
+//
+//void reshape(int width,int height)
+//{
+//  using namespace std;
+//  // Save width and height
+//  ::width = width;
+//  ::height = height;
+//  // Re-initialize textures and frame bufferes
+//  init_texture();
+//  glMatrixMode(GL_PROJECTION);
+//  glLoadIdentity();
+//  glViewport(0,0,width,height);
+//}
+//
+//// Set up double-sided lights
+//void lights()
+//{
+//  using namespace std;
+//  glEnable(GL_LIGHTING);
+//  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
+//  glEnable(GL_LIGHT0);
+//  glEnable(GL_LIGHT1);
+//  float ones[4] = {1.0,1.0,1.0,1.0};
+//  float zeros[4] = {0.0,0.0,0.0,0.0};
+//  float pos[4];
+//  copy(light_pos,light_pos+4,pos);
+//  glLightfv(GL_LIGHT0,GL_AMBIENT,zeros);
+//  glLightfv(GL_LIGHT0,GL_DIFFUSE,ones);
+//  glLightfv(GL_LIGHT0,GL_SPECULAR,zeros);
+//  glLightfv(GL_LIGHT0,GL_POSITION,pos);
+//  pos[0] *= -1;
+//  pos[1] *= -1;
+//  pos[2] *= -1;
+//  glLightfv(GL_LIGHT1,GL_AMBIENT,zeros);
+//  glLightfv(GL_LIGHT1,GL_DIFFUSE,ones);
+//  glLightfv(GL_LIGHT1,GL_SPECULAR,zeros);
+//  glLightfv(GL_LIGHT1,GL_POSITION,pos);
+//}
+//
+//// Set up projection and model view of scene
+//void push_scene()
+//{
+//  using namespace igl;
+//  glMatrixMode(GL_PROJECTION);
+//  glLoadIdentity();
+//  gluPerspective(45,(double)width/(double)height,1e-2,100);
+//  glMatrixMode(GL_MODELVIEW);
+//  glLoadIdentity();
+//  gluLookAt(0,0,3,0,0,0,0,1,0);
+//  glPushMatrix();
+//  float mat[4*4];
+//  quat_to_mat(scene_rot,mat);
+//  glMultMatrixf(mat);
+//}
+//
+//void pop_scene()
+//{
+//  glPopMatrix();
+//}
+//
+//// Scale and shift for object
+//void push_object()
+//{
+//  glPushMatrix();
+//  glScaled(2./bbd,2./bbd,2./bbd);
+//  glTranslated(-mean(0,0),-mean(0,1),-mean(0,2));
+//}
+//
+//void pop_object()
+//{
+//  glPopMatrix();
+//}
+//
+//const float back[4] = {190.0/255.0,190.0/255.0,190.0/255.0,0};
+//void display()
+//{
+//  using namespace Eigen;
+//  using namespace igl;
+//  using namespace std;
+//  glClearColor(back[0],back[1],back[2],0);
+//  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+//  // All smooth points
+//  glEnable( GL_POINT_SMOOTH );
+//
+//  lights();
+//  push_scene();
+//  glEnable(GL_DEPTH_TEST);
+//  glDepthFunc(GL_LEQUAL);
+//  glEnable(GL_NORMALIZE);
+//  glEnable(GL_COLOR_MATERIAL);
+//  glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
+//  push_object();
+//
+//  if(trackball_on)
+//  {
+//    // Draw a "laser" line
+//    glLineWidth(3.0);
+//    glDisable(GL_LIGHTING);
+//    glEnable(GL_DEPTH_TEST);
+//    glBegin(GL_LINES);
+//    glColor3f(1,0,0);
+//    glVertex3dv(s.data());
+//    glColor3f(1,0,0);
+//    glVertex3dv(d.data());
+//    glEnd();
+//
+//    // Draw the start and end points used for ray
+//    glPointSize(10.0);
+//    glBegin(GL_POINTS);
+//    glColor3f(1,0,0);
+//    glVertex3dv(s.data());
+//    glColor3f(0,0,1);
+//    glVertex3dv(d.data());
+//    glEnd();
+//  }
+//
+//  // Draw the model
+//  glEnable(GL_LIGHTING);
+//  draw_mesh(V,F,N,C);
+//
+//  // Draw all hits
+//  glBegin(GL_POINTS);
+//  glColor3f(0,0.2,0.2);
+//  for(vector<igl::Hit>::iterator hit = hits.begin();
+//      hit != hits.end();
+//      hit++)
+//  {
+//    const double w0 = (1.0-hit->u-hit->v);
+//    const double w1 = hit->u;
+//    const double w2 = hit->v;
+//    VectorXd hitP = 
+//      w0 * V.row(F(hit->id,0)) + 
+//      w1 * V.row(F(hit->id,1)) + 
+//      w2 * V.row(F(hit->id,2));
+//    glVertex3dv(hitP.data());
+//  }
+//  glEnd();
+//
+//  pop_object();
+//
+//  // Draw a nice floor
+//  glPushMatrix();
+//  glEnable(GL_LIGHTING);
+//  glTranslated(0,-1,0);
+//  draw_floor();
+//  glPopMatrix();
+//
+//  // draw a transparent "projection screen" show model at time of hit (aka
+//  // mouse down)
+//  push_object();
+//  if(trackball_on)
+//  {
+//    glColor4f(0,0,0,1.0);
+//    glPointSize(10.0);
+//    glBegin(GL_POINTS);
+//    glVertex3dv(SW.data());
+//    glVertex3dv(SE.data());
+//    glVertex3dv(NE.data());
+//    glVertex3dv(NW.data());
+//    glEnd();
+//
+//    glDisable(GL_LIGHTING);
+//    glEnable(GL_TEXTURE_2D);
+//    glBindTexture(GL_TEXTURE_2D, tex_id);
+//    glColor4f(1,1,1,0.7);
+//    glBegin(GL_QUADS);
+//    glTexCoord2d(0,0);
+//    glVertex3dv(SW.data());
+//    glTexCoord2d(1,0);
+//    glVertex3dv(SE.data());
+//    glTexCoord2d(1,1);
+//    glVertex3dv(NE.data());
+//    glTexCoord2d(0,1);
+//    glVertex3dv(NW.data());
+//    glEnd();
+//    glBindTexture(GL_TEXTURE_2D, 0);
+//    glDisable(GL_TEXTURE_2D);
+//  }
+//  pop_object();
+//  pop_scene();
+//
+//  // Draw a faint point over mouse
+//  if(!trackball_on)
+//  {
+//    glDisable(GL_LIGHTING);
+//    glDisable(GL_COLOR_MATERIAL);
+//    glDisable(GL_DEPTH_TEST);
+//    glEnable(GL_BLEND);
+//    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
+//    glColor4f(1.0,0.3,0.3,0.6);
+//    glMatrixMode(GL_PROJECTION);
+//    glLoadIdentity();
+//    gluOrtho2D(0,width,0,height);
+//    glMatrixMode(GL_MODELVIEW);
+//    glLoadIdentity();
+//    glPointSize(20.0);
+//    glBegin(GL_POINTS);
+//    glVertex2dv(win_s.data());
+//    glEnd();
+//  }
+//  report_gl_error();
+//
+//  glutSwapBuffers();
+//  glutPostRedisplay();
+//}
+//
+//// Initialize colors to a boring green
+//void init_C()
+//{
+//  C.col(0).setConstant(0.4);
+//  C.col(1).setConstant(0.8);
+//  C.col(2).setConstant(0.3);
+//}
+//
+//void mouse_move(int mouse_x, int mouse_y)
+//{
+//  using namespace std;
+//  using namespace Eigen;
+//  using namespace igl;
+//  using namespace std;
+//  init_C();
+//  glutSetCursor(GLUT_CURSOR_CROSSHAIR);
+//  // Push scene and object
+//  push_scene();
+//  push_object();
+//  // Unproject mouse at 0 depth and some positive depth
+//  win_s = Vector3d(mouse_x,height-mouse_y,0);
+//  Vector3d win_d(mouse_x,height-mouse_y,1);
+//  unproject(win_s,s);
+//  unproject(win_d,d);
+//  pop_object();
+//  pop_scene();
+//  report_gl_error();
+//  // Shoot ray at unprojected mouse in view direction
+//  dir = d-s;
+//  int num_rays_shot;
+//  ei.intersectRay(s,dir,hits,num_rays_shot);
+//  for(vector<igl::Hit>::iterator hit = hits.begin();
+//      hit != hits.end();
+//      hit++)
+//  {
+//    // Change color of hit faces
+//    C(hit->id,0) = 1;
+//    C(hit->id,1) = 0.4;
+//    C(hit->id,2) = 0.4;
+//  }
+//}
+//
+//void mouse(int glutButton, int glutState, int mouse_x, int mouse_y)
+//{
+//  using namespace std;
+//  using namespace Eigen;
+//  using namespace igl;
+//  switch(glutState)
+//  {
+//    case 1:
+//      // up
+//      glutSetCursor(GLUT_CURSOR_CROSSHAIR);
+//      trackball_on = false;
+//      hits.clear();
+//      init_C();
+//      break;
+//    case 0:
+//      // be sure this has been called recently
+//      mouse_move(mouse_x,mouse_y);
+//      // down
+//      glutSetCursor(GLUT_CURSOR_CYCLE);
+//      // collect information for trackball
+//      trackball_on = true;
+//      copy(scene_rot,scene_rot+4,down_scene_rot);
+//      down_mouse_x = mouse_x;
+//      down_mouse_y = mouse_y;
+//      // Collect "projection screen" locations
+//      push_scene();
+//      push_object();
+//      // unproject corners of window
+//      const double depth = 0.999;
+//      Vector3d win_NW(    0,height,depth);
+//      Vector3d win_NE(width,height,depth);
+//      Vector3d win_SE(width,0,depth);
+//      Vector3d win_SW(0,0,depth);
+//      unproject(win_NW,NW);
+//      unproject(win_NE,NE);
+//      unproject(win_SE,SE);
+//      unproject(win_SW,SW);
+//      // render to framebuffer
+//      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id);
+//      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dfbo_id);
+//      glClearColor(0,0,0,1);
+//      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+//      // Render the model ---> to the framebuffer attached to the "projection
+//      // screen" texture
+//      glEnable(GL_COLOR_MATERIAL);
+//      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
+//      glEnable(GL_LIGHTING);
+//      glEnable(GL_DEPTH_TEST);
+//      draw_mesh(V,F,N,C);
+//      pop_object();
+//      pop_scene();
+//      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+//      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+//    break;
+//  }
+//}
+//
+//void mouse_drag(int mouse_x, int mouse_y)
+//{
+//  using namespace igl;
+//
+//  if(trackball_on)
+//  {
+//    // Rotate according to trackball
+//    trackball<float>(
+//      width,
+//      height,
+//      2,
+//      down_scene_rot,
+//      down_mouse_x,
+//      down_mouse_y,
+//      mouse_x,
+//      mouse_y,
+//      scene_rot);
+//  }
+//}
+//
+//
+//void key(unsigned char key, int mouse_x, int mouse_y)
+//{
+//  using namespace std;
+//  switch(key)
+//  {
+//    // Ctrl-c and esc exit
+//    case char(3):
+//    case char(27):
+//      exit(0);
+//    default:
+//      cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
+//  }
+//  
+//}
+//
+//int main(int argc, char * argv[])
+int main()
 {
-  using namespace Eigen;
-  using namespace igl;
+//  using namespace Eigen;
+//  using namespace igl;
   using namespace std;
 
-  // init mesh
-  string filename = "../shared/decimated-knight.obj";
-  if(argc < 2)
-  {
-    cerr<<"Usage:"<<endl<<"    ./example input.obj"<<endl;
-    cout<<endl<<"Opening default mesh..."<<endl;
-  }else
-  {
-    // Read and prepare mesh
-    filename = argv[1];
-  }
-  if(!read(filename,V,F))
-  {
-    return 1;
-  }
-  // Compute normals, centroid, colors, bounding box diagonal
-  per_face_normals(V,F,N);
-  normalize_row_lengths(N,N);
-  mean = V.colwise().mean();
-  C.resize(F.rows(),3);
-  init_C();
-  bbd = 
-    (V.colwise().maxCoeff() -
-    V.colwise().minCoeff()).maxCoeff();
-
-  // Init embree
-  ei = EmbreeIntersector<double,int>(V,F);
-
-  // Init glut
-  glutInit(&argc,argv);
-  glutInitDisplayString( "rgba depth double samples>=8 ");
-  glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT));
-  glutCreateWindow("embree");
-  glutDisplayFunc(display);
-  glutReshapeFunc(reshape);
-  glutKeyboardFunc(key);
-  glutMouseFunc(mouse);
-  glutMotionFunc(mouse_drag);
-  glutPassiveMotionFunc(mouse_move);
-  glutMainLoop();
+//  // init mesh
+//  string filename = "../shared/decimated-knight.obj";
+//  if(argc < 2)
+//  {
+//    cerr<<"Usage:"<<endl<<"    ./example input.obj"<<endl;
+//    cout<<endl<<"Opening default mesh..."<<endl;
+//  }else
+//  {
+//    // Read and prepare mesh
+//    filename = argv[1];
+//  }
+//  if(!read(filename,V,F))
+//  {
+//    return 1;
+//  }
+//  // Compute normals, centroid, colors, bounding box diagonal
+//  per_face_normals(V,F,N);
+//  normalize_row_lengths(N,N);
+//  mean = V.colwise().mean();
+//  C.resize(F.rows(),3);
+//  init_C();
+//  bbd = 
+//    (V.colwise().maxCoeff() -
+//    V.colwise().minCoeff()).maxCoeff();
+//
+//  // Init embree
+//  ei = EmbreeIntersector<double,int>(V,F);
+//
+//  // Init glut
+//  glutInit(&argc,argv);
+//  glutInitDisplayString( "rgba depth double samples>=8 ");
+//  glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT));
+//  glutCreateWindow("embree");
+//  glutDisplayFunc(display);
+//  glutReshapeFunc(reshape);
+//  glutKeyboardFunc(key);
+//  glutMouseFunc(mouse);
+//  glutMotionFunc(mouse_drag);
+//  glutPassiveMotionFunc(mouse_move);
+//  glutMainLoop();
   return 0;
 }

+ 2 - 2
examples/patches/Makefile

@@ -20,8 +20,8 @@ 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
+EMBREE_INC=-I$(EMBREE)/ -I$(EMBREE)/embree
+EMBREE_LIB=-L$(EMBREE)/bin -lembree -lsys
 
 MATLAB_INC=-I$(MATLAB)/extern/include/
 MATLAB_LIB=-L$(MATLAB)/bin/maci64 -lmx -lmat -lmex -lstdc++

+ 20 - 31
include/igl/embree/EmbreeIntersector.h

@@ -7,20 +7,15 @@
 #ifndef IGL_EMBREE_INTERSECTOR_H
 #define IGL_EMBREE_INTERSECTOR_H
 
-#include "include/embree.h"
-#include "include/intersector1.h"
-#include "common/ray.h"
+#include "Hit.h"
+#include <Eigen/Core>
+#include <embree/include/embree.h>
+#include <embree/include/intersector1.h>
+#include <embree/common/ray.h>
 #include <vector>
 
 namespace igl
 {
-  struct Hit
-  {
-    int id; // primitive id
-    float u,v; // barycentric coordinates
-    float t; // distance = direction*t to intersection
-  };
-
   template <
   typename Scalar,
   typename Index>
@@ -32,10 +27,9 @@ namespace igl
   public:
     // V  #V by 3 list of vertex positions
     // F  #F by 3 list of Oriented triangles
-    EmbreeIntersector();
     EmbreeIntersector(
-      const PointMatrixType & V,
-      const FaceMatrixType & F,
+      const PointMatrixType & V = PointMatrixType(),
+      const FaceMatrixType & F = FaceMatrixType(),
       const char* structure = "default",
       const char* builder = "default",
       const char* traverser = "default");
@@ -97,24 +91,6 @@ namespace igl
 template <typename RowVector3>
 inline embree::Vector3f toVector3f(const RowVector3 &p) { return embree::Vector3f((float)p[0], (float)p[1], (float)p[2]); }
 
-template <
-typename Scalar,
-typename Index>
-igl::EmbreeIntersector < Scalar, Index>
-::EmbreeIntersector()
-{
-  static bool inited = false;
-  if(!inited)
-  {
-    embree::rtcInit();
-#ifdef VERBOSE
-  embree::rtcSetVerbose(3);
-#endif
-    embree::rtcStartThreads();
-    inited = true;
-  }
-}
-
 template <
 typename Scalar,
 typename Index>
@@ -124,17 +100,30 @@ igl::EmbreeIntersector < Scalar, Index>
                     const char* structure,
                     const char* builder,
                     const char* traverser)
+  :
+    mesh(NULL),
+    triangles(NULL),
+    vertices(NULL),
+    intersector(NULL)
 {
+  using namespace std;
   static bool inited = false;
   if(!inited)
   {
+    cout<<"before rtcInit()"<<endl;
     embree::rtcInit();
+    cout<<"after rtcInit()"<<endl;
 #ifdef VERBOSE
     embree::rtcSetVerbose(3);
 #endif
     embree::rtcStartThreads();
     inited = true;
   }
+
+   if(V.size() == 0 || F.size() == 0)
+   {
+     return;
+   }
   
   mesh = embree::rtcNewTriangleMesh(F.rows(),V.rows(),structure);
 

+ 14 - 0
include/igl/embree/Hit.h

@@ -0,0 +1,14 @@
+#ifndef IGL_HIT_H
+#define IGL_HIT_H
+
+namespace igl
+{
+  // Reimplementation of the embree::Hit struct from embree1.0
+  struct Hit
+  {
+    int id; // primitive id
+    float u,v; // barycentric coordinates
+    float t; // distance = direction*t to intersection
+  };
+}
+#endif 

+ 4 - 2
include/igl/embree/Makefile

@@ -24,8 +24,10 @@ EIGEN3_INC=-I$(DEFAULT_PREFIX)/include/eigen3 -I$(DEFAULT_PREFIX)/include/eigen3
 INC+=$(EIGEN3_INC)
 
 # embree dependency
-EMBREE=../../../external/embree
-EMBREE_INC=-I$(EMBREE)/common -I$(EMBREE)/rtcore/
+#EMBREE=../../../external/embree
+#EMBREE_INC=-I$(EMBREE)/common -I$(EMBREE)/rtcore/
+EMBREE=../../../external/embree/
+EMBREE_INC=-I$(EMBREE)/ -I$(EMBREE)/embree
 #EMBREE_LIB=-L$(EMBREE)/bin -lrtcore -lsys
 INC+=$(EMBREE_INC)
 

+ 8 - 11
include/igl/embree/ambient_occlusion.cpp

@@ -3,14 +3,13 @@
 #include <igl/random_dir.h>
 
 template <
-  typename PointMatrixType,
-  typename FaceMatrixType,
-  typename RowVector3,
+  typename Scalar,
+  typename Index,
   typename DerivedP,
   typename DerivedN,
   typename DerivedS >
 void igl::ambient_occlusion(
-  const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+  const igl::EmbreeIntersector<Scalar,Index> & ei,
   const Eigen::PlainObjectBase<DerivedP> & P,
   const Eigen::PlainObjectBase<DerivedN> & N,
   const int num_samples,
@@ -39,7 +38,7 @@ void igl::ambient_occlusion(
         // reverse ray
         d *= -1;
       }
-      embree::Hit hit;
+      igl::Hit hit;
       if(ei.intersectRay(origin,d,hit))
       {
         num_hits++;
@@ -66,15 +65,13 @@ void igl::ambient_occlusion(
   using namespace igl;
   using namespace Eigen;
   EmbreeIntersector<
-    PlainObjectBase<DerivedV>,
-    PlainObjectBase<DerivedF>,
-    Matrix<typename DerivedP::Scalar,3,1> > ei(V,F);
+    typename DerivedV::Scalar,
+    typename DerivedF::Scalar > ei(V,F);
   return ambient_occlusion(ei,P,N,num_samples,S);
 }
 
 #ifndef IGL_HEADER_ONLY
 // 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> >&);
+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> >&);
 #endif

+ 5 - 7
include/igl/embree/ambient_occlusion.h

@@ -6,9 +6,8 @@ namespace igl
 {
   // Forward define
   template <
-    typename PointMatrixType,
-    typename FaceMatrixType,
-    typename RowVector3>
+    typename Scalar,
+    typename Index>
   class EmbreeIntersector;
   // Compute ambient occlusion per given point
   //
@@ -21,14 +20,13 @@ namespace igl
   //      (not occluded)
   //
   template <
-    typename PointMatrixType,
-    typename FaceMatrixType,
-    typename RowVector3,
+    typename Scalar,
+    typename Index,
     typename DerivedP,
     typename DerivedN,
     typename DerivedS >
   void ambient_occlusion(
-    const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+    const igl::EmbreeIntersector<Scalar,Index> & ei,
     const Eigen::PlainObjectBase<DerivedP> & P,
     const Eigen::PlainObjectBase<DerivedN> & N,
     const int num_samples,

+ 4 - 4
include/igl/embree/bone_visible.cpp

@@ -26,8 +26,8 @@ IGL_INLINE void igl::bone_visible(
   FF.resize(F.rows()*2,F.cols());
   FF << F, F.rowwise().reverse();
   // Initialize intersector
-  const EmbreeIntersector<MatrixXd,MatrixXi,Vector3d> ei = 
-        EmbreeIntersector<MatrixXd,MatrixXi,Vector3d>(V,FF);
+  const EmbreeIntersector<double,int> ei = 
+        EmbreeIntersector<double,int>(V,FF);
   const double sd_norm = (s-d).norm();
   // Embree seems to be parallel when constructing but not when tracing rays
 #pragma omp parallel for
@@ -64,14 +64,14 @@ IGL_INLINE void igl::bone_visible(
         projv = d;
       }
     }
-    embree::Hit hit;
+    igl::Hit hit;
     // perhaps 1.0 should be 1.0-epsilon, or actually since we checking the
     // incident face, perhaps 1.0 should be 1.0+eps
     const Vector3d dir = (Vv-projv)*1.0;
     if(ei.intersectSegment(projv,dir, hit))
     {
       // mod for double sided lighting
-      const int fi = hit.id0 % F.rows();
+      const int fi = hit.id % F.rows();
 
       //if(v == 1228-1)
       //{

+ 5 - 7
include/igl/embree/orient_outward_ao.cpp

@@ -13,16 +13,15 @@ template <
   typename DerivedV, 
   typename DerivedF, 
   typename DerivedC, 
-  typename PointMatrixType,
-  typename FaceMatrixType,
-  typename RowVector3,
+  typename Scalar,
+  typename Index,
   typename DerivedFF, 
   typename DerivedI>
 IGL_INLINE void igl::orient_outward_ao(
   const Eigen::PlainObjectBase<DerivedV> & V,
   const Eigen::PlainObjectBase<DerivedF> & F,
   const Eigen::PlainObjectBase<DerivedC> & C,
-  const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+  const igl::EmbreeIntersector<Scalar,Index> & ei,
   const int num_samples,
   Eigen::PlainObjectBase<DerivedFF> & FF,
   Eigen::PlainObjectBase<DerivedI> & I)
@@ -142,9 +141,8 @@ IGL_INLINE void igl::orient_outward_ao(
   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,F2);
+    typename DerivedV::Scalar,
+    typename DerivedF::Scalar > ei(V,F2);
   return orient_outward_ao(V, F, C, ei, num_samples, FF, I);
 }
 

+ 5 - 7
include/igl/embree/orient_outward_ao.h

@@ -6,9 +6,8 @@ namespace igl
 {
   // Forward define
   template <
-    typename PointMatrixType,
-    typename FaceMatrixType,
-    typename RowVector3>
+    typename Scalar,
+    typename Index>
   class EmbreeIntersector;
   // Orient each component (identified by C) of a mesh (V,F) using ambient occlusion 
   // such that the front side is less occluded than back side
@@ -27,16 +26,15 @@ namespace igl
     typename DerivedV, 
     typename DerivedF, 
     typename DerivedC, 
-    typename PointMatrixType,
-    typename FaceMatrixType,
-    typename RowVector3,
+    typename Scalar,
+    typename Index,
     typename DerivedFF, 
     typename DerivedI>
   IGL_INLINE void orient_outward_ao(
     const Eigen::PlainObjectBase<DerivedV> & V,
     const Eigen::PlainObjectBase<DerivedF> & F,
     const Eigen::PlainObjectBase<DerivedC> & C,
-    const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+    const igl::EmbreeIntersector<Scalar,Index> & ei,
     const int num_samples,
     Eigen::PlainObjectBase<DerivedFF> & FF,
     Eigen::PlainObjectBase<DerivedI> & I);

+ 8 - 11
include/igl/embree/unproject_in_mesh.cpp

@@ -4,31 +4,29 @@
 #include <vector>
 
 template <
-  typename PointMatrixType,
-  typename FaceMatrixType,
-  typename RowVector3,
+  typename Scalar,
+  typename Index,
   typename Derivedobj>
 int igl::unproject_in_mesh(
   const int x,
   const int y,
-  const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+  const igl::EmbreeIntersector<Scalar,Index> & ei,
   Eigen::PlainObjectBase<Derivedobj> & obj)
 {
-  std::vector<embree::Hit> hits;
+  std::vector<igl::Hit> hits;
   return igl::unproject_in_mesh(x,y,ei,obj,hits);
 }
 
 template <
-  typename PointMatrixType,
-  typename FaceMatrixType,
-  typename RowVector3,
+  typename Scalar,
+  typename Index,
   typename Derivedobj>
 int igl::unproject_in_mesh(
   const int x,
   const int y,
-  const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+  const igl::EmbreeIntersector<Scalar,Index> & ei,
   Eigen::PlainObjectBase<Derivedobj> & obj,
-  std::vector<embree::Hit > & hits)
+  std::vector<igl::Hit > & hits)
 {
   using namespace igl;
   using namespace std;
@@ -65,5 +63,4 @@ int igl::unproject_in_mesh(
 }
 
 #ifndef IGL_HEADER_ONLY
-template int igl::unproject_in_mesh<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, 3, 1, 0, 3, 1> >(int, int, 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, 3, 1, 0, 3, 1> >&);
 #endif

+ 10 - 13
include/igl/embree/unproject_in_mesh.h

@@ -4,15 +4,14 @@
 #include <Eigen/Core>
 
 #include <vector>
-#include "Embree_convenience.h"
+#include "Hit.h"
 
 namespace igl
 {
   // Forward define
   template <
-    typename PointMatrixType,
-    typename FaceMatrixType,
-    typename RowVector3>
+    typename Scalar,
+    typename Index>
   class EmbreeIntersector;
   // Unproject a screen location (using current opengl viewport, projection, and
   // model view) to a 3D position 
@@ -26,27 +25,25 @@ namespace igl
   // Returns number of hits
   //
   template <
-    typename PointMatrixType,
-    typename FaceMatrixType,
-    typename RowVector3,
+    typename Scalar,
+    typename Index,
     typename Derivedobj>
   int unproject_in_mesh(
     const int x,
     const int y,
-    const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+    const igl::EmbreeIntersector<Scalar,Index> & ei,
     Eigen::PlainObjectBase<Derivedobj> & obj);
 
   template <
-    typename PointMatrixType,
-    typename FaceMatrixType,
-    typename RowVector3,
+    typename Scalar,
+    typename Index,
     typename Derivedobj>
   int unproject_in_mesh(
     const int x,
     const int y,
-    const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+    const igl::EmbreeIntersector<Scalar,Index> & ei,
     Eigen::PlainObjectBase<Derivedobj> & obj,
-    std::vector<embree::Hit > & hits);
+    std::vector<igl::Hit > & hits);
 }
 #ifdef IGL_HEADER_ONLY
 #  include "unproject_in_mesh.cpp"